01: package org.apache.lucene.queryParser.surround.query;
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 java.io.IOException;
21:
22: import org.apache.lucene.index.IndexReader;
23: import org.apache.lucene.index.Term;
24: import org.apache.lucene.index.TermEnum;
25:
26: public class SrndTermQuery extends SimpleTerm {
27: public SrndTermQuery(String termText, boolean quoted) {
28: super (quoted);
29: this .termText = termText;
30: }
31:
32: private final String termText;
33:
34: public String getTermText() {
35: return termText;
36: }
37:
38: public Term getLuceneTerm(String fieldName) {
39: return new Term(fieldName, getTermText());
40: }
41:
42: public String toStringUnquoted() {
43: return getTermText();
44: }
45:
46: public void visitMatchingTerms(IndexReader reader,
47: String fieldName, MatchingTermVisitor mtv)
48: throws IOException {
49: /* check term presence in index here for symmetry with other SimpleTerm's */
50: TermEnum enumerator = reader.terms(getLuceneTerm(fieldName));
51: try {
52: Term it = enumerator.term(); /* same or following index term */
53: if ((it != null) && it.text().equals(getTermText())
54: && it.field().equals(fieldName)) {
55: mtv.visitMatchingTerm(it);
56: } else {
57: System.out.println("No term in " + fieldName
58: + " field for: " + toString());
59: }
60: } finally {
61: enumerator.close();
62: }
63: }
64: }
|