use of org.apache.lucene.search.WildcardQuery in project neo4j by neo4j.
the class LuceneDocumentStructure method newWildCardStringQuery.
public static Query newWildCardStringQuery(String searchFor) {
String searchTerm = QueryParser.escape(searchFor);
Term term = new Term(ValueEncoding.String.key(0), "*" + searchTerm + "*");
return new WildcardQuery(term);
}
use of org.apache.lucene.search.WildcardQuery in project neo4j by neo4j.
the class LuceneDocumentStructure method newSuffixStringQuery.
public static Query newSuffixStringQuery(String suffix) {
String searchTerm = QueryParser.escape(suffix);
Term term = new Term(ValueEncoding.String.key(0), "*" + searchTerm);
return new WildcardQuery(term);
}
use of org.apache.lucene.search.WildcardQuery in project neo4j by neo4j.
the class LuceneDocumentStructureTest method shouldBuildWildcardQueries.
@Test
public void shouldBuildWildcardQueries() throws Exception {
// given
WildcardQuery query = (WildcardQuery) LuceneDocumentStructure.newWildCardStringQuery("foo");
// then
assertEquals("string", query.getField());
}
use of org.apache.lucene.search.WildcardQuery in project intellij-community by JetBrains.
the class MavenClassSearcher method preparePatternAndQuery.
protected Pair<String, Query> preparePatternAndQuery(String pattern) {
pattern = pattern.toLowerCase();
if (pattern.trim().length() == 0) {
return new Pair<>(pattern, new MatchAllDocsQuery());
}
List<String> parts = StringUtil.split(pattern, ".");
StringBuilder newPattern = new StringBuilder();
for (int i = 0; i < parts.size() - 1; i++) {
String each = parts.get(i);
newPattern.append(each.trim());
newPattern.append("*.");
}
String className = parts.get(parts.size() - 1);
boolean exactSearch = className.endsWith(" ");
newPattern.append(className.trim());
if (!exactSearch)
newPattern.append("*");
pattern = newPattern.toString();
String queryPattern = "*/" + pattern.replaceAll("\\.", "/");
return new Pair<>(pattern, new WildcardQuery(new Term(TERM, queryPattern)));
}
use of org.apache.lucene.search.WildcardQuery in project intellij-community by JetBrains.
the class MavenIndicesTest method testSearchingForClasses.
public void testSearchingForClasses() throws Exception {
MavenIndex i = myIndices.add("id", myRepositoryHelper.getTestDataPath("local1"), MavenIndex.Kind.LOCAL);
myIndices.updateOrRepair(i, true, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
assertSearchResults(i, new WildcardQuery(new Term(MavenServerIndexer.SEARCH_TERM_CLASS_NAMES, "*runwith*")), "junit:junit:4.0");
}
Aggregations