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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/handler/AnalysisRequestHandlerTestBase.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.handler;
19
 
 
20
 
import org.apache.solr.SolrTestCaseJ4;
21
 
import org.apache.solr.common.util.NamedList;
22
 
import org.apache.commons.lang.ArrayUtils;
23
 
 
24
 
/**
25
 
 * A base class for all analysis request handler tests.
26
 
 *
27
 
 * @version $Id: AnalysisRequestHandlerTestBase.java 1135156 2011-06-13 16:14:49Z uschindler $
28
 
 * @since solr 1.4
29
 
 */
30
 
public abstract class AnalysisRequestHandlerTestBase extends SolrTestCaseJ4 {
31
 
 
32
 
  protected void assertToken(NamedList token, TokenInfo info) {
33
 
    assertEquals(info.getText(), token.get("text"));
34
 
    if (info.getRawText() != null) {
35
 
      assertEquals(info.getRawText(), token.get("raw_text"));
36
 
    }
37
 
    assertEquals(info.getType(), token.get("type"));
38
 
    assertEquals(new Integer(info.getStart()), token.get("start"));
39
 
    assertEquals(new Integer(info.getEnd()), token.get("end"));
40
 
    assertEquals(new Integer(info.getPosition()), token.get("position"));
41
 
    assertArrayEquals(info.getPositionHistory(), ArrayUtils.toPrimitive((Integer[]) token.get("positionHistory")));
42
 
    if (info.isMatch()) {
43
 
      assertEquals(Boolean.TRUE, token.get("match"));
44
 
    }
45
 
    if (info.getPayload() != null) {
46
 
      assertEquals(info.getPayload(), token.get("payload"));
47
 
    }
48
 
  }
49
 
 
50
 
 
51
 
  //================================================= Inner Classes ==================================================
52
 
 
53
 
  protected class TokenInfo {
54
 
 
55
 
    private String text;
56
 
    private String rawText;
57
 
    private String type;
58
 
    private int start;
59
 
    private int end;
60
 
    private String payload;
61
 
    private int position;
62
 
    private int[] positionHistory;
63
 
    private boolean match;
64
 
 
65
 
    public TokenInfo(
66
 
            String text,
67
 
            String rawText,
68
 
            String type,
69
 
            int start,
70
 
            int end,
71
 
            int position,
72
 
            int[] positionHistory,
73
 
            String payload,
74
 
            boolean match) {
75
 
 
76
 
      this.text = text;
77
 
      this.rawText = rawText;
78
 
      this.type = type;
79
 
      this.start = start;
80
 
      this.end = end;
81
 
      this.position = position;
82
 
      this.positionHistory = positionHistory;
83
 
      this.payload = payload;
84
 
      this.match = match;
85
 
    }
86
 
 
87
 
    public String getText() {
88
 
      return text;
89
 
    }
90
 
 
91
 
    public String getRawText() {
92
 
      return rawText;
93
 
    }
94
 
 
95
 
    public String getType() {
96
 
      return type;
97
 
    }
98
 
 
99
 
    public int getStart() {
100
 
      return start;
101
 
    }
102
 
 
103
 
    public int getEnd() {
104
 
      return end;
105
 
    }
106
 
 
107
 
    public String getPayload() {
108
 
      return payload;
109
 
    }
110
 
 
111
 
    public int getPosition() {
112
 
      return position;
113
 
    }
114
 
 
115
 
    public int[] getPositionHistory() {
116
 
      return positionHistory;
117
 
    }
118
 
 
119
 
    public boolean isMatch() {
120
 
      return match;
121
 
    }
122
 
  }
123
 
 
124
 
}