why in solr 1.4 passing a letter to a 'int' field results in exception?

93 views Asked by At

I'm running lucene solr 1.4 on top of tomcat.

I have a field id defined with type int which is mapped to solr.TrieIntField.

When I do a solr query like ?q=id:a I get a NumberFormatException.

Is it possible to configure solr in such a way that it returns empty result set for above scenraio instead of throwing the exception?

2

There are 2 answers

0
Arun On BEST ANSWER

Why do you have to have this as TrieIntField? Can you not use ? They are all sub classes of non tokekenized field (org.apache.solr.schema.FieldType).

Update: Based on your original question, as it is about id, i suggested to use string, as it makes no difference in that case. But if other fields use TrieIntField type the downside of using string for those fields is that your sorts and range queries may go string based and may be not desirable. In that case you need to prevent your orignal problem in client API or you need to handle them better by writing your own handler. Solr is doing correct thing by giving error as most applications would capure this error and respond to users with better user error message. If solr returns no results instead of error then it would be missleading.

1
kee On

Solr is written in Java so it is expected. You have to either filter out non-integer value from your client side (or API layer) or use String type as Arun suggested.