1 package org.apache.lucene.queryParser.surround.query;
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.lucene.index.Term;
20 import org.apache.lucene.index.TermEnum;
21 import org.apache.lucene.index.IndexReader;
23 import java.io.IOException;
26 public class SrndPrefixQuery extends SimpleTerm {
27 public SrndPrefixQuery(String prefix, boolean quoted, char truncator) {
30 this.truncator = truncator;
33 private final String prefix;
34 public String getPrefix() {return prefix;}
36 private final char truncator;
37 public char getSuffixOperator() {return truncator;}
39 public Term getLucenePrefixTerm(String fieldName) {
40 return new Term(fieldName, getPrefix());
44 public String toStringUnquoted() {return getPrefix();}
47 protected void suffixToString(StringBuilder r) {r.append(getSuffixOperator());}
50 public void visitMatchingTerms(
53 MatchingTermVisitor mtv) throws IOException
55 /* inspired by PrefixQuery.rewrite(): */
56 TermEnum enumerator = reader.terms(getLucenePrefixTerm(fieldName));
59 Term term = enumerator.term();
61 && term.text().startsWith(getPrefix())
62 && term.field().equals(fieldName)) {
63 mtv.visitMatchingTerm(term);
67 } while (enumerator.next());