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 Gelens
On Tue, Oct 31, 2006 at 03:55:07PM +0900, Jeffrey Gelens wrote:> 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?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 kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
> On Tue, Oct 31, 2006 at 03:55:07PM +0900, Jeffrey Gelens wrote: > > 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? > > 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. > > > JensNow I constructed the queryparser using the same analyzer and it seems that was indeed the problem. Thanks. The reason why I''m using the regexp /./ is that I''m indexing Japanese sites. I found a solution on this mailinglist to use a RegExpAnalyzer using this regexp for asian characters. It is working fine. Am I using it correctly or should I index Japanese characters ? -- Jeffrey Gelens
On Tue, Nov 07, 2006 at 12:36:18PM +0900, Jeffrey Gelens wrote: [..]> Now I constructed the queryparser using the same analyzer and it seems > that was indeed the problem. Thanks. > > The reason why I''m using the regexp /./ is that I''m indexing Japanese > sites. I found a solution on this mailinglist to use a RegExpAnalyzer > using this regexp for asian characters. > It is working fine. Am I using it correctly or should I index Japanese > characters ?I don''t know anything about indexing japanese characters, so just ignore me if it is working fine ;-) Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66