Search in sources :

Example 36 with WildcardQuery

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);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 37 with WildcardQuery

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);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 38 with WildcardQuery

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());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Test(org.junit.Test)

Example 39 with WildcardQuery

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)));
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Pair(com.intellij.openapi.util.Pair)

Example 40 with WildcardQuery

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");
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)71 Term (org.apache.lucene.index.Term)63 BooleanQuery (org.apache.lucene.search.BooleanQuery)30 PrefixQuery (org.apache.lucene.search.PrefixQuery)24 Query (org.apache.lucene.search.Query)22 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)20 TermQuery (org.apache.lucene.search.TermQuery)20 Document (org.apache.lucene.document.Document)17 BoostQuery (org.apache.lucene.search.BoostQuery)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)15 RegexpQuery (org.apache.lucene.search.RegexpQuery)15 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 PhraseQuery (org.apache.lucene.search.PhraseQuery)14 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)14 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)14 Field (org.apache.lucene.document.Field)13 IndexReader (org.apache.lucene.index.IndexReader)13 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13