01: package org.apache.lucene.search.regex;
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.search.MultiTermQuery;
21: import org.apache.lucene.search.FilteredTermEnum;
22: import org.apache.lucene.index.Term;
23: import org.apache.lucene.index.IndexReader;
24:
25: import java.io.IOException;
26:
27: /** Implements the regular expression term search query.
28: * The expressions supported depend on the regular expression implementation
29: * used by way of the {@link RegexCapabilities} interface.
30: *
31: * @see RegexTermEnum
32: */
33: public class RegexQuery extends MultiTermQuery implements
34: RegexQueryCapable {
35: private RegexCapabilities regexImpl = new JavaUtilRegexCapabilities();
36:
37: /** Constructs a query for terms matching <code>term</code>. */
38: public RegexQuery(Term term) {
39: super (term);
40: }
41:
42: /**
43: * Defines which {@link RegexCapabilities} implementation is used by this instance.
44: *
45: * @param impl
46: */
47: public void setRegexImplementation(RegexCapabilities impl) {
48: this .regexImpl = impl;
49: }
50:
51: /**
52: * @return The implementation used by this instance.
53: */
54: public RegexCapabilities getRegexImplementation() {
55: return regexImpl;
56: }
57:
58: protected FilteredTermEnum getEnum(IndexReader reader)
59: throws IOException {
60: Term term = new Term(getTerm().field(), getTerm().text());
61: return new RegexTermEnum(reader, term, regexImpl);
62: }
63:
64: /* generated by IntelliJ IDEA */
65: public boolean equals(Object o) {
66: if (this == o)
67: return true;
68: if (o == null || getClass() != o.getClass())
69: return false;
70: if (!super .equals(o))
71: return false;
72:
73: final RegexQuery that = (RegexQuery) o;
74:
75: return regexImpl.equals(that.regexImpl);
76: }
77:
78: /* generated by IntelliJ IDEA */
79: public int hashCode() {
80: int result = super .hashCode();
81: result = 29 * result + regexImpl.hashCode();
82: return result;
83: }
84: }
|