private List<String> transform(String type, FacetResult facetResult) { List<String> results = new LinkedList<>(); FieldFacetResult fResults = facetResult.getFieldFacetResult(PublicationIndexFieldConstants.FIELD_ANCESTOR_NAME + SEP + MAP_ANCESTOR_TYPE_TO_LEVEL.get(type)); if (fResults != null && fResults.getValues() != null) { for(String element : fResults.getValues().keySet()){ results.add(IndexUtils.decodeNameValue(element)); } } return results; }
@Override public List<String> performSearch(FulltextSearchQuery searchQuery, String... excluded) { FulltextSearchResults searchResults = indexService.performSearch(searchQuery); FieldFacetResult facetResult = searchResults.getFacetResult() .getFieldFacetResult(PublicationIndexFieldConstants.FIELD_DATASET); List<String> results = new ArrayList<String>(); for (Map.Entry<String, Long> entry : facetResult.getValues().entrySet()) { if ( ! ArrayUtils.contains(excluded, entry.getKey())) { results.add(entry.getKey().toLowerCase()); } } return results; }
public Map<String, Long> getFieldFacetResult(String field) { Map<String, Long> result = Collections.emptyMap(); FacetResult facetResult = fulltextSearchResults.getFacetResult(); if (result != null) { FieldFacetResult fieldFacet = facetResult.getFieldFacetResult(field); if (fieldFacet != null) { result = fieldFacet.getValues(); } } return result; }
private Map<String, WeightedElement<String>> getElementsFromIndex(String facetField, String queryField, SearchCriterion criterion, SuggestionsQuery query) { Map<String, WeightedElement<String>> elements = new HashMap<>(); FulltextSearchResults result = getFacet(facetField, criterion, query); FacetResult facetResult = result.getFacetResult(); FieldFacetResult fieldFacetResult = facetResult.getFieldFacetResult(facetField); int size = result.getCount(); int weightMultiplier = QUERY_FIELD_MULTIPLIERS.get(queryField); for (Entry<String, Long> facetEntry : fieldFacetResult.getValues().entrySet()) { double ratio = ((double) facetEntry.getValue()) / size; WeightedElement<String> element = new WeightedElement<String>(facetEntry.getKey(), (int) (ratio * weightMultiplier)); elements.put(element.getValue(), element); } return elements; }
@Override public List<FacetField> translate(FacetResult facetResult, Locale locale) { if (facetResult == null) { return null; } List<FacetField> output = new ArrayList<FacetField>(); for (FieldFacetResult fieldFacetResult : facetResult.getFieldFacetResults()) { FacetField facetField = new FacetField(fieldFacetResult.getFieldName()); for (Map.Entry<String, Long> entry : fieldFacetResult.getValues().entrySet()) { if (wildcardContains(getTranslatedFields(), fieldFacetResult.getFieldName())) { facetField.addValue(new FacetFieldValue(entry.getKey(), entry.getValue(), encodeField(fieldFacetResult.getFieldName(), entry.getKey(), locale))); } else { facetField.addValue(new FacetFieldValue(entry.getKey(), entry.getValue())); } } if (wildcardContains(getSortFields(), fieldFacetResult.getFieldName())) { Collections.sort(facetField.getValues(), getFacetComparator()); log.debug("Facet values for field {} sorted", fieldFacetResult.getFieldName()); } output.add(facetField); } return output; }
private FieldFacetResultProto transformFieldFacetResult(final FieldFacetResult fieldFacetResult) { pl.edu.icm.synat.api.services.index.fulltext.protobuf.FulltextIndexModel.FieldFacetResultProto.Builder fieldBuilder; fieldBuilder = FieldFacetResultProto.newBuilder(); fieldBuilder.setFieldName(fieldFacetResult.getFieldName()); if (fieldFacetResult.hasMissingCount()) { fieldBuilder.setMissingCount(fieldFacetResult.getMissingCount()); } for (Entry<String, Long> entry : fieldFacetResult.getValues().entrySet()) { String value = entry.getKey(); Long count = entry.getValue(); fieldBuilder.addValuesBuilder().setCount(count).setValue(value).build(); } return fieldBuilder.build(); }
private void tryFacet() { int batchSize = 1; ResultsFormat resultsFormat = new ResultsFormat(new FieldRequest(pl.edu.icm.synat.logic.index.publication.CollectionIndexFieldConstants.FIELD_EXID, true)); FulltextSearchQuery searchQuery = null; searchQuery = new FulltextSearchQuery(0, batchSize, resultsFormat, new FieldCriterion("*", "*", SearchOperator.AND)); Facet facet = new Facet(); facet.addFieldFacet(PublicationIndexFieldConstants.FIELD_TYPE); searchQuery.setFacet(facet); FulltextSearchResults searchResults = indexService.performSearch(searchQuery); FieldFacetResult facetResult = searchResults.getFacetResult().getFieldFacetResult(PublicationIndexFieldConstants.FIELD_TYPE); Set<Entry<String,Long>> entrySet = facetResult.getValues().entrySet(); for (Entry<String, Long> entry : entrySet) { System.out.println("["+entry.getKey()+"]="+entry.getValue()); } }