Let Lucene include spaces in term for exact match

Boris Callens picture Boris Callens · Mar 9, 2009 · Viewed 10k times · Source

I want my Lucene query to contain something similar to:

companyNam:mercedes trucks

Where it will do an exact match for the string "mercedes trucks" in the companyName field.
The companyName is an untokenized field, but anything with a space returns null results..

new TermQuery(new Term("companyName", "mercedes trucks"));

Always results 0 results if there is a space involved. Otherwise my program is working fine.

Answer

derCris picture derCris · May 31, 2010

Maybe replace:

mercedes trucks 

with

mercedes?trucks

Works for me.