[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: Full text search?
From:       Javier Guerra <javier () guerrag ! com>
Date:       2005-02-28 20:20:33
Message-ID: 200502281520.38664.javier () guerrag ! com
[Download RAW message or body]


On Monday 28 February 2005 8:40 am, PA wrote:
> Just as a follow-up, here is my first draft implementation of a
> diminutive text search in Lua:

most people thought of something like this:

function addfile (ndx,fname)
  local fl
  local f = assert (io.open (fname))
  for l in f:lines () do
    for w in string.gfind (l, "%a+") do
      ndx [w] = ndx [w] or {}
      ndx [w] [fname] = ndx [w] [fname] + 1
    end
  end
  f:close()
end

after adding all the files, you can print how many times is a word in each 
file with:

for f,n in pairs (ndx["word"]) do
  print (string.format ("%s times in file %s", n, f))
end

but for big datasets, the index could get too big for memory.

-- 
Javier

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic