tags:

views:

125

answers:

4

From schema.xml:

<field name="myfield" type="integer" indexed="true" stored="false"/>

The record with id 5 has myfield with value of 0, which I've confirmed by searching for plain id:5 and looking at the objectXml.

A search for id:5 AND myfield:0 returns no records.

A search for id:5 AND -myfield:1, however, returns the record I am expecting.

Why?

-- Additional info:

Definition for integer type: <fieldType name="integer" class="solr.IntField" omitNorms="true"/>

Solr version: 1.4

+1  A: 

What is the class that is bound to the "integer" field type? Does it treat 0 as a marker for not indexing?

What does the index data on that document look like in the admin?

Instantsoup
The whole query is id:5 AND myfield:0. I am not trying to return myfield. I am searching by id and myfield. FWIW, if I search for something else using myfield:1, it does return results. It just doesn't seem to like myfield:0.
Mike
A: 

Numeric fields require numeric queries. Try giving a type of something other than numeric for your field.

Xodarap
When did 0 stop being a number?
Mike
...? When you specify a field type of numeric, that means that you want to store it as a trie, with a certain precision. This means that your number is *not* indexed verbatim; so you need a special type of query to query it (essentially it's a range query variant). "Numeric query" does not mean "a normal query with a number in it", it refers to a special Lucene class.
Xodarap
Thanks for the explanation, but it doesn't really help me. I have a field that is an integer. If I search for "myfield:<any integer other than 0>", I find what I'm looking for. If I search for "myfield:0", I get nothing. You're saying I need a special type of query - ok, can you give me an example?
Mike
A: 

I tried your case assuming you used the standard fieldtype for int:

<fieldtype name="integer" class="solr.TrieIntField" ... />

That works fine. So i guess the field type definition of integer is somehow wrong. Check this definition.

cuh
A: 

I've solved the issue. It was a bug in the core of the application (third party CMS) and had nothing to do with Solr.

The problem was that the vendor's code was verifying to see if the value being indexed was not false before indexing it. Unfortunately, they were doing so like this:

$value = strval($node);
if ($value)

Of course, 0 evaluates to false, even if it's the string "0".

I changed it to:

$value = strval($node);
if ($value !== false)

... and now it works.

Thank you for your efforts and sorry the problem ended up being something completely unrelated.

Mike