Java Code Examples for org.apache.lucene.sandbox.queries.regex.RegexQuery

The following examples show how to use org.apache.lucene.sandbox.queries.regex.RegexQuery. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query apply(Function input, Context context) throws IOException {
    Tuple<Reference, Literal> prepare = prepare(input);
    if (prepare == null) { return null; }
    String fieldName = prepare.v1().info().ident().columnIdent().fqn();
    Object value = prepare.v2().value();

    if (value instanceof BytesRef) {
        BytesRef pattern = ((BytesRef) value);
        if (isPcrePattern(pattern.utf8ToString())) {
            return new RegexQuery(new Term(fieldName, pattern));
        } else {
            return toLuceneRegexpQuery(fieldName, pattern, context);
        }
    }
    throw new IllegalArgumentException("Can only use ~ with patterns of type string");
}
 
Example 2
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query apply(Function input, Context context) throws IOException {
    Tuple<Reference, Literal> prepare = prepare(input);
    if (prepare == null) { return null; }
    String fieldName = prepare.v1().info().ident().columnIdent().fqn();
    Object value = prepare.v2().value();

    if (value instanceof BytesRef) {
        RegexQuery query = new RegexQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
        query.setRegexImplementation(new JavaUtilRegexCapabilities(
                JavaUtilRegexCapabilities.FLAG_CASE_INSENSITIVE |
                JavaUtilRegexCapabilities.FLAG_UNICODE_CASE));
        return query;
    }
    throw new IllegalArgumentException("Can only use ~* with patterns of type string");
}
 
Example 3
Source Project: incubator-atlas   Source File: RegexQueryExpression.java    License: Apache License 2.0 2 votes vote down vote up
public RegexQueryExpression(RegexQuery query, ResourceDefinition resourceDefinition) {
    super(query.getField(), query.getTerm().text(), resourceDefinition);

}