Minor fix
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-data-search-client@124103 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8885e36c90
commit
eadda06e39
|
@ -4,10 +4,7 @@ import java.io.IOException;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
@ -15,7 +12,6 @@ import org.elasticsearch.action.delete.DeleteResponse;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
||||
|
@ -23,7 +19,6 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
|
|||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.TermsQueryBuilder;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.highlight.HighlightField;
|
||||
import org.gcube.portal.databook.shared.EnhancedFeed;
|
||||
import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster;
|
||||
import org.gcube.socialnetworking.social_data_indexing_common.utils.IndexFields;
|
||||
|
@ -108,11 +103,11 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
|
|||
@Override
|
||||
public List<EnhancedFeed> searchInEnhancedFeeds(String query, Set<String> vreIDS, int from, int to){
|
||||
|
||||
if(from < 0 || to <= 0)
|
||||
return new ArrayList<EnhancedFeed>();
|
||||
|
||||
List<EnhancedFeed> toReturn = new ArrayList<>();
|
||||
|
||||
if(from < 0 || to <= 0)
|
||||
return toReturn;
|
||||
|
||||
// build the query
|
||||
MultiMatchQueryBuilder mq = QueryBuilders.multiMatchQuery(
|
||||
query,
|
||||
|
@ -144,10 +139,6 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
|
|||
.setQuery(filteredQuery)
|
||||
.setFrom(from)
|
||||
.setSize(to)
|
||||
.setHighlighterPreTags("<em><b>")
|
||||
.setHighlighterPostTags("</b></em>")
|
||||
.addHighlightedField(IndexFields.EF_FEED_TEXT)
|
||||
//.addHighlightedField(IndexFields.EF_COMMENT_TEXT) TODO
|
||||
.setExplain(true)
|
||||
.execute()
|
||||
.actionGet();
|
||||
|
@ -164,30 +155,9 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
|
|||
for (SearchHit hit : results) {
|
||||
EnhancedFeed enhFeed;
|
||||
try {
|
||||
|
||||
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class);
|
||||
|
||||
// highlight returned object
|
||||
Map<String, HighlightField> fields = hit.getHighlightFields();
|
||||
Iterator<Entry<String, HighlightField>> iterator = fields.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String,HighlightField> entry = iterator.next();
|
||||
|
||||
switch (entry.getKey()) {
|
||||
case IndexFields.EF_FEED_TEXT:
|
||||
Text highlightedText = entry.getValue().fragments()[0];
|
||||
enhFeed.getFeed().setDescription(highlightedText.toString());
|
||||
break;
|
||||
|
||||
// case IndexFields.EF_COMMENT_TEXT: TODO
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_log.debug("Score is " + hit.score() + " result is " + enhFeed.toString());
|
||||
toReturn.add(enhFeed);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -42,7 +42,8 @@ public class Tests
|
|||
ElasticSearchClientImpl el = new ElasticSearchClientImpl("gcube");
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.add("/gcube/devsec/devVRE");
|
||||
el.searchInEnhancedFeeds("walter white", set, 0, 10);
|
||||
set.add("/gcube/devsec/OpenAireDevVRE");
|
||||
el.searchInEnhancedFeeds("#pippo test", set, 0, 10);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue