QueryParser bug?

I cooked up a little script to show what I mean. This doesn’t look right
to me, but maybe I just completely misunderstand QueryParser.
Same output on mswin32, unix, ferret 0.9 and 0.10
Cheers, Sam

require ‘rubygems’
require ‘ferret’
p Ferret::VERSION # 0.10.6

index = Ferret::Index::Index.new()

index << {:title => “Programming Ruby”, :content => “yada yada yada”}
puts index.search(“ruby”).total_hits # returns 1

query_parser = Ferret::QueryParser.new( :default_field => :title )
query = query_parser.parse(“title:ruby”)
puts index.search(query).total_hits # returns 1

query_parser = Ferret::QueryParser.new( )

:default_field: Default: “*”

The default field to search when no field is specified in the search

string.
query = query_parser.parse(“ruby”)
puts index.search(query).total_hits # returns 0

On 9/22/06, Sam G. [email protected] wrote:

string.
query = query_parser.parse(“ruby”)
puts index.search(query).total_hits # returns 0

Hi Sam,

The way “*” works is it expands to query to search all fields
specified by the :fields parameter. So you could also try this:

query = query_parser.parse("*:ruby")
puts index.search(query).total_hits # returns 0

Without knowing what fields are available the query parser wouldn’t
know how to expand the “*” field specifier. Note that you can print
the query to to see how it was parsed.

require 'rubygems'
require 'ferret'
p Ferret::VERSION # 0.10.6

index = Ferret::Index::Index.new()

index << {:title => "Programming Ruby", :content => "yada yada 

yada"}
puts index.search(“ruby”).total_hits # returns 1

query_parser = Ferret::QueryParser.new( :default_field => :title )
query = query_parser.parse("title:ruby")
puts index.search(query).total_hits # returns 1

query_parser = Ferret::QueryParser.new( )
# :default_field:       Default: "*"
# The default field to search when no field is specified in the

search string.
query = query_parser.parse(“ruby”)
puts query.to_s
puts index.search(query).total_hits # returns 0

query_parser = Ferret::QueryParser.new( :fields => [:title, 

:content])
query = query_parser.parse(“ruby”)
puts query.to_s
puts index.search(query).total_hits # returns 0

Hope that clears things up for you.

Cheers,
Dave