Search in sources :

Example 6 with Type

use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.

the class RegexpCondition 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 RegexpQuery(term);
    } else {
        String message = String.format("Regexp queries are not supported by %s mapper", fieldType);
        throw new UnsupportedOperationException(message);
    }
    return query;
}
Also used : Type(com.tuplejump.stargate.lucene.Type) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) Term(org.apache.lucene.index.Term) Properties(com.tuplejump.stargate.lucene.Properties) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 7 with Type

use of com.tuplejump.stargate.lucene.Type 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 8 with Type

use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.

the class CassandraUtils method setFromAbstractType.

public static void setFromAbstractType(Properties properties, AbstractType type) {
    if (properties.getType() != null)
        return;
    CQL3Type cqlType = type.asCQL3Type();
    Type fromAbstractType = fromAbstractType(cqlType);
    properties.setType(fromAbstractType);
}
Also used : CQL3Type(org.apache.cassandra.cql3.CQL3Type) Type(com.tuplejump.stargate.lucene.Type) FieldType(org.apache.lucene.document.FieldType) CQL3Type(org.apache.cassandra.cql3.CQL3Type)

Example 9 with Type

use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.

the class MatchCondition method query.

/**
     * {@inheritDoc}
     */
@Override
public Query query(Options schema) throws Exception {
    if (field == null || field.trim().isEmpty()) {
        throw new IllegalArgumentException("Field name required");
    }
    if (value == null || value instanceof String && ((String) value).trim().isEmpty()) {
        throw new IllegalArgumentException("Field value required");
    }
    NumericConfig numericConfig = schema.numericFieldOptions.get(field);
    Properties properties = schema.getProperties(field);
    Type fieldType = properties != null ? properties.getType() : Type.text;
    Query query;
    if (fieldType.isCharSeq() || fieldType == Type.bool) {
        String analyzedValue = analyze(field, value.toString(), schema.analyzer);
        if (analyzedValue == null) {
            throw new IllegalArgumentException("Value discarded by analyzer");
        }
        Term term = new Term(field, analyzedValue);
        query = new TermQuery(term);
    } else if (fieldType == Type.integer) {
        assert numericConfig != null;
        Integer value = numericConfig.getNumberFormat().parse(this.value.toString()).intValue();
        query = NumericRangeQuery.newIntRange(field, value, value, true, true);
    } else if (fieldType == Type.bigint || fieldType == Type.date) {
        assert numericConfig != null;
        Long value = numericConfig.getNumberFormat().parse(this.value.toString()).longValue();
        query = NumericRangeQuery.newLongRange(field, value, value, true, true);
    } else if (fieldType == Type.decimal) {
        assert numericConfig != null;
        Float value = numericConfig.getNumberFormat().parse(this.value.toString()).floatValue();
        query = NumericRangeQuery.newFloatRange(field, value, value, true, true);
    } else if (fieldType == Type.bigdecimal) {
        assert numericConfig != null;
        Double value = numericConfig.getNumberFormat().parse(this.value.toString()).doubleValue();
        query = NumericRangeQuery.newDoubleRange(field, value, value, true, true);
    } else {
        String message = String.format("Match queries are not supported by %s field type", fieldType);
        throw new UnsupportedOperationException(message);
    }
    return query;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) Properties(com.tuplejump.stargate.lucene.Properties) Type(com.tuplejump.stargate.lucene.Type) NumericConfig(org.apache.lucene.queryparser.flexible.standard.config.NumericConfig)

Example 10 with Type

use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.

the class PrefixCondition method query.

/**
     * {@inheritDoc}
     */
@Override
public Query query(Options schema) {
    if (field == null || field.trim().isEmpty()) {
        throw new IllegalArgumentException("Field name required");
    }
    if (value == null) {
        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 PrefixQuery(term);
    } else {
        String message = String.format("Prefix queries are not supported by %s mapper", fieldType);
        throw new UnsupportedOperationException(message);
    }
    return query;
}
Also used : Type(com.tuplejump.stargate.lucene.Type) Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term) Properties(com.tuplejump.stargate.lucene.Properties)

Aggregations

Type (com.tuplejump.stargate.lucene.Type)11 Properties (com.tuplejump.stargate.lucene.Properties)9 Term (org.apache.lucene.index.Term)6 Query (org.apache.lucene.search.Query)5 NumericConfig (org.apache.lucene.queryparser.flexible.standard.config.NumericConfig)3 CQL3Type (org.apache.cassandra.cql3.CQL3Type)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 FieldType (org.apache.lucene.document.FieldType)2 Options (com.tuplejump.stargate.lucene.Options)1 ParseException (java.text.ParseException)1 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 PerFieldAnalyzerWrapper (org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 PhraseQuery (org.apache.lucene.search.PhraseQuery)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1 RegexpQuery (org.apache.lucene.search.RegexpQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 WildcardQuery (org.apache.lucene.search.WildcardQuery)1