Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,495,102字

该文章投稿至Nemo社区   Java  板块 复制链接


Luncene 多字段查询记录

发布于 2017/10/18 14:27 3,475浏览 0回复 1,605

多字段查询需要使用MultiFieldQueryParser来做解析:

String params[] = new String[]{par,par};

String fields[] = new String[]{"title","context"};
BooleanClause.Occur rules[] = new BooleanClause.Occur[]{BooleanClause.Occur.SHOULD,BooleanClause.Occur.SHOULD};
Query query = MultiFieldQueryParser.parse(params,fields,rules,analyzer);

其中par是查询关键字,params是根据需要查询的字段数定义的查询参数列表。以上可以翻译为:title like par or context like par。

fields是需要同时查询的字段列表。

analyzer是分词器,不必说。

rules是定义多个参数的匹配规则列表,总共有以下几种情况:


/** Use this operator for clauses that <i>must</i> appear in the matching documents. */
MUST { @Override public String toString() { return "+"; } },

/** Like {@link #MUST} except that these clauses do not participate in scoring. */
FILTER { @Override public String toString() { return "#"; } },

/** Use this operator for clauses that <i>should</i> appear in the
* matching documents. For a BooleanQuery with no <code>MUST</code>
* clauses one or more <code>SHOULD</code> clauses must match a document
* for the BooleanQuery to match.
* @see BooleanQuery.Builder#setMinimumNumberShouldMatch
*/
SHOULD { @Override public String toString() { return ""; } },

/** Use this operator for clauses that <i>must not</i> appear in the matching documents.
* Note that it is not possible to search for queries that only consist
* of a <code>MUST_NOT</code> clause. These clauses do not contribute to the
* score of documents. */
MUST_NOT { @Override public String toString() { return "-"; } };
BooleanClause.Occur.MUSTand
BooleanClause.Occur.MUST_NOTnot
BooleanClause.Occur.SHOULDor



点赞(0)
点了个评