index << {:name => “Joe”}
index << {:name => “Sandy”}
index << {:name => “Billy”}
index << {:name => “Lona”}
index << {:name => “Frank”}
index.optimize
query = Search::TermQuery.new(:name, “Joe”)
index.search_each(query, {:limit => :all}) do |doc, score|
puts ‘i am here to just drink some hot chocolate.’
puts index[doc][“name”]
end
-------------END SCRIPT----------------
index << {:name => “Lona”}
index << {:name => “Frank”}
index.optimize
query = Search::TermQuery.new(:name, “Joe”)
Your problem lies here. The AsciiStandardAnalyzer downcases all of the
data as it is entered into the index, so you should be searching for
“joe”, not “Joe”. Since you are using the Index class you can just do
it like this also;
index.search_each("name:Joe", {:limit => :all}) do |doc, score|
In this case the QueryParser will downcase “Joe” for you.
index << {:name => “Lona”}
index << {:name => “Frank”}
index.optimize
query = Search::TermQuery.new(:name, “Joe”)
Your problem lies here. The AsciiStandardAnalyzer downcases all of the
data as it is entered into the index, so you should be searching for
“joe”, not “Joe”. Since you are using the Index class you can just do
it like this also;
index.search_each("name:Joe", {:limit => :all}) do |doc, score|
In this case the QueryParser will downcase “Joe” for you.
Cheers,
Dave
Thanks.
I thought the AsciiStandardAnalyzer would be used by the
index.search_each(…) call. How do I specify a analyzer
(AsciiStandardAnalyzer) while searching the index? I thought that I
could specify the analyzer via the constructor for the Index class.
Later when I index data or search the index the set analyzer would be
used. Am I understanding this right?
index << {:name => “Lona”}
index << {:name => “Frank”}
index.optimize
query = Search::TermQuery.new(:name, “Joe”)
Your problem lies here. The AsciiStandardAnalyzer downcases all of the
data as it is entered into the index, so you should be searching for
“joe”, not “Joe”. Since you are using the Index class you can just do
it like this also;
index.search_each("name:Joe", {:limit => :all}) do |doc, score|
In this case the QueryParser will downcase “Joe” for you.
Cheers,
Dave
Thanks.
I thought the AsciiStandardAnalyzer would be used by the
index.search_each(…) call. How do I specify a analyzer
(AsciiStandardAnalyzer) while searching the index? I thought that I
could specify the analyzer via the constructor for the Index class.
Later when I index data or search the index the set analyzer would be
used. Am I understanding this right?
Just read David’s post carefully
I guess the QueryParser uses the analyzer set:
index.search_each(“name:Joe”, {:limit => :all}) do |doc, …
My next question is how do I get the analyzer to be used when i create
my query and search like this:
I’m not sure why you’d want to do this when you can just pass the
query string to the search_each method and it does it for you. What
exactly are you trying to do? Can’t you just do this;