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);
}
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;
}
}
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);
}
Aggregations