在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 大數(shù)據(jù)/ Lucene BooleanQuery類
Lucene TermRangeQuery類
Lucene排序
Lucene Query類
Lucene搜索操作
Lucene TokenStream
Lucene IndexWriter類
Lucene Term類
Lucene Token
Lucene索引操作
Lucene Field選項
Lucene BooleanQuery類
Lucene StandardAnalyzer類
Lucene字段
Lucene添加文檔操作
Lucene環(huán)境設置
Lucene Searching類
Lucene StopAnalyzer類
Lucene第一個應用程序
Lucene MatchAllDocsQuery類
Lucene IndexSearcher類
Lucene索引類
Lucene更新文檔操作
Lucene教程
Lucene PrefixQuery類
Lucene Analyzer類
Lucene TopDocs類
Lucene TermQuery類
Lucene文檔
Lucene查詢編程
Lucene WildcardQuery類
Lucene WhitespaceAnalyzer
Lucene SimpleAnalyzer類
Lucene目錄
Lucene刪除文檔操作
Lucene索引過程
Lucene FuzzyQuery類
Lucene PhraseQuery類
Lucene分析

Lucene BooleanQuery類

BooleanQuery 用于搜索的是使用 AND,OR或NOT運算符多個查詢結(jié)果的文件。

類聲明

以下是org.apache.lucene.search.BooleanQuery類的聲明:

public class BooleanQuery
   extends Query
      implements Iterable<BooleanClause>

字段

  • protected int minNrShouldMatch

類的構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù)和說明
1 BooleanQuery()
構(gòu)造一個空的布爾查詢。
1 BooleanQuery(boolean disableCoord)
構(gòu)造一個空的布爾查詢。

類方法

S.N. 方法及說明
1 void add(BooleanClause clause)
Adds a clause to a boolean query.
2 void add(Query query, BooleanClause.Occur occur)
Adds a clause to a boolean query.
3 List<BooleanClause> clauses()
Returns the list of clauses in this query.
4 Object clone()
Returns a clone of this query.
5 Weight createWeight(Searcher searcher)
Expert: Constructs an appropriate Weight implementation for this query.
6 boolean equals(Object o)
Returns true iff o is equal to this.
7 void extractTerms(Set<Term> terms)
Expert: adds all terms occurring in this query to the terms set.
8 BooleanClause[] getClauses()
Returns the set of clauses in this query.
9 static int getMaxClauseCount()
Return the maximum number of clauses permitted, 1024 by default.
10 int getMinimumNumberShouldMatch()
Gets the minimum number of the optional BooleanClauses which must be satisfied.
11 int hashCode()
Returns a hash code value for this object.
12 boolean isCoordDisabled()
Returns true iff Similarity.coord(int,int) is disabled in scoring for this query instance.
13 Iterator<BooleanClause> iterator()
Returns an iterator on the clauses in this query.
14 Query rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
15 static void setMaxClauseCount(int maxClauseCount)
Set the maximum number of clauses permitted per BooleanQuery.
16 void setMinimumNumberShouldMatch(int min)
Specifies a minimum number of the optional BooleanClauses which must be satisfied.
17 String toString(String field)
Prints a user-readable version of this query.

繼承的方法

這個類繼承了以下類方法:

  • org.apache.lucene.search.Query

  • java.lang.Object

使用

private void searchUsingBooleanQuery(String searchQuery1,
   String searchQuery2)throws IOException, ParseException{
   searcher = new Searcher(indexDir);
   long startTime = System.currentTimeMillis();
   //create a term to search file name
   Term term1 = new Term(LuceneConstants.FILE_NAME, searchQuery1);
   //create the term query object
   Query query1 = new TermQuery(term1);

   Term term2 = new Term(LuceneConstants.FILE_NAME, searchQuery2);
   //create the term query object
   Query query2 = new PrefixQuery(term2);

   BooleanQuery query = new BooleanQuery();
   query.add(query1,BooleanClause.Occur.MUST_NOT);
   query.add(query2,BooleanClause.Occur.MUST);

   //do the search
   TopDocs hits = searcher.search(query);
   long endTime = System.currentTimeMillis();

   System.out.println(hits.totalHits +
      " documents found. Time :" + (endTime - startTime) + "ms");
   for(ScoreDoc scoreDoc : hits.scoreDocs) {
      Document doc = searcher.getDocument(scoreDoc);
      System.out.println("File: "+ doc.get(LuceneConstants.FILE_PATH));
   }
   searcher.close();
}

應用程序示例

讓我們創(chuàng)建一個測試Lucene的應用程序中使用BooleanQuery測試搜索。

步驟 描述
1 Create a project with a name LuceneFirstApplication under a packagecom.yiibai.lucene as explained in the Lucene - First Application chapter. You can also use the project created in Lucene - First Application chapter as such for this chapter to understand searching process.
2 Create LuceneConstants.java and Searcher.java as explained in the Lucene - First Applicationchapter. Keep rest of the files unchanged.
3 Create LuceneTester.java as mentioned below.
4 Clean and Build the application to make sure business logic is working as per the requirements.

LuceneConstants.java

這個類是用來提