01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.util.LuceneTestCase;
21: import org.apache.lucene.analysis.WhitespaceAnalyzer;
22:
23: public class TestQueryTermVector extends LuceneTestCase {
24:
25: public TestQueryTermVector(String s) {
26: super (s);
27: }
28:
29: public void testConstructor() {
30: String[] queryTerm = { "foo", "bar", "foo", "again", "foo",
31: "bar", "go", "go", "go" };
32: //Items are sorted lexicographically
33: String[] gold = { "again", "bar", "foo", "go" };
34: int[] goldFreqs = { 1, 2, 3, 3 };
35: QueryTermVector result = new QueryTermVector(queryTerm);
36: assertTrue(result != null);
37: String[] terms = result.getTerms();
38: assertTrue(terms.length == 4);
39: int[] freq = result.getTermFrequencies();
40: assertTrue(freq.length == 4);
41: checkGold(terms, gold, freq, goldFreqs);
42: result = new QueryTermVector(null);
43: assertTrue(result.getTerms().length == 0);
44:
45: result = new QueryTermVector(
46: "foo bar foo again foo bar go go go",
47: new WhitespaceAnalyzer());
48: assertTrue(result != null);
49: terms = result.getTerms();
50: assertTrue(terms.length == 4);
51: freq = result.getTermFrequencies();
52: assertTrue(freq.length == 4);
53: checkGold(terms, gold, freq, goldFreqs);
54: }
55:
56: private void checkGold(String[] terms, String[] gold, int[] freq,
57: int[] goldFreqs) {
58: for (int i = 0; i < terms.length; i++) {
59: assertTrue(terms[i].equals(gold[i]));
60: assertTrue(freq[i] == goldFreqs[i]);
61: }
62: }
63: }
|