每个人都是大数据的初学者,并尝试索引和搜索数据。我有个问题 1) - 索引程序运行非常顺利,但搜索它总是显示每个查询一个或零点击。
像这样: -
Skipped write.lock
补充:D:\ Studies \ Universities-Punjab University- \ Notes \ Final Year Project \ Appache Lucene \ Result 3 \ file.txt
补充:D:\ Studies \ Universities-Punjab University- \ Notes \ Final Year Project \ Appache Lucene \ Result 3 \ lab 1.txt
已添加2份文件。
输入搜索查询(q =退出):
瓦利德
找到1次点击。
输入搜索查询(q =退出):
Wlaeed
找到0次点击。
输入搜索查询(q =退出):
艾哈迈德
找到1次点击。
输入搜索查询(q =退出):
列车
找到1次点击。
输入搜索查询(q =退出):
q
索引编码: -
Reader fr = null;
try {
Document doc = new Document();
fr = new FileReader(f);
doc.add(new StringField("path", f.getPath(), Field.Store.YES));
doc.add(new StringField("filename", f.getName(),Field.Store.YES));
doc.add(new TextField("contents", fr));
writer.addDocument(doc);
enhanceList(f, helper);
} catch (Exception e) {
System.out.println("Could Not Add: " + f);
} finally {
fr.close();
}
搜索/查询代码: -
void searching() throws IOException {
String s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(directory)));
IndexSearcher searcher = new IndexSearcher(reader);
while (!s.equalsIgnoreCase("q")) {
try {
System.out.println("Enter the Search Query (q=quit):");
s = br.readLine();
if (s.equalsIgnoreCase("q")) {
break;
}
Query q = new QueryParser(Version.LUCENE_44, "contents", analyzer).parse(s);
ScoreDoc[] hits = searcher.search(q, 1000).scoreDocs;
System.out.println("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("path") + " score=" + hits[i].score);
}
} catch (Exception e) {
System.out.println("Error Searching " + s + " : " + e.getMessage());
}
}
}
请任何人帮我找出解决方案..