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;
}
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;
}
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);
}
};
}
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);
}
}
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]));
}
Aggregations