我想用Lucene做查詢,我想選擇標題以「@」字符開頭的文檔。 我看了文檔,但結果是零元素。 這是代碼和結果。 感謝您的幫助。查詢選擇所有lucene的java
這是代碼:
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "@aa Lucene in Action", "193398817");
addDoc(w, "@ba Lucene for Dummies", "55320055Z");
addDoc(w, "prova Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
String querystring = "@";
Query q;
q = new QueryParser(LUCENE_41, "title", new StandardAnalyzer(LUCENE_41)).parse(querystring);
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs docs = searcher.search(q, 1000000);
ScoreDoc[] hits = docs.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("isbn") + "\t" + d.get("title"));
}
reader.close();
,這是輸出
Building provaLucerne 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ provaLucerne ---
Found 0 hits.
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1.505s
Finished at: Wed Nov 02 19:49:39 CET 2016
Final Memory: 5M/155M
我想'@'由'StandardAnalyzer'被除去而索引 –