Do not return disabled feeds (double check)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-data-search-client@124163 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-15 09:24:49 +00:00
parent f7c12467ff
commit fe7316dc90
2 changed files with 14 additions and 8 deletions

View File

@ -20,6 +20,7 @@ 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.portal.databook.shared.FeedType;
import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster;
import org.gcube.socialnetworking.social_data_indexing_common.utils.IndexFields;
import org.slf4j.Logger;
@ -101,11 +102,11 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
}
@Override
public List<EnhancedFeed> searchInEnhancedFeeds(String query, Set<String> vreIDS, int from, int to){
public List<EnhancedFeed> searchInEnhancedFeeds(String query, Set<String> vreIDS, int from, int quantity){
List<EnhancedFeed> toReturn = new ArrayList<>();
if(from < 0 || to <= 0)
if(from < 0 || quantity <= 0)
return toReturn;
// build the query
@ -138,7 +139,7 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
SearchResponse response = client.prepareSearch(IndexFields.INDEX_NAME)
.setQuery(filteredQuery)
.setFrom(from)
.setSize(to)
.setSize(quantity)
.setExplain(true)
.execute()
.actionGet();
@ -157,13 +158,17 @@ public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
try {
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class);
_log.debug("Score is " + hit.score() + " result is " + enhFeed.toString());
toReturn.add(enhFeed);
// check if it is still valid and add
if(!enhFeed.getFeed().getType().equals(FeedType.DISABLED))
toReturn.add(enhFeed);
} catch (IOException e) {
_log.error(e.toString());
}
}
_log.debug("Returning " + toReturn.size() + " results");
return toReturn;
}

View File

@ -14,14 +14,15 @@ import org.gcube.portal.databook.shared.EnhancedFeed;
public interface ElasticSearchClientInterface {
/**
* Given a query, the method find matching enhanced feeds into the elasticsearch index and return <b>to</b> hits starting from <b>from</b>.
* Given a query, the method find matching enhanced feeds into the elasticsearch index and return
* at most <b>quantity</b> hits starting from <b>from</b>.
* @param query the query to match
* @param vreIDS specifies the vre(s) to which the returning feeds must belong
* @param from start hits index
* @param to number of hits to returning starting from <b>from</b>
* @param quantity max number of hits to return starting from <b>from</b>
* @return A list of matching enhanced feeds or nothing
*/
public List<EnhancedFeed> searchInEnhancedFeeds(String query, Set<String> vreIDS, int from, int to);
public List<EnhancedFeed> searchInEnhancedFeeds(String query, Set<String> vreIDS, int from, int quantity);
/**
* Delete from the index a document with id docID.