Search in sources :

Example 1 with ParseException

use of com.orientechnologies.orient.core.sql.parser.ParseException in project orientdb by orientechnologies.

the class OCommandExecutorScript method executeInContext.

public Object executeInContext(final OCommandContext iContext, final Map<Object, Object> iArgs) {
    final String language = request.getLanguage();
    parserText = request.getText();
    parameters = iArgs;
    parameters = iArgs;
    if (language.equalsIgnoreCase("SQL")) {
        // SPECIAL CASE: EXECUTE THE COMMANDS IN SEQUENCE
        try {
            parserText = preParse(parserText, iArgs);
        } catch (ParseException e) {
            throw new OCommandExecutionException("Invalid script:" + e.getMessage());
        }
        return executeSQL();
    } else {
        return executeJsr223Script(language, iContext, iArgs);
    }
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException)

Example 2 with ParseException

use of com.orientechnologies.orient.core.sql.parser.ParseException in project orientdb by orientechnologies.

the class OLuceneTextOperator method evaluateRecord.

@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight, OCommandContext iContext) {
    OLuceneFullTextIndex index = involvedIndex(iRecord, iCurrentResult, iCondition, iLeft, iRight);
    if (index == null) {
        throw new OCommandExecutionException("Cannot evaluate lucene condition without index configuration.");
    }
    MemoryIndex memoryIndex = (MemoryIndex) iContext.getVariable(MEMORY_INDEX);
    if (memoryIndex == null) {
        memoryIndex = new MemoryIndex();
        iContext.setVariable(MEMORY_INDEX, memoryIndex);
    }
    memoryIndex.reset();
    try {
        for (IndexableField field : index.buildDocument(iLeft).getFields()) {
            memoryIndex.addField(field.name(), field.tokenStream(index.indexAnalyzer(), null));
        }
        return memoryIndex.search(index.buildQuery(iRight)) > 0.0f;
    } catch (ParseException e) {
        OLogManager.instance().error(this, "error occurred while building query", e);
    } catch (IOException e) {
        OLogManager.instance().error(this, "error occurred while building memory index", e);
    }
    return null;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) MemoryIndex(org.apache.lucene.index.memory.MemoryIndex) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) IOException(java.io.IOException)

Example 3 with ParseException

use of com.orientechnologies.orient.core.sql.parser.ParseException 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)

Example 4 with ParseException

use of com.orientechnologies.orient.core.sql.parser.ParseException in project orientdb by orientechnologies.

the class OLuceneFullTextIndexEngine method getInTx.

@Override
public Object getInTx(Object key, OLuceneTxChanges changes) {
    try {
        Query q = queryBuilder.query(index, key, queryAnalyzer());
        OCommandContext context = null;
        if (key instanceof OLuceneCompositeKey) {
            context = ((OLuceneCompositeKey) key).getContext();
        }
        return getResults(q, context, key, changes);
    } catch (ParseException e) {
        throw OException.wrapException(new OIndexEngineException("Error parsing lucene query"), e);
    }
}
Also used : OLuceneCompositeKey(com.orientechnologies.lucene.collections.OLuceneCompositeKey) Query(org.apache.lucene.search.Query) OCommandContext(com.orientechnologies.orient.core.command.OCommandContext) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException)

Aggregations

ParseException (com.orientechnologies.orient.core.sql.parser.ParseException)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 OLuceneCompositeKey (com.orientechnologies.lucene.collections.OLuceneCompositeKey)1 OLuceneFullTextIndex (com.orientechnologies.lucene.index.OLuceneFullTextIndex)1 OLuceneMultiFieldQueryParser (com.orientechnologies.lucene.parser.OLuceneMultiFieldQueryParser)1 OCommandContext (com.orientechnologies.orient.core.command.OCommandContext)1 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)1 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IndexableField (org.apache.lucene.index.IndexableField)1 MemoryIndex (org.apache.lucene.index.memory.MemoryIndex)1 Query (org.apache.lucene.search.Query)1