Comment's author is now searchable

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-data-search-client@124089 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-10 17:43:17 +00:00
parent 7b25b47932
commit 61e2cdc58e
2 changed files with 14 additions and 13 deletions

View File

@ -14,10 +14,10 @@ import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
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.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster;
@ -60,9 +60,11 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
ElasticSearchRunningCluster elasticCluster = new ElasticSearchRunningCluster(scope);
// save info
clusterName = elasticCluster.getClusterName();
hostsToContact = elasticCluster.getHosts();
portNumbers = elasticCluster.getPorts();
clusterName = "ElasticSearchCluster";//elasticCluster.getClusterName();
hostsToContact = new ArrayList<>();
hostsToContact.add("localhost");//elasticCluster.getHosts();
portNumbers = new ArrayList<>();
portNumbers.add(9300);//elasticCluster.getPorts();
_log.debug("Creating elasticsearch client for hosts = " + hostsToContact + ", port = " + portNumbers + " and "
+ " cluster's name = " + clusterName);
@ -112,25 +114,25 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
IndexFields.EF_FEED_TEXT + "^2", // weight of 2 for feed's description
IndexFields.EF_ATTACHMENT_NAME,
IndexFields.EF_PREVIEW_DESCRIPTION,
IndexFields.EF_COMMENT_TEXT)
IndexFields.EF_COMMENT_TEXT + "^2",
IndexFields.EF_COMMENT_FULL_NAME)
.type(Type.MOST_FIELDS);
_log.debug(mq.toString());
//_log.debug(mq.toString());
// filter on vre
BoolQueryBuilder filter = QueryBuilders.boolQuery();
MatchQueryBuilder queryFilter = QueryBuilders.matchQuery(IndexFields.EF_FEED_VRE_ID, vreIDS);
queryFilter.type(MatchQueryBuilder.Type.PHRASE);
TermsQueryBuilder queryFilter = QueryBuilders.termsQuery(IndexFields.EF_FEED_VRE_ID, vreIDS);
filter.should(queryFilter);
_log.debug(filter.toString());
//_log.debug(filter.toString());
// final filtered query
BoolQueryBuilder filteredQuery = QueryBuilders.boolQuery();
filteredQuery.must(mq);
filteredQuery.filter(filter);
_log.debug(filteredQuery.toString());
//_log.debug(filteredQuery.toString());
SearchResponse response = client.prepareSearch(IndexFields.INDEX_NAME)
.setQuery(filteredQuery)
@ -152,7 +154,7 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
EnhancedFeed enhFeed;
try {
_log.debug(hit.getSourceAsString());
_log.debug("score " + hit.getScore() + " for " +hit.getSourceAsString());
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class);
// add to the return set
@ -175,5 +177,4 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
return response.isFound();
}
}

View File

@ -44,7 +44,7 @@ public class Tests
Set<String> set = new HashSet<String>();
set.add("/gcube/devsec/devVRE");
set.add("/gcube/devsec/OpenAireDevVRE");
List<EnhancedFeed> res = el.searchInEnhancedFeeds("#pippo", set, 100);
List<EnhancedFeed> res = el.searchInEnhancedFeeds("#pippo test", set, 10);
_log.info("Query result is " + res);
}