I just started using Ferret and I successfully indexed some documents. I
can search this index using the following code:
index = Index::Index.new(:path => path)
index.search_each(“something”) do |doc, score|
print “##{doc} #{index[doc][‘url’]} - #{score}”
print “\n”
end
However, when I try to use Search::Searcher and QueryParser I don’t get
any results. I tried the following code:
queryparser = QueryParser.new()
searcher = Searcher.new(path)
queryparser.fields = searcher.reader.fields
searcher.search(queryparser.parse(“something”))
I index all my documents as follows:
index = Index::Index.new(:path => path, :analyzer =>
Analysis::RegExpAnalyzer.new(/./, false))
index << { :title => title, :url => link, :body => page }
What am I doing wrong?
Thanks!
– Jeffrey G.
On Tue, Oct 31, 2006 at 03:55:07PM +0900, Jeffrey G. wrote:
any results. I tried the following code:
index << { :title => title, :url => link, :body => page }
What am I doing wrong?
Basically you should use the same analyzer to analyze queries as you
used to analyze your content. So constructing your queryparser like
this:
qp = QueryParser.new(:analyzer => Analysis::RegExpAnalyzer.new(/./,
false))
your searches should work.
However, your regexp for the analyzer looks strange - /./ matches every
single character, including whitespace. So each field’s value would be
indexed as 1-character long terms, which probably is not what you want.
However I don’t know why searching through the Index class worked, I’d
suspect it not to work, too.
Jens
–
webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66