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.queryParser.core.config.AbstractQueryConfig;
21 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
22 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
23 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
24 import org.apache.lucene.queryParser.standard.processors.GroupQueryNodeProcessor;
25 import org.apache.lucene.util.AttributeImpl;
28 * This attribute is used by {@link GroupQueryNodeProcessor} processor and must
29 * be defined in the {@link QueryConfigHandler}. This attribute tells the
30 * processor which is the default boolean operator when no operator is defined
31 * between terms. <br/>
33 * @see org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute
39 public class DefaultOperatorAttributeImpl extends AttributeImpl
40 implements DefaultOperatorAttribute, ConfigAttribute {
42 private static final long serialVersionUID = -6804760312723049526L;
44 private AbstractQueryConfig config;
46 { enableBackwards = false; }
48 public DefaultOperatorAttributeImpl() {
52 public void setOperator(Operator operator) {
54 if (operator == null) {
55 throw new IllegalArgumentException("default operator cannot be null!");
58 org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator newOperator;
60 if (operator == Operator.AND) {
61 newOperator = org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.AND;
63 newOperator = org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.OR;
66 config.set(ConfigurationKeys.DEFAULT_OPERATOR, newOperator);
70 public Operator getOperator() {
71 org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator newOperator = config.get(ConfigurationKeys.DEFAULT_OPERATOR, org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.OR);
74 if (newOperator == org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.AND) {
75 oldOperator = Operator.AND;
77 oldOperator = Operator.OR;
85 throw new UnsupportedOperationException();
89 public void copyTo(AttributeImpl target) {
90 throw new UnsupportedOperationException();
94 public boolean equals(Object other) {
96 if (other instanceof DefaultOperatorAttributeImpl) {
97 DefaultOperatorAttributeImpl defaultOperatorAttr = (DefaultOperatorAttributeImpl) other;
99 if (defaultOperatorAttr.getOperator() == this.getOperator()) {
111 public int hashCode() {
112 return getOperator().hashCode() * 31;
116 public String toString() {
117 return "<defaultOperatorAttribute operator=" + getOperator().name() + "/>";
120 public void setQueryConfigHandler(AbstractQueryConfig config) {
121 this.config = config;
123 if (!config.has(ConfigurationKeys.DEFAULT_OPERATOR)) {
124 setOperator(Operator.OR);