I am unable to find the expected documents when I execute a query on a
keyword whose value contains punctuation.
Here is the test case:
import org.apache.lucene.queryParser.*;
import org.apache.lucene.search.*;
import org.apache.lucene.index.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*;
public class KeywordTest {
public static void main(String args[]) throws Exception {
Analyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter("index", analyzer, true);
Document d3 = new Document();
d3.add(Field.Keyword("id","person/john"));
d3.add(Field.Text("macrinstfulltext","male married"));
writer.addDocument(d3);
Document d4 = new Document();
d4.add(Field.Keyword("id","person/wendy"));
d4.add(Field.Text("macrinstfulltext","female Single"));
writer.addDocument(d4);
Document d5 = new Document();
d5.add(Field.Keyword("id","person123"));
d5.add(Field.Text("macrinstfulltext","female Single"));
writer.addDocument(d5);
writer.close();
IndexReader reader = IndexReader.open("index");
Searcher searcher = new IndexSearcher(reader);
search(searcher, analyzer, "id:person/john");
// this query doesn't find anything
search(searcher, analyzer, "id:person/wendy");
// this query doesn't find anything
search(searcher, analyzer, "id:person123");
// this query works
search(searcher, analyzer, "id:person/john id:person/wendy"); //
this query doesn't find anything
}
private static void search(Searcher searcher, Analyzer analyzer,
String queryString) throws Exception {
Query query = QueryParser.parse(queryString, "macrfulltext",
analyzer);
Hits hits = searcher.search(query);
System.out.println(query.toString("macrfulltext") + ": " +
hits.length() + " hits");
for (int i = 0; i < hits.length(); i++) {
System.out.println(" " + hits.doc(i).get("id"));
}
}
}
keyword whose value contains punctuation.
Here is the test case:
import org.apache.lucene.queryParser.*;
import org.apache.lucene.search.*;
import org.apache.lucene.index.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*;
public class KeywordTest {
public static void main(String args[]) throws Exception {
Analyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter("index", analyzer, true);
Document d3 = new Document();
d3.add(Field.Keyword("id","person/john"));
d3.add(Field.Text("macrinstfulltext","male married"));
writer.addDocument(d3);
Document d4 = new Document();
d4.add(Field.Keyword("id","person/wendy"));
d4.add(Field.Text("macrinstfulltext","female Single"));
writer.addDocument(d4);
Document d5 = new Document();
d5.add(Field.Keyword("id","person123"));
d5.add(Field.Text("macrinstfulltext","female Single"));
writer.addDocument(d5);
writer.close();
IndexReader reader = IndexReader.open("index");
Searcher searcher = new IndexSearcher(reader);
search(searcher, analyzer, "id:person/john");
// this query doesn't find anything
search(searcher, analyzer, "id:person/wendy");
// this query doesn't find anything
search(searcher, analyzer, "id:person123");
// this query works
search(searcher, analyzer, "id:person/john id:person/wendy"); //
this query doesn't find anything
}
private static void search(Searcher searcher, Analyzer analyzer,
String queryString) throws Exception {
Query query = QueryParser.parse(queryString, "macrfulltext",
analyzer);
Hits hits = searcher.search(query);
System.out.println(query.toString("macrfulltext") + ": " +
hits.length() + " hits");
for (int i = 0; i < hits.length(); i++) {
System.out.println(" " + hits.doc(i).get("id"));
}
}
}