Search in sources :

Example 1 with SearchFunction

use of org.apache.rya.indexing.SearchFunction in project incubator-rya by apache.

the class FreeTextTupleSet method evaluate.

/**
 * Returns an iterator over the result set of the contained {@link IndexExpr}.
 * <p>
 * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
 * method can be expected with some query evaluators.
 */
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) throws QueryEvaluationException {
    URI funcURI = filterInfo.getFunction();
    SearchFunction searchFunction = new SearchFunction() {

        @Override
        public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, StatementConstraints contraints) throws QueryEvaluationException {
            try {
                CloseableIteration<Statement, QueryEvaluationException> statements = freeTextIndexer.queryText(queryText, contraints);
                return statements;
            } catch (IOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public String toString() {
            return "TEXT";
        }
    };
    if (filterInfo.getArguments().length > 1) {
        throw new IllegalArgumentException("Index functions do not support more than two arguments.");
    }
    String queryText = ((Value) filterInfo.getArguments()[0]).stringValue();
    return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Statement(org.openrdf.model.Statement) Value(org.openrdf.model.Value) IOException(java.io.IOException) URI(org.openrdf.model.URI) SearchFunction(org.apache.rya.indexing.SearchFunction)

Example 2 with SearchFunction

use of org.apache.rya.indexing.SearchFunction in project incubator-rya by apache.

the class GeoTupleSet method evaluate.

/**
 * Returns an iterator over the result set of the contained IndexingExpr.
 * <p>
 * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
 * method can be expected with some query evaluators.
 */
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
    final URI funcURI = filterInfo.getFunction();
    final SearchFunction searchFunction = new GeoSearchFunctionFactory(conf, geoIndexer).getSearchFunction(funcURI);
    String queryText;
    Object arg = filterInfo.getArguments()[0];
    if (arg instanceof Value) {
        queryText = ((Value) arg).stringValue();
    } else if (arg instanceof Var) {
        queryText = bindings.getBinding(((Var) arg).getName()).getValue().stringValue();
    } else {
        throw new IllegalArgumentException("Query text was not resolved");
    }
    if (funcURI.equals(GeoConstants.GEO_SF_NEAR)) {
        if (filterInfo.getArguments().length > 3) {
            throw new IllegalArgumentException("Near functions do not support more than four arguments.");
        }
        final List<String> valueList = new ArrayList<>();
        for (final Object val : filterInfo.getArguments()) {
            if (val instanceof Value) {
                valueList.add(((Value) val).stringValue());
            } else if (val instanceof Var) {
                valueList.add(bindings.getBinding(((Var) val).getName()).getValue().stringValue());
            } else {
                throw new IllegalArgumentException("Query text was not resolved");
            }
        }
        queryText = String.join(NEAR_DELIM, valueList);
    } else if (filterInfo.getArguments().length > 1) {
        throw new IllegalArgumentException("Index functions do not support more than two arguments.");
    }
    try {
        final CloseableIteration<BindingSet, QueryEvaluationException> iterrez = IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
        return iterrez;
    } catch (final Exception e) {
        System.out.println(e.getMessage());
        throw e;
    }
}
Also used : BindingSet(org.openrdf.query.BindingSet) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URI(org.openrdf.model.URI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) ParseException(com.vividsolutions.jts.io.ParseException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Value(org.openrdf.model.Value) SearchFunction(org.apache.rya.indexing.SearchFunction)

Example 3 with SearchFunction

use of org.apache.rya.indexing.SearchFunction in project incubator-rya by apache.

the class MongoGeoTupleSet method evaluate.

/**
 * Returns an iterator over the result set of the contained IndexingExpr.
 * <p>
 * Should be thread-safe (concurrent invocation {@link OfflineIterable} this
 * method can be expected with some query evaluators.
 */
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) throws QueryEvaluationException {
    URI funcURI = filterInfo.getFunction();
    SearchFunction searchFunction = (new MongoGeoSearchFunctionFactory(conf)).getSearchFunction(funcURI);
    if (filterInfo.getArguments().length > 1) {
        throw new IllegalArgumentException("Index functions do not support more than two arguments.");
    }
    String queryText = ((Value) filterInfo.getArguments()[0]).stringValue();
    return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction);
}
Also used : Value(org.openrdf.model.Value) URI(org.openrdf.model.URI) SearchFunction(org.apache.rya.indexing.SearchFunction)

Aggregations

SearchFunction (org.apache.rya.indexing.SearchFunction)3 URI (org.openrdf.model.URI)3 Value (org.openrdf.model.Value)3 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2 ParseException (com.vividsolutions.jts.io.ParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StatementConstraints (org.apache.rya.indexing.StatementConstraints)1 Statement (org.openrdf.model.Statement)1 BindingSet (org.openrdf.query.BindingSet)1 Var (org.openrdf.query.algebra.Var)1