lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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: pgpl8rOizaAbz.pgp
Description: PGP signature