Hi,
I’m having difficulty getting the StemFilter and PhraseQuery to work
properly together. When I use a StemFilter with a PhraseQuery, searches
only
work if the phrase consists of stems. For example, the search phrase
“reduces health care” will not work but the phrase “reduce health care”
will
work even though the exact text “reduces health care” is contained in
the
original document. I’d like to use StemFilter in conjunction with
PhraseQuery because I need the stemming and I also need to be able to
use
the slop feature of PhraseQuery. Below is my use of StemFilter and
PhraseQuery. Is there anything I’m doing wrong or is the above
description
what I should expect? To get the response that I’m expecting I could
parse
the phrase and build up a query to be used by QueryParser but I’d like a
more succinct solution for now.
I use a StemFilter in my analyzer as follows:
def token_stream(field, str)
...
ts = LowerCaseFilter.new(ts) if @lower
ts = StopFilter.new(ts, @stop_words)
ts = StemFilter.new(ts)
...
end
My use of PhraseQuery is as follows:
def generate_query(phrase)
phrase = phrase.downcase
phrase_parts = phrase.split(’ ')
query = Ferret::Search::PhraseQuery.new(:content, 2)
phrase_parts.each do |part|
# puts “part: “” + part + “””
query.add_term(part, 1)
end
query
end