2016-11-24 34 views
0

我試着在Lucene的6.2.1如下(DIFF領域。):路口搜索 - Lucene的

我有不同的領域ABCDE我做的每場不同的searchquery

然後我想做一個十字路口。當結果無處不在時顯示它。

有人告訴我用Booleanquery試試這個。所以這是我的方法:

IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(index))); 
IndexSearcher searcher = new IndexSearcher(reader); 
Analyzer analyzer = new StandardAnalyzer(); 

BufferedReader in = null; 
in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); 

QueryParser parser1 = new QueryParser("A", analyzer);// i have 5 different QueryParser 
Query qPersonen = parser1.parse("searchstring"); // i have also 5 Queries 
booleanQuery.add(qPersonen, BooleanClause.Occur.MUST); 

TotalHitCountCollector collector = new TotalHitCountCollector(); 
TopDocs results = searcher.search(booleanQuery.build(), 100); 

ScoreDoc[] hits = results.scoreDocs; 
int numTotalHits = results.totalHits; 
System.out.println("Results: " + numTotalHits); 

爲什麼它不工作?可能是什麼錯?它總是不返回任何結果:(

+0

你的問題是什麼?該方法不起作用? – root545

+0

你爲什麼不得到'BooleanQuery'的實例? –

回答

0

當我看到你的代碼,看來你沒有得到的BooleanQuery例如由於Lucene的5,布爾查詢的API已經改變嘗試以下方法:。

QueryParser parser1 = new QueryParser("A", analyzer);// i have 5 different QueryParser 
Query qPersonen = parser1.parse("searchstring"); // i have also 5 Queries 
BooleanQuery.Builder bq = new BooleanQuery.Builder(); 
bq.add(new BooleanClause(aPersonen, BooleanClause.Occur.MUST)); 

希望這會對你有用:)