1 package org.apache.lucene.queryParser.standard.config;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import org.apache.lucene.analysis.Analyzer;
21 import org.apache.lucene.queryParser.core.config.AbstractQueryConfig;
22 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
23 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
24 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
25 import org.apache.lucene.queryParser.standard.processors.AnalyzerQueryNodeProcessor;
26 import org.apache.lucene.util.AttributeImpl;
29 * This attribute is used by {@link AnalyzerQueryNodeProcessor} processor and
30 * must be defined in the {@link QueryConfigHandler}. It provides to this
31 * processor the {@link Analyzer}, if there is one, which will be used to
32 * analyze the query terms. <br/>
34 * @see org.apache.lucene.queryParser.standard.config.AnalyzerAttribute
40 public class AnalyzerAttributeImpl extends AttributeImpl
41 implements AnalyzerAttribute, ConfigAttribute {
43 private static final long serialVersionUID = -6804760312723049526L;
45 private AbstractQueryConfig config;
47 { enableBackwards = false; }
49 public AnalyzerAttributeImpl() {}
51 public void setAnalyzer(Analyzer analyzer) {
52 config.set(ConfigurationKeys.ANALYZER, analyzer);
55 public Analyzer getAnalyzer() {
56 return config.get(ConfigurationKeys.ANALYZER);
61 throw new UnsupportedOperationException();
65 public void copyTo(AttributeImpl target) {
66 throw new UnsupportedOperationException();
70 public boolean equals(Object other) {
72 if (other instanceof AnalyzerAttributeImpl) {
73 AnalyzerAttributeImpl analyzerAttr = (AnalyzerAttributeImpl) other;
74 Analyzer otherAnalyzer = analyzerAttr.getAnalyzer();
75 Analyzer thisAnalyzer = getAnalyzer();
77 if (otherAnalyzer == thisAnalyzer
78 || (thisAnalyzer != null && otherAnalyzer != null && thisAnalyzer
79 .equals(otherAnalyzer))) {
92 public int hashCode() {
93 Analyzer analyzer = getAnalyzer();
94 return (analyzer == null) ? 0 : analyzer.hashCode();
97 public void setQueryConfigHandler(AbstractQueryConfig config) {
102 public String toString() {
103 return "<analyzerAttribute analyzer='" + getAnalyzer() + "'/>";