Search in sources :

Example 6 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project stargate-core by tuplejump.

the class WildcardCondition method query.

/**
     * {@inheritDoc}
     */
@Override
public Query query(Options schema) {
    if (field == null || field.trim().isEmpty()) {
        throw new IllegalArgumentException("Field name required");
    }
    if (value == null || value.trim().isEmpty()) {
        throw new IllegalArgumentException("Field value required");
    }
    Query query;
    Properties properties = schema.getProperties(field);
    Type fieldType = properties != null ? properties.getType() : Type.text;
    if (fieldType.isCharSeq()) {
        Term term = new Term(field, value);
        query = new WildcardQuery(term);
    } else {
        String message = String.format("Wildcard queries are not supported by %s mapper", fieldType);
        throw new UnsupportedOperationException(message);
    }
    return query;
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Type(com.tuplejump.stargate.lucene.Type) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term) Properties(com.tuplejump.stargate.lucene.Properties)

Example 7 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project intellij-community by JetBrains.

the class MavenIndicesTest method testCorrectlyClosingIndicesOnRemoteFacadeShutdown.

public void testCorrectlyClosingIndicesOnRemoteFacadeShutdown() throws Exception {
    MavenIndex i = myIndices.add("id", myRepositoryHelper.getTestDataPath("local1"), MavenIndex.Kind.LOCAL);
    myIndices.updateOrRepair(i, true, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
    MavenServerManager.getInstance().shutdown(true);
    initIndices();
    i = myIndices.getIndices().get(0);
    assertSearchResults(i, new WildcardQuery(new Term(MavenServerIndexer.SEARCH_TERM_COORDINATES, "*junit*")), "junit:junit:3.8.1", "junit:junit:3.8.2", "junit:junit:4.0");
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 8 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project intellij-community by JetBrains.

the class MavenIndicesTest method testSearching.

public void testSearching() 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_COORDINATES, "*junit*")), "junit:junit:3.8.1", "junit:junit:3.8.2", "junit:junit:4.0");
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 9 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project jackrabbit-oak by apache.

the class LucenePropertyIndex method createLikeQuery.

private static Query createLikeQuery(String name, String first) {
    first = first.replace('%', WildcardQuery.WILDCARD_STRING);
    first = first.replace('_', WildcardQuery.WILDCARD_CHAR);
    int indexOfWS = first.indexOf(WildcardQuery.WILDCARD_STRING);
    int indexOfWC = first.indexOf(WildcardQuery.WILDCARD_CHAR);
    int len = first.length();
    if (indexOfWS == len || indexOfWC == len) {
        // remove trailing "*" for prefixquery
        first = first.substring(0, first.length() - 1);
        if (JCR_PATH.equals(name)) {
            return new PrefixQuery(newPathTerm(first));
        } else {
            return new PrefixQuery(new Term(name, first));
        }
    } else {
        if (JCR_PATH.equals(name)) {
            return new WildcardQuery(newPathTerm(first));
        } else {
            return new WildcardQuery(new Term(name, first));
        }
    }
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term) TermFactory.newAncestorTerm(org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newAncestorTerm) TermFactory.newPathTerm(org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm) FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm)

Example 10 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class EnwikiQueryMaker method getPrebuiltQueries.

private static Query[] getPrebuiltQueries(String field) {
    WildcardQuery wcq = new WildcardQuery(new Term(field, "fo*"));
    wcq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
    // be wary of unanalyzed text
    return new Query[] { new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 5), new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(field, "night")), new SpanTermQuery(new Term(field, "trading")) }, 4, false), new SpanNearQuery(new SpanQuery[] { new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 10), new SpanTermQuery(new Term(field, "credit")) }, 10, false), wcq };
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)69 Term (org.apache.lucene.index.Term)61 BooleanQuery (org.apache.lucene.search.BooleanQuery)28 PrefixQuery (org.apache.lucene.search.PrefixQuery)24 Query (org.apache.lucene.search.Query)21 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)20 TermQuery (org.apache.lucene.search.TermQuery)18 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 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 PhraseQuery (org.apache.lucene.search.PhraseQuery)13 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13