FieldQuery not returning anything

Hey …

The QueryParser RDoc page explains to me on how to search for a specific
value in a specific field. This is not working the way i thought it
should be, what am i doing wrong? Here’s an example …

I’m storing model data in the index like this:

doc << Field.new( “object_id”, object.id, Field::Store::YES)
doc << Field.new( “type”, object.class.base_class.to_s,
Field::Store::YES)

This is working fine, i get something like this:

i[0]
=> Document {
stored/uncompressed,indexed,<object_id:3>
stored/uncompressed,indexed,type:Category
}

Now I want to search for all documents, with a specific type… here’s my
naive approach …

i.search_each(‘type:Category’) do |doc, score| puts “found #{doc}” end
=> 0

Searching for this will return my doc

i.search_each(‘object_id:3’) do |doc, score| puts “found #{doc}” end
found 0
=> 1

If I tokenize the ‘type’ field, my query is working, but I thought i can
store the value as-it by leaving it untokenized and am still able to
search for it with a FieldQuery. Am I wrong?

Thanks,
Ben

On 7/15/06, Benjamin K. [email protected] wrote:

Field::Store::YES)
Now I want to search for all documents, with a specific type… here’s my

If I tokenize the ‘type’ field, my query is working, but I thought i can
store the value as-it by leaving it untokenized and am still able to
search for it with a FieldQuery. Am I wrong?

Thanks,
Ben

Hi Ben,
The problem is that the Query parser will tokenize the query string.
So Category is getting downcased to category. So you have two options.
You can downcase all entries you want to make searchable in the
untokenized field. Or, if you want to make case meaningful, you need
to create an Analyzer that won’t downcase the “type” field.

Hope that helps,
Dave

The problem is that the Query parser will tokenize the query string.
So Category is getting downcased to category. So you have two options.
You can downcase all entries you want to make searchable in the
untokenized field. Or, if you want to make case meaningful, you need
to create an Analyzer that won’t downcase the “type” field.

ah… i see… thanks a lot :slight_smile:

Ben