1
package org.apache.solr.client.solrj.response;
3
* Licensed to the Apache Software Foundation (ASF) under one or more
4
* contributor license agreements. See the NOTICE file distributed with
5
* this work for additional information regarding copyright ownership.
6
* The ASF licenses this file to You under the Apache License, Version 2.0
7
* (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
import org.apache.solr.common.util.NamedList;
21
import java.util.ArrayList;
22
import java.util.HashMap;
23
import java.util.List;
27
* Encapsulates responses from TermsComponent
29
public class TermsResponse {
30
private Map<String, List<Term>> termMap = new HashMap<String, List<Term>>();
32
public TermsResponse(NamedList<Object> termsInfo) {
33
for (int i = 0; i < termsInfo.size(); i++) {
34
String fieldName = termsInfo.getName(i);
35
List<Term> itemList = new ArrayList<Term>();
36
NamedList<Object> items = (NamedList<Object>) termsInfo.getVal(i);
38
for (int j = 0; j < items.size(); j++) {
39
Term t = new Term(items.getName(j), ((Number) items.getVal(j)).longValue());
43
termMap.put(fieldName, itemList);
48
* Get's the term list for a given field
50
* @return the term list or null if no terms for the given field exist
52
public List<Term> getTerms(String field) {
53
return termMap.get(field);
56
public Map<String, List<Term>> getTermMap() {
60
public static class Term {
62
private long frequency;
64
public Term(String term, long frequency) {
66
this.frequency = frequency;
69
public String getTerm() {
73
public void setTerm(String term) {
77
public long getFrequency() {
81
public void setFrequency(long frequency) {
82
this.frequency = frequency;
85
public void addFrequency(long frequency) {
86
this.frequency += frequency;