Search in sources :

Example 1 with OLuceneMultiFieldQueryParser

use of com.orientechnologies.lucene.parser.OLuceneMultiFieldQueryParser in project orientdb by orientechnologies.

the class OLuceneQueryBuilder method getQueryParser.

protected Query getQueryParser(OIndexDefinition index, String key, Analyzer analyzer) throws ParseException {
    String[] fields;
    if (index.isAutomatic()) {
        fields = index.getFields().toArray(new String[index.getFields().size()]);
    } else {
        int length = index.getTypes().length;
        fields = new String[length];
        for (int i = 0; i < length; i++) {
            fields[i] = "k" + i;
        }
    }
    Map<String, OType> types = new HashMap<String, OType>();
    for (int i = 0; i < fields.length; i++) {
        String field = fields[i];
        types.put(field, index.getTypes()[i]);
    }
    //    for (Map.Entry<String, OType> typeEntry : types.entrySet()) {
    //      System.out.println("typeEntry = " + typeEntry);
    //    }
    final OLuceneMultiFieldQueryParser queryParser = new OLuceneMultiFieldQueryParser(types, fields, analyzer);
    queryParser.setAllowLeadingWildcard(allowLeadingWildcard);
    queryParser.setLowercaseExpandedTerms(lowercaseExpandedTerms);
    try {
        return queryParser.parse(key);
    } catch (org.apache.lucene.queryparser.classic.ParseException e) {
        throw new ParseException(e.getMessage());
    }
}
Also used : OLuceneMultiFieldQueryParser(com.orientechnologies.lucene.parser.OLuceneMultiFieldQueryParser) HashMap(java.util.HashMap) OType(com.orientechnologies.orient.core.metadata.schema.OType) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException)

Aggregations

OLuceneMultiFieldQueryParser (com.orientechnologies.lucene.parser.OLuceneMultiFieldQueryParser)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 ParseException (com.orientechnologies.orient.core.sql.parser.ParseException)1 HashMap (java.util.HashMap)1