Question about specific field searches


(Tom Tayon-2) #1

Hello,

I am trying to do a search using the Java API on a specific field
using the QueryStringQueryBuilder.field.

If I have 2 fields, one of type Integer, and one of type String, and
do a standard query across all fields for "bob", the search works as
expected.

If I tell the system to narrow the search to only the Integer field,
then search for "123", everything works as expected.

However, the search for "bob" results in a NumberFormatException[For
input string: "bob"]

It is apparently trying to convert "bob" to a number to do the search.
I cannot easily restrict what the user types in the search to know if
everything will convert. I would rather not have to parse the user
input looking for anything that will not match any field type that may
be selected. (We have dozens of different fields of different types)

Is this a known issue, or am I possibly doing something wrong? Why
does this work when I search across all fields?

Thanks for any help in the matter,

Tom


(Shay Banon) #2

Yea, the parser will try and use the provided value and convert it to
numeric if you query against it. You can do a simple check on the query
string, and if it is numeric, then query the integer field.

On Tue, Apr 3, 2012 at 6:02 PM, Tom Tayon tomtayon@gmail.com wrote:

Hello,

I am trying to do a search using the Java API on a specific field
using the QueryStringQueryBuilder.field.

If I have 2 fields, one of type Integer, and one of type String, and
do a standard query across all fields for "bob", the search works as
expected.

If I tell the system to narrow the search to only the Integer field,
then search for "123", everything works as expected.

However, the search for "bob" results in a NumberFormatException[For
input string: "bob"]

It is apparently trying to convert "bob" to a number to do the search.
I cannot easily restrict what the user types in the search to know if
everything will convert. I would rather not have to parse the user
input looking for anything that will not match any field type that may
be selected. (We have dozens of different fields of different types)

Is this a known issue, or am I possibly doing something wrong? Why
does this work when I search across all fields?

Thanks for any help in the matter,

Tom


(system) #3