On 9/5/06, Mufaddal Khumri <[EMAIL PROTECTED]> 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----------------
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk