//搜尋條件
PhraseQuery queryTitle = new PhraseQuery();
PhraseQuery queryContentD = new PhraseQuery();
foreach (string word in wordList)//先用空格,讓使用者去分詞,空格分隔的就是詞“計算機 專業”
{
queryTitle.Add(new Term("Title", word)); //對書名進行檢索
queryContentD.Add(new Term("ContentDescription", word));//對書簡介進行檢索
}
queryTitle.SetSlop(100);//多個查詢條件的詞之間的最大距離.在文章中相隔太遠 也就無意義.(例如 “大學生”這個查詢條件和"履歷"這個查詢條件之間如果間隔的詞太多也就沒有意義了。)
queryContentD.SetSlop(100);
//TopScoreDocCollector是盛放查詢結果的容器
BooleanQuery query = new BooleanQuery(); //多條件查詢 相當于或
query.Add(queryTitle, BooleanClause.Occur.SHOULD);
query.Add(queryContentD, BooleanClause.Occur.SHOULD);
TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
searcher.Search(query, null, collector);//根據query查詢條件進行查詢,查詢結果放入collector容器