* @throws Exception
*/
public void testParsingAndSearching() throws Exception {
String field = "content";
boolean dbg = false;
QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, field, new WhitespaceAnalyzer());
qp.setAllowLeadingWildcard(true);
String docs[] = {
"\\ abcdefg1",
"\\79 hijklmn1",
"\\\\ opqrstu1",
};
// queries that should find all docs
String matchAll[] = {
"*", "*1", "**1", "*?", "*?1", "?*1", "**", "***", "\\\\*"
};
// queries that should find no docs
String matchNone[] = {
"a*h", "a?h", "*a*h", "?a", "a?",
};
// queries that should be parsed to prefix queries
String matchOneDocPrefix[][] = {
{"a*", "ab*", "abc*", }, // these should find only doc 0
{"h*", "hi*", "hij*", "\\\\7*"}, // these should find only doc 1
{"o*", "op*", "opq*", "\\\\\\\\*"}, // these should find only doc 2
};
// queries that should be parsed to wildcard queries
String matchOneDocWild[][] = {
{"*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**"}, // these should find only doc 0
{"*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**"}, // these should find only doc 1
{"*o*", "*op*", "*opq**", "op*q*", "*u?", "*t?1", "opq**"}, // these should find only doc 2
};
// prepare the index
RAMDirectory dir = new RAMDirectory();
IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
for (int i = 0; i < docs.length; i++) {
Document doc = new Document();
doc.add(new Field(field,docs[i],Store.NO,Index.ANALYZED));
iw.addDocument(doc);
}