List of usage examples for org.apache.solr.client.solrj SolrQuery getCopy
public SolrQuery getCopy()
From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.IntactSolrSearcher.java
License:Apache License
public Multimap<String, InteractorIdCount> searchInteractors(SolrQuery originalQuery, IntactFacetField[] intactFacetFields) throws IntactSolrException { SolrQuery query = originalQuery.getCopy(); query.setRows(0);/* ww w.j a va 2 s.c o m*/ // we allow faceting query.setFacet(true); // we want all the facet fields with min count = 1. The facet fields with count = 0 are not interesting query.setFacetMinCount(1); Multimap<String, InteractorIdCount> interactors = HashMultimap.create(); if (intactFacetFields != null) { // we sort the results : the biggest count first query.setFacetSort(FacetParams.FACET_SORT_COUNT); for (IntactFacetField facetField : intactFacetFields) { final String fieldName = createFieldName(facetField.getFieldName()); // important optimization. We don't want to return all the fields, only a certain number for pagination if (facetField.getFirst() != null) { query.set("f." + fieldName + ".facet.offset", facetField.getFirst()); } if (facetField.getMax() != null) { query.set("f." + fieldName + ".facet.limit", facetField.getMax()); } query.addFacetField(fieldName); } } QueryResponse queryResponse = executeQuery(query); List<FacetField> facetFields = queryResponse.getFacetFields(); if (facetFields == null || facetFields.isEmpty()) { return interactors; } for (FacetField ff : facetFields) { if (ff != null && ff.getValues() != null) { for (FacetField.Count c : ff.getValues()) { interactors.put(extractInteractorTypeFromFieldName(ff.getName()), new InteractorIdCount(c.getName(), c.getCount())); } } } return interactors; }
From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.IntactSolrSearcher.java
License:Apache License
public Map<String, Integer> countAllInteractors(SolrQuery originalQuery, String[] interactorTypeMis) throws IntactSolrException { boolean endOfFacetResults = false; int firstResults = 0; Map<String, Integer> results = new HashMap<String, Integer>(); while (!endOfFacetResults) { int chunkResults = 0; SolrQuery query = originalQuery.getCopy(); query.setRows(0);/*from ww w . j ava 2s . c o m*/ // we allow faceting query.setFacet(true); // we want all the facet fields with min count = 1. The facet fields with count = 0 are not interesting query.setFacetMinCount(1); // important optimization. We don't want to return all the fields, only a certain number for pagination query.set(FacetParams.FACET_OFFSET, firstResults); query.setFacetLimit(CHUNK_FACET_THRESHOLD); // we sort the results : the biggest count first query.setFacetSort(FacetParams.FACET_SORT_COUNT); for (String mi : interactorTypeMis) { final String fieldName = createFieldName(mi); query.addFacetField(fieldName); } QueryResponse queryResponse = executeQuery(query); List<FacetField> facetFields = queryResponse.getFacetFields(); if (facetFields == null || facetFields.isEmpty()) { endOfFacetResults = true; } else { for (FacetField facetField : facetFields) { if (facetField.getValueCount() > 0) { chunkResults += facetField.getValueCount(); if (results.containsKey(facetField.getName())) { int current = results.get(facetField.getName()); results.put(facetField.getName(), current + facetField.getValueCount()); } else { results.put(facetField.getName(), facetField.getValueCount()); } } else if (!results.containsKey(facetField.getName())) { results.put(facetField.getName(), 0); } } if (chunkResults < CHUNK_FACET_THRESHOLD) { endOfFacetResults = true; } } firstResults += CHUNK_FACET_THRESHOLD; } return results; }