The following script creates a search index and then searches it. I get no results? Where am I going wrong? Thanks. -----------BEGIN SCRIPT---------------- require ''rubygems'' require ''ferret'' include Ferret path = ''/tmp/myindex'' field_infos = Ferret::Index::FieldInfos.new() field_infos.add_field(:name, :store => :yes, :index => :yes) field_infos.create_index(path) index = Index::Index.new(:path => path, :field_infos => field_infos, :analyzer => Analysis::AsciiStandardAnalyzer.new) 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---------------- -- Posted via http://www.ruby-forum.com/.
On 9/5/06, Mufaddal Khumri <mkhumri at allegromedical.com> wrote:> The following script creates a search index and then searches it. I get > no results? Where am I going wrong? > > Thanks. > > -----------BEGIN SCRIPT---------------- > require ''rubygems'' > require ''ferret'' > > include Ferret > > path = ''/tmp/myindex'' > field_infos = Ferret::Index::FieldInfos.new() > field_infos.add_field(:name, :store => :yes, :index => :yes) > field_infos.create_index(path) > index = Index::Index.new(:path => path, :field_infos => field_infos, > :analyzer => Analysis::AsciiStandardAnalyzer.new) > > index << {:name => "Joe"} > index << {:name => "Sandy"} > index << {:name => "Billy"} > 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> 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----------------
David Balmain wrote:> On 9/5/06, Mufaddal Khumri <mkhumri at allegromedical.com> wrote: >> >> 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, > DaveThanks. 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? -- Posted via http://www.ruby-forum.com/.
Mufaddal Khumri wrote:> David Balmain wrote: >> On 9/5/06, Mufaddal Khumri <mkhumri at allegromedical.com> wrote: >>> >>> 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: query = Search::TermQuery.new(:name, "Joe") index.search_each(query, {:limit => :all}) do |doc, score| .... Thanks. -- Posted via http://www.ruby-forum.com/.
On 9/5/06, Mufaddal Khumri <mkhumri at allegromedical.com> wrote:> Mufaddal Khumri wrote: > > David Balmain wrote: > >> On 9/5/06, Mufaddal Khumri <mkhumri at allegromedical.com> wrote: > >>> > >>> 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: > > query = Search::TermQuery.new(:name, "Joe") > index.search_each(query, {:limit => :all}) do |doc, score| .... > > Thanks.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; query = Search::TermQuery.new(:name, "Joe".downcase) Anything more complicated than this and you are better off leaving it to the QueryParser. Cheers, Dave