lucene Field引起的误会

来源:互联网 发布:淘宝知识侵权 编辑:程序博客网 时间:2024/06/01 09:20
今天,犯了个低级错误…做查询的时候发现lucene用queryparser只有完全等值才能匹配。

经过排查原来是在建立索引的时候使用了StringField作为字段(这个只支持全值相等)

改为TextField方可模糊查询……

baidu好多资料是没有发现的……

后来看到官方某个角落的文档发现了这个,才想起来怎么回事……感冒中……

  • public class Fieldextends Objectimplements IndexableField
    Expert: directly create a field for a document.Most users should use one of the sugar subclasses:
    • TextFieldReader or String indexed for full-textsearch
    • StringFieldString indexed verbatim as a singletoken
    • IntPointint indexed for exact/rangequeries.
    • LongPointlong indexed forexact/range queries.
    • FloatPointfloat indexed forexact/range queries.
    • DoublePointdouble indexed forexact/range queries.
    • SortedDocValuesFieldbyte[] indexed column-wisefor sorting/faceting
    • SortedSetDocValuesFieldSortedSet indexed column-wise forsorting/faceting
    • NumericDocValuesFieldlong indexed column-wisefor sorting/faceting
    • SortedNumericDocValuesFieldSortedSet indexed column-wise forsorting/faceting
    • StoredField: Stored-only value for retrieving insummary results

    A field is a section of a Document. Each field has three parts:name, type and value. Values may be text (String, Reader orpre-analyzed TokenStream), binary (byte[]), or numeric (a Number).Fields are optionally stored in the index, so that they may bereturned with hits on the document.

    NOTE: the field type is an IndexableFieldType. Making changes to the state ofthe IndexableFieldType will impact any Field it is used in. It isstrongly recommended that no changes be made after Fieldinstantiation.


    原创粉丝点击