lucene booleanquery組合查詢

2021-05-17 12:51:59 字數 874 閱讀 3879

當parse函式中指定多個項時,queryparser能很方便地構建booleanquery物件。使用圓括號分組,通過指定的-、+、and、or以及not這些操作符。

允許進行邏輯的and、or或not組合,通過booleanquery的add方法將乙個查詢子句增加到某個booleanquery物件中:

public void add(query query,boolean required,booleanprohibited)

required

false

true

prohibited

false

該子句是可選(邏輯或)

該子句是必須匹配(邏輯與)

true

該子句是不允許匹配的(邏輯非)

termquery searchingbooks=new termquery(newterm("subject","search"));

rangequery currentbooks=new rangequery(newterm("pubmonth","200401"),new term("pubmonth","200412"),true);

booleanquery currentsearchingbooks=new booleanquery();

currentsearchingbooks.add(searchingbooks,true,false);

currentsearchingbooks.add(currentbooks,true,false);

indexsearcher searcher=new indexsearcher(directory);

hits hits=searcher.search(currentsearchingbooks);

lucene booleanquery組合查詢

當parse函式中指定多個項時,queryparser能很方便地構建booleanquery物件。使用圓括號分組,通過指定的 and or以及not這些操作符。允許進行邏輯的and or或not組合,通過booleanquery的add方法將乙個查詢子句增加到某個booleanquery物件中 pu...

Lucene BooleanQuery相關演算法

booleanquery對兩種不同查詢場景執行不同的演算法 場景1 所有的子句都必須滿足,而且所有的子句裡沒有巢狀booleanquery。例 a and b and c 上面語句表示要同時包含a,b,c三個字元 詞元 的文件,假如現在索引裡包含a的文件有4,6,8 b的文件有 2,4,6 c的文件...

elasticsearch bool組合查詢

bool組合查詢 filter 過濾,不參與打分 must 如果有多個條件,這些條件都必須滿足 and與 should 如果有多個條件,滿足乙個或多個即可 or或 must not 和must相反,必須都不滿足條件才可以匹配到 非 布林查詢 與匹配其他查詢的布林組合的文件相匹配的查詢。bool查詢對...