Spring SnarlTemplate could use a search method

1 view
Skip to first unread message

Roman Sova

unread,
Aug 14, 2014, 5:15:16 PM8/14/14
to sta...@clarkparsia.com

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;

}


}

Mike Grove

unread,
Aug 15, 2014, 10:06:05 AM8/15/14
to stardog
You could consider using the SPARQL syntax [1] for full-text search, then you would not have to extend the template.

Cheers,



--
-- --
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

Roman Sova

unread,
Sep 15, 2014, 1:43:34 PM9/15/14
to sta...@clarkparsia.com
Michael,
Thank you.
That is what I needed.
Cheers,
Roman
Reply all
Reply to author
Forward
0 new messages