今天,犯了个低级错误…做查询的时候发现lucene用queryparser只有完全等值才能匹配。
经过排查原来是在建立索引的时候使用了StringField作为字段(这个只支持全值相等)
改为TextField方可模糊查询……
baidu好多资料是没有发现的……
后来看到官方某个角落的文档发现了这个,才想起来怎么回事……感冒中……
-
public class Field extends Object implements IndexableField
Expert: directly create a field for a document. Most users should use one of the sugar subclasses:TextField
:Reader
or String
indexed for full-text search StringField
:String
indexed verbatim as a single token IntPoint
:int
indexed for exact/range queries. LongPoint
:long
indexed for exact/range queries. FloatPoint
:float
indexed for exact/range queries. DoublePoint
:double
indexed for exact/range queries. SortedDocValuesField
:byte[]
indexed column-wise for sorting/faceting SortedSetDocValuesField
:SortedSet
indexed column-wise for sorting/faceting NumericDocValuesField
:long
indexed column-wise for sorting/faceting SortedNumericDocValuesFi
:eld SortedSet
indexed column-wise for sorting/faceting StoredField
: Stored-only value for retrieving in summary results
A field is a section of a Document. Each field has three parts: name, type and value. Values may be text (String, Reader or pre-analyzed TokenStream), binary (byte[]), or numeric (a Number). Fields are optionally stored in the index, so that they may be returned with hits on the document.
NOTE: the field type is an
IndexableFieldType
. Making changes to the state of the IndexableFieldType will impact any Field it is used in. It is strongly recommended that no changes be made after Field instantiation.