diff --git a/src/main/java/org/gcube/socialnetworking/social_data_search_client/ElasticSearchClientImpl.java b/src/main/java/org/gcube/socialnetworking/social_data_search_client/ElasticSearchClientImpl.java index d360f82..21e2cd9 100644 --- a/src/main/java/org/gcube/socialnetworking/social_data_search_client/ElasticSearchClientImpl.java +++ b/src/main/java/org/gcube/socialnetworking/social_data_search_client/ElasticSearchClientImpl.java @@ -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(); } - } diff --git a/src/test/java/org/gcube/socialnetworking/social_data_search_client/Tests.java b/src/test/java/org/gcube/socialnetworking/social_data_search_client/Tests.java index 084382f..123c4e4 100644 --- a/src/test/java/org/gcube/socialnetworking/social_data_search_client/Tests.java +++ b/src/test/java/org/gcube/socialnetworking/social_data_search_client/Tests.java @@ -44,7 +44,7 @@ public class Tests Set set = new HashSet(); set.add("/gcube/devsec/devVRE"); set.add("/gcube/devsec/OpenAireDevVRE"); - List res = el.searchInEnhancedFeeds("#pippo", set, 100); + List res = el.searchInEnhancedFeeds("#pippo test", set, 10); _log.info("Query result is " + res); }