@Override protected Query newWildcardQuery(Term t) { if (t.text().contains("\\")) { String regexp = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, t.text()); return new RegexQuery(new Term(t.field(), regexp)); } else { return super.newWildcardQuery(t); } }
@Override protected Query newPrefixQuery(Term prefix) { if (prefix.text().contains("\\")) { String regexp = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, prefix.text()); return new RegexQuery(new Term(prefix.field(), regexp)); } else { return super.newPrefixQuery(prefix); } }
public void testRegexQuery() throws Exception { Directory directory = TestUtil.getBookIndexDirectory(); IndexSearcher searcher = new IndexSearcher(directory); RegexQuery q = new RegexQuery(new Term("title", ".*st.*")); TopDocs hits = searcher.search(q, 10); assertEquals(2, hits.totalHits); assertTrue(TestUtil.hitsIncludeTitle(searcher, hits, "Tapestry in Action")); assertTrue(TestUtil.hitsIncludeTitle(searcher, hits, "Mindstorms: Children, Computers, And Powerful Ideas")); searcher.close(); directory.close(); }
private RegexQuery makeFullPathRegexQueryFromString(String regex) { return new RegexQuery(TERM_FULL.createTerm(regex)); }