Hi,
I run into a minor limitation on the great and all-mighty SnarlTemplate where I wanted to run my text-search and reasoning query at the same time. Below is my solution.
I could be running with scissors here, but this what I ended up doing.
I basically extended the SnarlTemplate class, for my own use.
Is there any plans in the future to enable the SnarlTemplate class to handle search connections as well?
Cheers,
Roman
package com.complexible.stardog.ext.spring;
import java.util.ArrayList;
import java.util.List;
import org.openrdf.query.QueryEvaluationException;
import com.complexible.common.iterations.Iteration;
import com.complexible.stardog.StardogException;
import com.complexible.stardog.api.search.SearchConnection;
import com.complexible.stardog.api.search.SearchResult;
import com.complexible.stardog.api.search.SearchResults;
import com.complexible.stardog.api.search.Searcher;
public class SnarlTemplatePlus extends SnarlTemplate {
public List<SearchResult> search(int limit, String searchQuery, double threshold) {
List<SearchResult> resultList = new ArrayList<SearchResult>();
SearchConnection connection = null;
try {
connection = getDataSource().getConnection().as(SearchConnection.class);
Searcher aSearch = connection.search().limit(limit).query(searchQuery).threshold(threshold);
SearchResults aSearchResults = aSearch.search();
Iteration<SearchResult, QueryEvaluationException> results = aSearchResults.iteration();
while (results.hasNext()) {
resultList.add(results.next());
}
results.close();
} catch (StardogException e) {
log.error("Error during search", e);
throw new RuntimeException(e);
} catch (QueryEvaluationException e) {
log.error("Error during processing search results", e);
throw new RuntimeException(e);
} finally {
getDataSource().releaseConnection(connection);
}
return resultList;
}
}
--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en