Search in sources :

Example 91 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project kie-wb-common by kiegroup.

the class SearchEmptyQueryBuilder method addRuleNameWildCardTerm.

public SearchEmptyQueryBuilder addRuleNameWildCardTerm() {
    ValueIndexTerm valTerm = new ValueResourceIndexTerm("*", ResourceType.RULE, TermSearchType.WILDCARD);
    queryBuilder.add(new WildcardQuery(new Term(valTerm.getTerm(), valTerm.getValue())), MUST);
    return this;
}
Also used : ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) WildcardQuery(org.apache.lucene.search.WildcardQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) Term(org.apache.lucene.index.Term) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)

Example 92 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project cxf by apache.

the class LuceneQueryVisitor method createEqualsQuery.

private Query createEqualsQuery(Class<?> cls, String name, Object value) {
    final Query query;
    if (cls == String.class) {
        String strValue = value.toString();
        if (caseInsensitiveMatch) {
            strValue = strValue.toLowerCase();
        }
        boolean isWildCard = strValue.contains("*") || super.isWildcardStringMatch();
        String theContentsFieldName = getContentsFieldName(name);
        if (theContentsFieldName == null) {
            if (!isWildCard) {
                query = newTermQuery(name, strValue);
            } else {
                query = new WildcardQuery(new Term(name, strValue));
            }
        } else if (!isWildCard) {
            query = newPhraseQuery(theContentsFieldName, strValue);
        } else {
            query = new WildcardQuery(new Term(theContentsFieldName, strValue));
        }
    } else {
        query = createRangeQuery(cls, name, value, ConditionType.EQUALS);
    }
    return query;
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) PhraseQuery(org.apache.lucene.search.PhraseQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ParamConverterUtils.getString(org.apache.cxf.jaxrs.ext.search.ParamConverterUtils.getString) Term(org.apache.lucene.index.Term)

Example 93 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project ranger by apache.

the class SubsetQueryPlugin method createParser.

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {

        @Override
        public Query parse() throws SyntaxError {
            String fieldName = Preconditions.checkNotNull(localParams.get(SETVAL_FIELD_NAME));
            String countFieldName = Preconditions.checkNotNull(localParams.get(COUNT_FIELD_NAME));
            boolean allowMissingValues = Boolean.parseBoolean(Preconditions.checkNotNull(localParams.get(MISSING_VAL_ALLOWED)));
            String wildcardToken = localParams.get(WILDCARD_CHAR);
            LongValuesSource minimumNumberMatch = LongValuesSource.fromIntField(countFieldName);
            Collection<Query> queries = new ArrayList<>();
            String fieldVals = Preconditions.checkNotNull(localParams.get(SETVAL_PARAM_NAME));
            for (String v : fieldVals.split(",")) {
                queries.add(new TermQuery(new Term(fieldName, v)));
            }
            if (wildcardToken != null && !wildcardToken.equals("")) {
                queries.add(new TermQuery(new Term(fieldName, wildcardToken)));
            }
            if (allowMissingValues) {
                // To construct this query we need to do a little trick tho construct a test for an empty field as follows:
                // (*:* AND -fieldName:*) ==> parses as: (+*:* -fieldName:*)
                // It is a feature of Lucene that pure negative queries are not allowed (although Solr allows them as a top level construct)
                // therefore we need to AND with *:*
                // We can then pass this BooleanQuery to the CoveringQuery as one of its allowed matches.
                BooleanQuery.Builder builder = new BooleanQuery.Builder();
                builder.add(new BooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD));
                builder.add(new BooleanClause(new WildcardQuery(new Term(fieldName, "*")), BooleanClause.Occur.MUST_NOT));
                queries.add(builder.build());
            }
            return new CoveringQuery(queries, minimumNumberMatch);
        }
    };
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) CoveringQuery(org.apache.lucene.search.CoveringQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BooleanClause(org.apache.lucene.search.BooleanClause) QParser(org.apache.solr.search.QParser) CoveringQuery(org.apache.lucene.search.CoveringQuery) LongValuesSource(org.apache.lucene.search.LongValuesSource)

Example 94 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project drools-wb by kiegroup.

the class IndexRuleAttributeNameAndValueTest method testIndexDrlRuleAttributeNameAndValues.

@Test
public void testIndexDrlRuleAttributeNameAndValues() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("drl1.rdrl");
    final String drl = loadText("drl1.rdrl");
    ioService().write(path, drl);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
    {
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        ValueSharedPartIndexTerm indexTerm = new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP);
        queryBuilder.add(new WildcardQuery(new Term(indexTerm.getTerm(), indexTerm.getValue())), BooleanClause.Occur.MUST);
        queryBuilder.add(new WildcardQuery(new Term("shared:nonexistend", "*")), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 0);
    }
    {
        // This could also just be a TermQuery..
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        ValueSharedPartIndexTerm indexTerm = new ValueSharedPartIndexTerm("myruleflowgroup", PartType.RULEFLOW_GROUP);
        queryBuilder.add(new TermQuery(new Term(indexTerm.getTerm(), indexTerm.getValue())), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) BooleanQuery(org.apache.lucene.search.BooleanQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 95 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project querydsl by querydsl.

the class LuceneSerializer method like.

protected Query like(Operation<?> operation, QueryMetadata metadata) {
    verifyArguments(operation);
    Path<?> path = getPath(operation.getArg(0));
    String field = toField(path);
    String[] terms = convert(path, operation.getArg(1));
    if (terms.length > 1) {
        BooleanQuery bq = new BooleanQuery();
        for (String s : terms) {
            bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
        }
        return bq;
    }
    return new WildcardQuery(new Term(field, terms[0]));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)102 Term (org.apache.lucene.index.Term)94 BooleanQuery (org.apache.lucene.search.BooleanQuery)38 TermQuery (org.apache.lucene.search.TermQuery)38 Query (org.apache.lucene.search.Query)29 PrefixQuery (org.apache.lucene.search.PrefixQuery)27 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)23 Document (org.apache.lucene.document.Document)19 IndexSearcher (org.apache.lucene.search.IndexSearcher)17 RegexpQuery (org.apache.lucene.search.RegexpQuery)17 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)16 PhraseQuery (org.apache.lucene.search.PhraseQuery)16 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)16 BoostQuery (org.apache.lucene.search.BoostQuery)15 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)15 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)15 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)15 SpanQuery (org.apache.lucene.search.spans.SpanQuery)15 IndexReader (org.apache.lucene.index.IndexReader)14 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)14