Forum: Ferret Is there any working way to search multiple indexes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joshua B. (Guest)
on 2006-05-06 00:14
(Received via mailing list)
I'm running from the trunk, and hitting road blocks no matter which way
I
attempt
to search across multiple indexes.

I tried a MultiSearcher, but I can't pass a string for the search query

ms.search "iraq"
TypeError: wrong argument type String (expected Data)

So I tried creating a QueryParser to pass, but I can't get the fields
from
the reader
 r.get_field_names
NoMethodError: undefined method `get_field_names' for
#<Ferret::Index::IndexReader:0x406059dc>

and even if I could, I cant pass any fields to the QueryParser
qp.fields = ["title"]
NoMethodError: undefined method `fields=' for
#<Ferret::QueryParser:0x407db070>

So I tried using the MultiReader, like acts_as_ferret does, but it won't
take any arguments
@reader = Index::MultiReader.new(sub_readers)
ArgumentError: wrong number of arguments (1 for 0)

Is everything I'm trying to do unimplemented in the c version, or am I
just
overlooking something obvious?

thanks,
joshua
David B. (Guest)
on 2006-05-06 04:47
(Received via mailing list)
Hi Joshua,

The best place to check how to use the MultiSearcher is the
MultiSearcher unit tests;

    test/unit/search/tc_multi_searcher.rb
    test/unit/search/tc_multi_searcher2.rb

Create a MultiSearcher like this;

    @multi = Ferret::Search::MultiSearcher.new([IndexSearcher.new(dir1),
IndexSearcher.new(dir2)])

You can have as many IndexSearchers as you like. You actually need to
pass a query to both IndexSearcher and MultiSearcher. Strings are not
allowed in Ferret 0.9.1. That may change in future versions. So do
something like this;

  def do_search(query)
    @query_parser ||= Ferret::QueryParser.new(['date', 'field',
'cat'], :analyzer => WhiteSpaceAnalyzer.new())
    query = @query_parser.parse(query) if (query.is_a? String)
    return @multi.search(query)
  end

Hope that helps.

Cheers,
Dave
This topic is locked and can not be replied to.