Search in sources :

Example 6 with Properties

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

the class PhraseCondition method query.

/**
     * {@inheritDoc}
     */
@Override
public Query query(Options schema) {
    if (field == null || field.trim().isEmpty()) {
        throw new IllegalArgumentException("Field name required");
    }
    if (values == null) {
        throw new IllegalArgumentException("Field values required");
    }
    if (slop == null) {
        throw new IllegalArgumentException("Slop required");
    }
    if (slop < 0) {
        throw new IllegalArgumentException("Slop must be positive");
    }
    Properties properties = schema.getProperties(field);
    Type fieldType = properties != null ? properties.getType() : Type.text;
    if (fieldType.isCharSeq()) {
        Analyzer analyzer = schema.analyzer;
        PhraseQuery.Builder query = new PhraseQuery.Builder();
        query.setSlop(slop);
        int count = 0;
        for (String value : values) {
            if (value != null) {
                String analyzedValue = analyze(field, value, analyzer);
                if (analyzedValue != null) {
                    Term term = new Term(field, analyzedValue);
                    query.add(term, count);
                }
            }
            count++;
        }
        return query.build();
    }
    String message = String.format("Phrase queries cannot be supported until mapping is defined");
    throw new UnsupportedOperationException(message);
}
Also used : Type(com.tuplejump.stargate.lucene.Type) PhraseQuery(org.apache.lucene.search.PhraseQuery) Term(org.apache.lucene.index.Term) Properties(com.tuplejump.stargate.lucene.Properties) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 7 with Properties

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

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

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

the class AggregateFunction method load.

public void load(Tuple tuple, IndexEntryCollector.IndexEntry entry) {
    for (String field : positions.keySet()) {
        Type validator = options.types.get(field);
        load(tuple, entry, field, validator);
        if (validator == null) {
            Iterator<String> fieldNameParts = Constants.dotSplitter.split(field).iterator();
            String columnName = fieldNameParts.next();
            if (options.nestedFields.contains(columnName)) {
                Properties columnProps = options.fields.get(columnName);
                Properties fieldProps;
                if (columnProps.getType() == Type.map) {
                    fieldProps = columnProps.getFields().get("_value");
                } else {
                    fieldProps = columnProps.getFields().get(fieldNameParts.next());
                }
                load(tuple, entry, field, fieldProps.getType());
            }
        }
    }
}
Also used : Properties(com.tuplejump.stargate.lucene.Properties)

Example 10 with Properties

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

the class JsonDocumentTest method shouldParseJsonAndGetFields.

@Test
public void shouldParseJsonAndGetFields() throws Exception {
    Properties jsonColProps = new Properties();
    jsonColProps.setType(Type.object);
    Properties ageProps = new Properties();
    ageProps.setType(Type.integer);
    //json fields mapping
    jsonColProps.setFields(Collections.singletonMap("age", ageProps));
    Properties rootProps = new Properties();
    rootProps.setFields(Collections.singletonMap("jsoncol", jsonColProps));
    StringWriter sw = new StringWriter();
    PrintWriter writer = new PrintWriter(sw);
    //formatJsonNode(kid, writer, 0);
    formatJsonNode(jsonVal, writer, 0);
    writer.flush();
    String json = sw.toString();
    JsonDocument jsonDocument = new StreamingJsonDocument(json, rootProps, "jsoncol");
    List<Field> fields = jsonDocument.getFields();
    System.out.println(fields);
    System.out.println("Overall fields:" + fields.size());
    Assert.assertEquals(75, fields.size());
    Assert.assertEquals(5, numberOfFieldsWithKey("name", fields));
    Assert.assertEquals(15, numberOfFieldsWithPrefix("friends", fields));
    Assert.assertEquals(15, numberOfFieldsWithKey("friends.name", fields));
    Assert.assertEquals(15, numberOfFieldsWithKey("tags", fields));
    Assert.assertEquals(5, numberOfFieldsWithNumericType(FieldType.NumericType.INT, fields));
    MemIndex memIndex = new MemIndex(rootProps);
    List<JsonNode> kids = jsonVal.getElements();
    for (JsonNode kid : kids) {
        StringWriter kidSWriter = new StringWriter();
        PrintWriter kidWriter = new PrintWriter(kidSWriter);
        formatJsonNode(kid, kidWriter, 0);
        kidWriter.flush();
        String kidJson = kidSWriter.toString();
        JsonDocument kidDoc = new StreamingJsonDocument(kidJson, rootProps, "jsoncol");
        memIndex.add(kidDoc.getFields());
    }
    Assert.assertEquals(1, memIndex.hits("age:40", "jsoncol"));
    Assert.assertEquals(2, memIndex.hits("eyeColor:blue", "jsoncol"));
    Assert.assertEquals(2, memIndex.hits("gender:female", "jsoncol"));
}
Also used : Field(org.apache.lucene.document.Field) JsonField(argo.jdom.JsonField) StreamingJsonDocument(com.tuplejump.stargate.lucene.json.StreamingJsonDocument) JsonNode(argo.jdom.JsonNode) Properties(com.tuplejump.stargate.lucene.Properties) JsonDocument(com.tuplejump.stargate.lucene.json.JsonDocument) StreamingJsonDocument(com.tuplejump.stargate.lucene.json.StreamingJsonDocument) Test(org.junit.Test)

Aggregations

Properties (com.tuplejump.stargate.lucene.Properties)13 Type (com.tuplejump.stargate.lucene.Type)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 Analyzer (org.apache.lucene.analysis.Analyzer)2 FieldType (org.apache.lucene.document.FieldType)2 JsonField (argo.jdom.JsonField)1 JsonNode (argo.jdom.JsonNode)1 Options (com.tuplejump.stargate.lucene.Options)1 JsonDocument (com.tuplejump.stargate.lucene.json.JsonDocument)1 StreamingJsonDocument (com.tuplejump.stargate.lucene.json.StreamingJsonDocument)1 ParseException (java.text.ParseException)1 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 CQL3Type (org.apache.cassandra.cql3.CQL3Type)1 PerFieldAnalyzerWrapper (org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper)1 Field (org.apache.lucene.document.Field)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1