Examples of FacetConfig


Examples of org.fao.geonet.kernel.search.LuceneConfig.FacetConfig

            for (String item : items) {
                if (item.startsWith("any")) {
                    tmpConfig = _summaryConfig;
                    break;
                }
                final FacetConfig facetConfig = _summaryConfig.get(item.trim());
                if (facetConfig != null) {
                    tmpConfig.put(item.trim(), facetConfig);
                } else {
                    throw new BadParameterEx(Geonet.SearchResult.SUMMARY_ITEMS, item + " Legal values are: " + _summaryConfig.keySet());
                }
View Full Code Here

Examples of org.fao.geonet.kernel.search.LuceneConfig.FacetConfig

            String langCode) throws IOException {
        DecimalFormat doubleFormat = new DecimalFormat("0");

        try {
            for (Map.Entry<String, FacetConfig> fEntry : summaryConfigValues.entrySet()) {
                FacetConfig facetConfig = fEntry.getValue();
                String facetFieldName = facetConfig.getIndexKey() +
                        SearchManager.FACET_FIELD_SUFFIX;
                OrdinalsReader ordsReader = new DocValuesOrdinalsReader(facetFieldName);
                Facets facets = new TaxonomyFacetCounts(ordsReader, taxonomyReader, facetConfiguration, facetCollector);

                FacetResult facetResults = facets.getTopChildren(facetConfig.getMax(), facetFieldName); // facetConfig.getIndexKey()
                if (facetResults != null) {
                    // Create the XML element for the response
                    String facetName = facetConfig.getPlural();
                    Element facetsSummaryElement = new Element(facetName);

                    // Get the optional translator for the facet
                    final Translator translator;
                    if (ServiceContext.get() != null) {
                        try {
                            ServiceContext context = ServiceContext.get();
                            translator = facetConfig.getTranslator(context, langCode);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        translator = Translator.NULL_TRANSLATOR;
                    }


                    // Collecting all values and sort them
                    Map<String, Number> facetValues = new LinkedHashMap<String, Number>();
                    if (Log.isDebugEnabled(Geonet.FACET_ENGINE)) {
                        Log.debug(Geonet.FACET_ENGINE, facetName
                                + ":\tSorting facet by " + facetConfig.getSortBy().toString()
                                + " (" + facetConfig.getSortOrder().toString() + ")");
                    }

                    for (LabelAndValue result : facetResults.labelValues) {
                        facetValues.put(result.label, result.value);
                    }

                    List<Map.Entry<String, Number>> entries =
                            new ArrayList<Map.Entry<String, Number>>(facetValues.entrySet());
                    //No need for a custom comparator Lucene facet request is
                    // made by count descending order
                    if (LuceneConfig.Facet.SortBy.COUNT != facetConfig.getSortBy()) {
                        Comparator<Map.Entry<String, Number>> comparator;
                        if (LuceneConfig.Facet.SortBy.LABEL == facetConfig.getSortBy()) {
                            comparator = new Comparator<Map.Entry<String, Number>>() {

                                @Override
                                public int compare(Map.Entry<String, Number> o1, Map.Entry<String, Number> o2) {
                                    String label1 = null;
                                    String label2 = null;
                                    if (translator != null) {
                                        label1 = translator.translate(o1.getKey());
                                        label2 = translator.translate(o2.getKey());
                                    }
                                    if (label1 == null) {
                                        label1 = o1.getKey();
                                    }
                                    if (label2 == null) {
                                        label2 = o2.getKey();
                                    }
                                    return label1.compareTo(label2);
                                }
                            };
                        } else if (LuceneConfig.Facet.SortBy.NUMVALUE == facetConfig.getSortBy()) {
                            // Create a numeric comparator
                            comparator = new Comparator<Map.Entry<String, Number>>() {
                                public int compare(final Map.Entry<String, Number> e1, final Map.Entry<String, Number> e2) {
                                    try {
                                        Double d1 = Double.valueOf(e1.getKey());
                                        Double d2 = Double.valueOf(e2.getKey());

                                        return d1.compareTo(d2);
                                    } catch (NumberFormatException e) {
                                        // String comparison
                                        Log.warning(Geonet.FACET_ENGINE,
                                                "Failed to compare numeric values (" + e1.getKey() + " / " + e2.getKey()
                                                        + ") for facet. Check sortBy option in summary configuration.");
                                        return e1.getKey().compareTo(e2.getKey());
                                    }
                                }
                            };
                        } else {
                            comparator = new Comparator<Map.Entry<String, Number>>() {
                                public int compare(final Map.Entry<String, Number> e1, final Map.Entry<String, Number> e2) {
                                    return e1.getKey().compareTo(e2.getKey());
                                }
                            };
                        }
                        Collections.sort(entries, comparator);


                        if (LuceneConfig.Facet.SortOrder.DESCENDING == facetConfig.getSortOrder()) {
                            Collections.reverse(entries);
                        }
                    }

                    for (Map.Entry<String, Number> entry : entries) {
                        String facetValue = entry.getKey();
                        String facetCount = doubleFormat.format(entry
                                .getValue());

                        if (Log.isDebugEnabled(Geonet.FACET_ENGINE)) {
                            Log.debug(Geonet.FACET_ENGINE, " - " + facetValue
                                    + " (" + facetCount + ")");
                        }

                        String translatedValue = translator.translate(facetValue);

                        Element facetElement = new Element(facetConfig.getName());
                        facetElement.setAttribute("count", facetCount);
                        facetElement.setAttribute("name", facetValue);
                        if (translatedValue != null) {
                            facetElement.setAttribute("label", translatedValue);
                        }
                        facetsSummaryElement.addContent(facetElement);
                    }
                    elSummary.addContent(facetsSummaryElement);
                } else {
                    Log.debug(
                            Geonet.FACET_ENGINE,
                            "Null facet results for field " + facetConfig.getIndexKey());
                }
            }

        } catch (ArrayIndexOutOfBoundsException e) {
            Log.error(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.