2 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 package com.liferay.portal.search.solr.facet;
17 import com.liferay.portal.kernel.search.facet.collector.FacetCollector;
18 import com.liferay.portal.kernel.search.facet.collector.TermCollector;
20 import java.util.ArrayList;
21 import java.util.LinkedHashMap;
22 import java.util.List;
25 import org.apache.solr.client.solrj.response.FacetField.Count;
26 import org.apache.solr.client.solrj.response.FacetField;
29 * @author Raymond Augé
31 public class SolrFacetFieldCollector implements FacetCollector {
33 public SolrFacetFieldCollector(String fieldName, FacetField facetField) {
34 _fieldName = fieldName;
36 List<Count> counts = facetField.getValues();
39 for (Count count : counts) {
40 _counts.put(count.getName(), count);
45 public String getFieldName() {
49 public TermCollector getTermCollector(String term) {
50 Count count = _counts.get(term);
55 occurences = (int)count.getCount();
58 return new SolrTermCollector(term, occurences);
61 public List<TermCollector> getTermCollectors() {
62 if (_termCollectors != null) {
63 return _termCollectors;
66 List<TermCollector> termCollectors = new ArrayList<TermCollector>();
68 for (Map.Entry<String, Count> entry : _counts.entrySet()) {
69 Count count = entry.getValue();
71 TermCollector termCollector = new SolrTermCollector(
72 entry.getKey(), (int)count.getCount());
74 termCollectors.add(termCollector);
77 _termCollectors = termCollectors;
79 return _termCollectors;
82 private Map<String, Count> _counts = new LinkedHashMap<String, Count>();
83 private String _fieldName;
84 private List<TermCollector> _termCollectors;