On 9/30/06, Albert <[EMAIL PROTECTED]> wrote:
>
> Hi Dave,
>
> Thanks for following up!  The StemmingAnalyzer is actually just the
> MyAnalyzer from the example above:
>
> module Ferret::Analysis
>   class StemmingAnalyzer
>     def token_stream(field, text)
>       StemFilter.new(StandardTokenizer.new(text))
>     end
>   end
> end
>
> I've been trying to find the error but no success.  The searching is
> done this way:
>
>     i = Ferret::Index::Index.new(:path => index)
>     qp = Ferret::QueryParser.new(:analyzer =>
> Ferret::Analysis::StemmingAnalyzer.new)
>     query = qp.parse(query_string)
>     i.search_each(query) { |doc, score| ... }
>
> What I don't get is that search_each(query) never returns a result
> whereas when I use the original query string as in
>
>     i = Ferret::Index::Index.new(:path => index)
> #    qp = Ferret::QueryParser.new(:analyzer =>
> Ferret::Analysis::StemmingAnalyzer.new)
> #    query = qp.parse(query_string)
>     i.search_each(query_string) { |doc, score| ... }
>                   ------------
>
> things work as expected (modulo the stemmming, of course).  So, it may
> be that I fundamentally misunderstand something or make a stupid mistake
> ...
>
> Cheers,
>
> Albert
>

Sorry, I must have been tired last night. The problem is obvious to me
now. You need to set the :fields parameter. The above query parser
should work as long as you explicitly specify all fields in your
query. For example:

    "content:(ruby rails) title:(ruby rails)"

But if you want to search all fields by default then you need to tell
the QueryParser what fields exist. The Index class will handle all of
this for you including using the same analyzer as is used during
indexing. It looks like you are using the Index class for your
searches so why not just leave the query parsing to it. Otherwise you
can get the fields from the reader.

    query = Ferret::QueryParser.new(
        :analyzer => Ferret::Analysis::StemmingAnalyzer.new,
        :fields => reader.fields,
        :tokenized_fields => reader.tokenized_fields
    ).parse(query_string)

    index.search_each(query) { |doc, score| ... }

Hope that helps,
Dave
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to