0
lucene 색인에서 검색하려고하지만이 검색을 필터링하고 싶습니다. 거기에는 두 개의 필드 내용과 범주가 있습니다. "내가 스포츠"를 가지고있는 파일을 검색하고 싶고 또한 파일이 얼마나 많은지를 세고 싶다. 나는이 코드를 다음과 같이 작성하려고 노력 중이다. 그러나 문제는 루프 실행으로 인해 수백만 개의 레코드가있는 경우 속도가 느려지므로 작업을 수행하는 다른 방법을 제안합니다.apache lucene index에서 검색하고 결과 그룹을 현명하게 계산하십시오.
시도 {파일 indexDir = 새로운 파일 ("파일의 경로")
Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory, true);
int maxhits=1000000;
QueryParser parser1 = new QueryParser(Version.LUCENE_36, "contents",
new StandardAnalyzer(Version.LUCENE_36));
Query qu=parser1.parse("sport");
TopDocs topDocs = searcher.search(, maxhits);
ScoreDoc[] hits = topDocs.scoreDocs;
len = hits.length;
JOptionPane.showMessageDialog(null,"found times"+len);
int docId = 0;
Document d;
String category="";
int ctr=0,ctr1=0;
for (i = 0; i<len; i++) {
docId = hits[i].doc;
d = searcher.doc(docId);
category= d.get(("category"));
if(category.equals("a"))
ctr++;
if(category.equals("b"))
ctr1++;
}
JOptionPane.showMessageDialog("wprd found in category a times"+ctr);
JOptionPane.showMessageDialog("wprd found in category b times"+ctr1);
}
catch(Exception ex)
{
ex.printStackTrace();
}