~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/solrj/src/java/org/apache/solr/client/solrj/response/TermsResponse.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.client.solrj.response;
2
 
/**
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
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
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.
17
 
 */
18
 
 
19
 
import org.apache.solr.common.util.NamedList;
20
 
 
21
 
import java.util.ArrayList;
22
 
import java.util.HashMap;
23
 
import java.util.List;
24
 
import java.util.Map;
25
 
 
26
 
/**
27
 
 * Encapsulates responses from TermsComponent
28
 
 */
29
 
public class TermsResponse {
30
 
  private Map<String, List<Term>> termMap = new HashMap<String, List<Term>>();
31
 
  
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);
37
 
      
38
 
      for (int j = 0; j < items.size(); j++) {
39
 
        Term t = new Term(items.getName(j), ((Number) items.getVal(j)).longValue());
40
 
        itemList.add(t);
41
 
      }
42
 
      
43
 
      termMap.put(fieldName, itemList);
44
 
    }
45
 
  }
46
 
 
47
 
  /**
48
 
   * Get's the term list for a given field
49
 
   * 
50
 
   * @return the term list or null if no terms for the given field exist
51
 
   */
52
 
  public List<Term> getTerms(String field) {
53
 
    return termMap.get(field);
54
 
  }
55
 
  
56
 
  public Map<String, List<Term>> getTermMap() {
57
 
    return termMap;
58
 
  }
59
 
 
60
 
  public static class Term {
61
 
    private String term;
62
 
    private long frequency;
63
 
 
64
 
    public Term(String term, long frequency) {
65
 
      this.term = term;
66
 
      this.frequency = frequency;
67
 
    }
68
 
 
69
 
    public String getTerm() {
70
 
      return term;
71
 
    }
72
 
 
73
 
    public void setTerm(String term) {
74
 
      this.term = term;
75
 
    }
76
 
    
77
 
    public long getFrequency() {
78
 
      return frequency;
79
 
    }
80
 
    
81
 
    public void setFrequency(long frequency) {
82
 
      this.frequency = frequency;
83
 
    }
84
 
    
85
 
    public void addFrequency(long frequency) {
86
 
      this.frequency += frequency;
87
 
    }
88
 
  }
89
 
}