public virtual void TestEscapes()
{
Directory indexStore = GetIndexStore("field", new string[] { "foo*bar", "foo??bar", "fooCDbar", "fooSOMETHINGbar", "foo\\" });
IndexReader reader = DirectoryReader.Open(indexStore);
IndexSearcher searcher = NewSearcher(reader);
// without escape: matches foo??bar, fooCDbar, foo*bar, and fooSOMETHINGbar
WildcardQuery unescaped = new WildcardQuery(new Term("field", "foo*bar"));
AssertMatches(searcher, unescaped, 4);
// with escape: only matches foo*bar
WildcardQuery escaped = new WildcardQuery(new Term("field", "foo\\*bar"));
AssertMatches(searcher, escaped, 1);
// without escape: matches foo??bar and fooCDbar
unescaped = new WildcardQuery(new Term("field", "foo??bar"));
AssertMatches(searcher, unescaped, 2);
// with escape: matches foo??bar only
escaped = new WildcardQuery(new Term("field", "foo\\?\\?bar"));
AssertMatches(searcher, escaped, 1);
// check escaping at end: lenient parse yields "foo\"
WildcardQuery atEnd = new WildcardQuery(new Term("field", "foo\\"));
AssertMatches(searcher, atEnd, 1);
reader.Dispose();
indexStore.Dispose();
}