Is there any working way to search multiple indexes?

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

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