Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RangeQueryNodeBuilder.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RangeQueryNodeBuilder.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RangeQueryNodeBuilder.java (working copy) @@ -21,8 +21,8 @@ import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode; import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode; +import org.apache.lucene.queryParser.standard.processors.MultiTermRewriteMethodProcessor; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.TermRangeQuery; @@ -55,7 +55,7 @@ TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, lower.getTextAsString(), upper.getTextAsString(), lowerInclusive, upperInclusive); - MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodAttribute.TAG_ID); + MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID); if (method != null) { rangeQuery.setRewriteMethod(method); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AnalyzerQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link AnalyzerQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. It provides to this - * processor the {@link Analyzer}, if there is one, which will be used to - * analyze the query terms.
- * - */ -public interface AnalyzerAttribute extends Attribute { - public void setAnalyzer(Analyzer analyzer); - public Analyzer getAnalyzer(); -} Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java (revision 1134869) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java (working copy) @@ -127,11 +127,10 @@ return getSpanQuery("", query); } - public SpanQuery getSpanQuery(CharSequence uniqueField, CharSequence query) + public SpanQuery getSpanQuery(String uniqueField, CharSequence query) throws QueryNodeException { - UniqueFieldAttribute uniqueFieldAtt = this.spanQueryConfigHandler - .getAttribute(UniqueFieldAttribute.class); - uniqueFieldAtt.setUniqueField(uniqueField); + + this.spanQueryConfigHandler.set(SpansQueryConfigHandler.UNIQUE_FIELD, uniqueField); QueryNode queryTree = this.queryParser.parse(query, "defaultField"); queryTree = this.spanProcessorPipeline.process(queryTree); Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttributeImpl.java (working copy) @@ -1,90 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Locale; - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by processor {@link ParametricRangeQueryNodeProcessor} - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor what is the default {@link Locale} used to parse a date.
- * - * @see org.apache.lucene.queryParser.standard.config.LocaleAttribute - */ -public class LocaleAttributeImpl extends AttributeImpl - implements LocaleAttribute { - - private Locale locale = Locale.getDefault(); - - public LocaleAttributeImpl() { - locale = Locale.getDefault(); //default in 2.4 - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public Locale getLocale() { - return this.locale; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof LocaleAttributeImpl) { - LocaleAttributeImpl localeAttr = (LocaleAttributeImpl) other; - - if (localeAttr.locale == this.locale - || (this.locale != null && localeAttr.locale != null && this.locale - .equals(localeAttr.locale))) { - - return true; - - } - - } - - return false; - - } - - @Override - public int hashCode() { - return (this.locale == null) ? 0 : this.locale.hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttribute.java (working copy) @@ -1,33 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AllowLeadingWildcardProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link AllowLeadingWildcardProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. It basically tells the - * processor if it should allow leading wildcard.
- * - */ -public interface AllowLeadingWildcardAttribute extends Attribute { - public void setAllowLeadingWildcard(boolean allowLeadingWildcard); - public boolean isAllowLeadingWildcard(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java (working copy) @@ -27,7 +27,7 @@ import org.apache.lucene.queryParser.core.nodes.TextableQueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryParser.core.util.UnescapedCharSequence; -import org.apache.lucene.queryParser.standard.config.LowercaseExpandedTermsAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; @@ -50,17 +50,10 @@ @Override public QueryNode process(QueryNode queryTree) throws QueryNodeException { + Boolean lowercaseExpandedTerms = getQueryConfigHandler().get(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS); - if (getQueryConfigHandler().hasAttribute( - LowercaseExpandedTermsAttribute.class)) { - - if (getQueryConfigHandler().getAttribute( - LowercaseExpandedTermsAttribute.class).isLowercaseExpandedTerms()) { - - return super.process(queryTree); - - } - + if (lowercaseExpandedTerms != null && lowercaseExpandedTerms) { + return super.process(queryTree); } return queryTree; Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttribute.java (working copy) @@ -1,34 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.PhraseSlopQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link PhraseSlopQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor what is the default phrase slop when no slop is defined in a - * phrase.
- * - */ -public interface DefaultPhraseSlopAttribute extends Attribute { - public void setDefaultPhraseSlop(int defaultPhraseSlop); - public int getDefaultPhraseSlop(); -} Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java (revision 1134869) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java (working copy) @@ -17,6 +17,7 @@ * limitations under the License. */ +import org.apache.lucene.queryParser.core.config.ConfigurationKey; import org.apache.lucene.queryParser.core.config.FieldConfig; import org.apache.lucene.queryParser.core.config.QueryConfigHandler; @@ -27,9 +28,11 @@ * It does not return any configuration for a field in specific. */ public class SpansQueryConfigHandler extends QueryConfigHandler { - + + final public static ConfigurationKey UNIQUE_FIELD = ConfigurationKey.newInstance(); + public SpansQueryConfigHandler() { - addAttribute(UniqueFieldAttribute.class); + // empty constructor } @Override Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttributeImpl.java (working copy) @@ -1,94 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.PhraseSlopQueryNodeProcessor; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link PhraseSlopQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor what is the default phrase slop when no slop is defined in a - * phrase.
- * - * @see org.apache.lucene.queryParser.standard.config.FuzzyAttribute - */ -public class FuzzyAttributeImpl extends AttributeImpl - implements FuzzyAttribute { - - private int prefixLength = FuzzyQuery.defaultPrefixLength; - - private float minSimilarity = FuzzyQuery.defaultMinSimilarity; - - public FuzzyAttributeImpl() { - // empty constructor - } - - public void setPrefixLength(int prefixLength) { - this.prefixLength = prefixLength; - } - - public int getPrefixLength() { - return this.prefixLength; - } - - public void setFuzzyMinSimilarity(float minSimilarity) { - this.minSimilarity = minSimilarity; - } - - public float getFuzzyMinSimilarity() { - return this.minSimilarity; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof FuzzyAttributeImpl - && ((FuzzyAttributeImpl) other).prefixLength == this.prefixLength) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return Integer.valueOf(this.prefixLength).hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LocaleAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Locale; - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by processor {@link ParametricRangeQueryNodeProcessor} - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor what is the default {@link Locale} used to parse a date.
- * - */ -public interface LocaleAttribute extends Attribute { - public void setLocale(Locale locale); - public Locale getLocale(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/BoostQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/BoostQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/BoostQueryNodeProcessor.java (working copy) @@ -27,7 +27,7 @@ import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryParser.core.util.StringUtils; -import org.apache.lucene.queryParser.standard.config.BoostAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.FieldConfigurationKeys; /** * This processor iterates the query node tree looking for every @@ -53,10 +53,12 @@ CharSequence field = fieldNode.getField(); FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field)); - if (fieldConfig != null && fieldConfig.hasAttribute(BoostAttribute.class)) { - BoostAttribute boostAttr = fieldConfig.getAttribute(BoostAttribute.class); + if (fieldConfig != null) { + Float boost = fieldConfig.get(FieldConfigurationKeys.BOOST); - return new BoostQueryNode(node, boostAttr.getBoost()); + if (boost != null) { + return new BoostQueryNode(node, boost); + } } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultPhraseSlopAttributeImpl.java (working copy) @@ -1,84 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.PhraseSlopQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link PhraseSlopQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor what is the default phrase slop when no slop is defined in a - * phrase.
- * - * @see org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute - */ -public class DefaultPhraseSlopAttributeImpl extends AttributeImpl - implements DefaultPhraseSlopAttribute { - - private int defaultPhraseSlop = 0; - - public DefaultPhraseSlopAttributeImpl() { - defaultPhraseSlop = 0; //default value in 2.4 - } - - public void setDefaultPhraseSlop(int defaultPhraseSlop) { - this.defaultPhraseSlop = defaultPhraseSlop; - } - - public int getDefaultPhraseSlop() { - return this.defaultPhraseSlop; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof DefaultPhraseSlopAttributeImpl - && ((DefaultPhraseSlopAttributeImpl) other).defaultPhraseSlop == this.defaultPhraseSlop) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return Integer.valueOf(this.defaultPhraseSlop).hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java (revision 1096393) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java (working copy) @@ -1,85 +0,0 @@ -package org.apache.lucene.queryParser.core.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.LinkedList; - -import org.apache.lucene.queryParser.core.processors.QueryNodeProcessor; -import org.apache.lucene.util.Attribute; -import org.apache.lucene.util.AttributeSource; - -/** - * This class can be used to hold any query configuration and no field - * configuration. For field configuration, it creates a empty - * {@link FieldConfig} object and delegate it to field config listeners, - * these are responsible for setting up all the field configuration. - * - * {@link QueryConfigHandler} should be extended by classes that intends to - * provide configuration to {@link QueryNodeProcessor} objects. - * - * This class extends {@link AttributeSource}, so {@link Attribute}s can be - * attached to it. - * - * The class that extends {@link QueryConfigHandler} should also provide - * {@link FieldConfig} objects for each collection field. - * - * @see Attribute - * @see FieldConfig - * @see FieldConfigListener - * @see QueryConfigHandler - */ -public abstract class QueryConfigHandler extends AttributeSource { - - private LinkedList listeners = new LinkedList(); - - /** - * Returns an implementation of - * {@link FieldConfig} for a specific field name. If the implemented - * {@link QueryConfigHandler} does not know a specific field name, it may - * return null, indicating there is no configuration for that - * field. - * - * @param fieldName - * the field name - * @return a {@link FieldConfig} object containing the field name - * configuration or null, if the implemented - * {@link QueryConfigHandler} has no configuration for that field - */ - public FieldConfig getFieldConfig(CharSequence fieldName) { - FieldConfig fieldConfig = new FieldConfig(fieldName); - - for (FieldConfigListener listener : this.listeners) { - listener.buildFieldConfig(fieldConfig); - } - - return fieldConfig; - - } - - /** - * Adds a listener. The added listeners are called in the order they are - * added. - * - * @param listener - * the listener to be added - */ - public void addFieldConfigListener(FieldConfigListener listener) { - this.listeners.add(listener); - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java (revision 0) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java (revision 1096393) @@ -0,0 +1,86 @@ +package org.apache.lucene.queryParser.core.config; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.LinkedList; + +import org.apache.lucene.queryParser.core.processors.QueryNodeProcessor; +import org.apache.lucene.queryParser.core.util.StringUtils; +import org.apache.lucene.util.Attribute; +import org.apache.lucene.util.AttributeSource; + +/** + * This class can be used to hold any query configuration and no field + * configuration. For field configuration, it creates a empty + * {@link FieldConfig} object and delegate it to field config listeners, + * these are responsible for setting up all the field configuration. + * + * {@link QueryConfigHandler} should be extended by classes that intends to + * provide configuration to {@link QueryNodeProcessor} objects. + * + * This class extends {@link AttributeSource}, so {@link Attribute}s can be + * attached to it. + * + * The class that extends {@link QueryConfigHandler} should also provide + * {@link FieldConfig} objects for each collection field. + * + * @see Attribute + * @see FieldConfig + * @see FieldConfigListener + * @see QueryConfigHandler + */ +public abstract class QueryConfigHandler extends AbstractQueryConfig { + + final private LinkedList listeners = new LinkedList(); + + /** + * Returns an implementation of + * {@link FieldConfig} for a specific field name. If the implemented + * {@link QueryConfigHandler} does not know a specific field name, it may + * return null, indicating there is no configuration for that + * field. + * + * @param fieldName + * the field name + * @return a {@link FieldConfig} object containing the field name + * configuration or null, if the implemented + * {@link QueryConfigHandler} has no configuration for that field + */ + public FieldConfig getFieldConfig(String fieldName) { + FieldConfig fieldConfig = new FieldConfig(StringUtils.toString(fieldName)); + + for (FieldConfigListener listener : this.listeners) { + listener.buildFieldConfig(fieldConfig); + } + + return fieldConfig; + + } + + /** + * Adds a listener. The added listeners are called in the order they are + * added. + * + * @param listener + * the listener to be added + */ + public void addFieldConfigListener(FieldConfigListener listener) { + this.listeners.add(listener); + } + +} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyConfig.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyConfig.java (revision 0) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyConfig.java (revision 0) @@ -0,0 +1,46 @@ +package org.apache.lucene.queryParser.standard.config; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.search.FuzzyQuery; + +public class FuzzyConfig { + + private int prefixLength = FuzzyQuery.defaultPrefixLength; + + private float minSimilarity = FuzzyQuery.defaultMinSimilarity; + + public FuzzyConfig() {} + + public int getPrefixLength() { + return prefixLength; + } + + public void setPrefixLength(int prefixLength) { + this.prefixLength = prefixLength; + } + + public float getMinSimilarity() { + return minSimilarity; + } + + public void setMinSimilarity(float minSimilarity) { + this.minSimilarity = minSimilarity; + } + +} Property changes on: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyConfig.java ___________________________________________________________________ Added: svn:keywords + Rev Date Added: svn:eol-style + native Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java (working copy) @@ -25,7 +25,7 @@ import org.apache.lucene.queryParser.core.nodes.SlopQueryNode; import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.DefaultPhraseSlopAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode; /** @@ -54,11 +54,11 @@ QueryConfigHandler queryConfig = getQueryConfigHandler(); if (queryConfig != null) { + Integer defaultPhraseSlop = queryConfig.get(ConfigurationKeys.DEFAULT_PHRASE_SLOP); + + if (defaultPhraseSlop != null) { + this.defaultPhraseSlop = defaultPhraseSlop; - if (queryConfig.hasAttribute(DefaultPhraseSlopAttribute.class)) { - this.defaultPhraseSlop = queryConfig.getAttribute( - DefaultPhraseSlopAttribute.class).getDefaultPhraseSlop(); - return super.process(queryTree); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttributeImpl.java (working copy) @@ -1,92 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.apache.lucene.queryParser.core.config.FieldConfig; -import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and - * it should be defined in a {@link FieldConfig}. This processor uses this - * attribute to define which boost a specific field should have when none is - * defined to it.
- *
- * - * @see org.apache.lucene.queryParser.standard.config.BoostAttribute - */ -public class FieldBoostMapAttributeImpl extends AttributeImpl - implements FieldBoostMapAttribute { - - private Map boosts = new LinkedHashMap(); - - - public FieldBoostMapAttributeImpl() { - // empty constructor - } - - public void setFieldBoostMap(Map boosts) { - this.boosts = boosts; - } - - public Map getFieldBoostMap() { - return this.boosts; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof FieldBoostMapAttributeImpl - && ((FieldBoostMapAttributeImpl) other).boosts.equals(this.boosts) ) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - final int prime = 97; - if (this.boosts != null) - return this.boosts.hashCode() * prime; - else - return Float.valueOf(prime).hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttribute.java (working copy) @@ -1,43 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.document.DateTools; -import org.apache.lucene.document.DateTools.Resolution; -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link ParametricRangeQueryNodeProcessor} processor - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor which {@link Resolution} to use when parsing the date.
- * - */ -public interface DateResolutionAttribute extends Attribute { - /** - * Sets the default date resolution used by {@link RangeQueryNode}s for - * fields for which no specific date resolutions has been set. Field - * specific resolutions can be set with - * - * @param dateResolution the default date resolution to set - */ - public void setDateResolution(DateTools.Resolution dateResolution); - public DateTools.Resolution getDateResolution(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java (working copy) @@ -33,8 +33,7 @@ import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.DateResolutionAttribute; -import org.apache.lucene.queryParser.standard.config.LocaleAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode; /** @@ -71,15 +70,13 @@ ParametricRangeQueryNode parametricRangeNode = (ParametricRangeQueryNode) node; ParametricQueryNode upper = parametricRangeNode.getUpperBound(); ParametricQueryNode lower = parametricRangeNode.getLowerBound(); - Locale locale = Locale.getDefault(); + DateTools.Resolution dateRes = null; boolean inclusive = false; + Locale locale = getQueryConfigHandler().get(ConfigurationKeys.LOCALE); - if (getQueryConfigHandler().hasAttribute(LocaleAttribute.class)) { - - locale = getQueryConfigHandler().getAttribute(LocaleAttribute.class) - .getLocale(); - + if (locale == null) { + locale = Locale.getDefault(); } CharSequence field = parametricRangeNode.getField(); @@ -93,14 +90,7 @@ .getFieldConfig(fieldStr); if (fieldConfig != null) { - - if (fieldConfig.hasAttribute(DateResolutionAttribute.class)) { - - dateRes = fieldConfig.getAttribute(DateResolutionAttribute.class) - .getDateResolution(); - - } - + dateRes = fieldConfig.get(ConfigurationKeys.DATE_RESOLUTION); } if (upper.getOperator() == CompareOperator.LE) { Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java (working copy) @@ -27,21 +27,10 @@ import org.apache.lucene.queryParser.core.QueryParserHelper; import org.apache.lucene.queryParser.core.config.QueryConfigHandler; import org.apache.lucene.queryParser.standard.builders.StandardQueryTreeBuilder; -import org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute; -import org.apache.lucene.queryParser.standard.config.AnalyzerAttribute; -import org.apache.lucene.queryParser.standard.config.DateResolutionAttribute; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute; -import org.apache.lucene.queryParser.standard.config.DefaultPhraseSlopAttribute; -import org.apache.lucene.queryParser.standard.config.FieldBoostMapAttribute; -import org.apache.lucene.queryParser.standard.config.FieldDateResolutionMapAttribute; -import org.apache.lucene.queryParser.standard.config.FuzzyAttribute; -import org.apache.lucene.queryParser.standard.config.LocaleAttribute; -import org.apache.lucene.queryParser.standard.config.LowercaseExpandedTermsAttribute; -import org.apache.lucene.queryParser.standard.config.MultiFieldAttribute; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; -import org.apache.lucene.queryParser.standard.config.PositionIncrementsAttribute; +import org.apache.lucene.queryParser.standard.config.FuzzyConfig; import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; import org.apache.lucene.queryParser.standard.parser.StandardSyntaxParser; import org.apache.lucene.queryParser.standard.processors.StandardQueryNodeProcessorPipeline; import org.apache.lucene.search.FuzzyQuery; @@ -179,9 +168,8 @@ * Gets implicit operator setting, which will be either {@link Operator#AND} * or {@link Operator#OR}. */ - public Operator getDefaultOperator() { - DefaultOperatorAttribute attr = getQueryConfigHandler().getAttribute(DefaultOperatorAttribute.class); - return attr.getOperator(); + public StandardQueryConfigHandler.Operator getDefaultOperator() { + return getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR); } /** @@ -192,9 +180,8 @@ * In {@link Operator#AND} mode terms are considered to be in conjunction: the * above mentioned query is parsed as capital AND of AND Hungary */ - public void setDefaultOperator(Operator operator) { - DefaultOperatorAttribute attr = getQueryConfigHandler().getAttribute(DefaultOperatorAttribute.class); - attr.setOperator(operator); + public void setDefaultOperator(StandardQueryConfigHandler.Operator operator) { + getQueryConfigHandler().set(ConfigurationKeys.DEFAULT_OPERATOR, operator); } /** @@ -207,16 +194,22 @@ * Default: false. */ public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) { - LowercaseExpandedTermsAttribute attr = getQueryConfigHandler().getAttribute(LowercaseExpandedTermsAttribute.class); - attr.setLowercaseExpandedTerms(lowercaseExpandedTerms); + getQueryConfigHandler().set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, lowercaseExpandedTerms); } /** * @see #setLowercaseExpandedTerms(boolean) */ public boolean getLowercaseExpandedTerms() { - LowercaseExpandedTermsAttribute attr = getQueryConfigHandler().getAttribute(LowercaseExpandedTermsAttribute.class); - return attr.isLowercaseExpandedTerms(); + Boolean lowercaseExpandedTerms = getQueryConfigHandler().get(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS); + + if (lowercaseExpandedTerms == null) { + return true; + + } else { + return lowercaseExpandedTerms; + } + } /** @@ -229,8 +222,7 @@ * Default: false. */ public void setAllowLeadingWildcard(boolean allowLeadingWildcard) { - AllowLeadingWildcardAttribute attr = getQueryConfigHandler().getAttribute(AllowLeadingWildcardAttribute.class); - attr.setAllowLeadingWildcard(allowLeadingWildcard); + getQueryConfigHandler().set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, allowLeadingWildcard); } /** @@ -243,16 +235,22 @@ * Default: false. */ public void setEnablePositionIncrements(boolean enabled) { - PositionIncrementsAttribute attr = getQueryConfigHandler().getAttribute(PositionIncrementsAttribute.class); - attr.setPositionIncrementsEnabled(enabled); + getQueryConfigHandler().set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, enabled); } /** * @see #setEnablePositionIncrements(boolean) */ public boolean getEnablePositionIncrements() { - PositionIncrementsAttribute attr = getQueryConfigHandler().getAttribute(PositionIncrementsAttribute.class); - return attr.isPositionIncrementsEnabled(); + Boolean enablePositionsIncrements = getQueryConfigHandler().get(ConfigurationKeys.ENABLE_POSITION_INCREMENTS); + + if (enablePositionsIncrements == null) { + return false; + + } else { + return enablePositionsIncrements; + } + } /** @@ -266,16 +264,14 @@ * not relevant then use this change the rewrite method. */ public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method) { - MultiTermRewriteMethodAttribute attr = getQueryConfigHandler().getAttribute(MultiTermRewriteMethodAttribute.class); - attr.setMultiTermRewriteMethod(method); + getQueryConfigHandler().set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD, method); } /** * @see #setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod) */ public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod() { - MultiTermRewriteMethodAttribute attr = getQueryConfigHandler().getAttribute(MultiTermRewriteMethodAttribute.class); - return attr.getMultiTermRewriteMethod(); + return getQueryConfigHandler().get(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD); } public void setMultiFields(CharSequence[] fields) { @@ -284,8 +280,7 @@ fields = new CharSequence[0]; } - MultiFieldAttribute attr = getQueryConfigHandler().addAttribute(MultiFieldAttribute.class); - attr.setFields(fields); + getQueryConfigHandler().set(ConfigurationKeys.MULTI_FIELDS, fields); } @@ -296,24 +291,30 @@ * The fuzzyPrefixLength to set. */ public void setFuzzyPrefixLength(int fuzzyPrefixLength) { - FuzzyAttribute attr = getQueryConfigHandler().addAttribute(FuzzyAttribute.class); - attr.setPrefixLength(fuzzyPrefixLength); + QueryConfigHandler config = getQueryConfigHandler(); + FuzzyConfig fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG); + + if (fuzzyConfig == null) { + fuzzyConfig = new FuzzyConfig(); + config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig); + } + + fuzzyConfig.setPrefixLength(fuzzyPrefixLength); + } /** * Set locale used by date range parsing. */ public void setLocale(Locale locale) { - LocaleAttribute attr = getQueryConfigHandler().addAttribute(LocaleAttribute.class); - attr.setLocale(locale); + getQueryConfigHandler().set(ConfigurationKeys.LOCALE, locale); } /** * Returns current locale, allowing access by subclasses. */ public Locale getLocale() { - LocaleAttribute attr = getQueryConfigHandler().addAttribute(LocaleAttribute.class); - return attr.getLocale(); + return getQueryConfigHandler().get(ConfigurationKeys.LOCALE); } /** @@ -321,40 +322,42 @@ * required. Default value is zero. */ public void setDefaultPhraseSlop(int defaultPhraseSlop) { - DefaultPhraseSlopAttribute attr = getQueryConfigHandler().addAttribute(DefaultPhraseSlopAttribute.class); - attr.setDefaultPhraseSlop(defaultPhraseSlop); + getQueryConfigHandler().set(ConfigurationKeys.DEFAULT_PHRASE_SLOP, defaultPhraseSlop); } public void setAnalyzer(Analyzer analyzer) { - AnalyzerAttribute attr = getQueryConfigHandler().getAttribute(AnalyzerAttribute.class); - attr.setAnalyzer(analyzer); + getQueryConfigHandler().set(ConfigurationKeys.ANALYZER, analyzer); } public Analyzer getAnalyzer() { - QueryConfigHandler config = this.getQueryConfigHandler(); - - if ( config.hasAttribute(AnalyzerAttribute.class)) { - AnalyzerAttribute attr = config.getAttribute(AnalyzerAttribute.class); - return attr.getAnalyzer(); - } - - return null; + return getQueryConfigHandler().get(ConfigurationKeys.ANALYZER); } /** * @see #setAllowLeadingWildcard(boolean) */ public boolean getAllowLeadingWildcard() { - AllowLeadingWildcardAttribute attr = getQueryConfigHandler().addAttribute(AllowLeadingWildcardAttribute.class); - return attr.isAllowLeadingWildcard(); + Boolean allowLeadingWildcard = getQueryConfigHandler().get(ConfigurationKeys.ALLOW_LEADING_WILDCARD); + + if (allowLeadingWildcard == null) { + return false; + + } else { + return allowLeadingWildcard; + } } /** * Get the minimal similarity for fuzzy queries. */ public float getFuzzyMinSim() { - FuzzyAttribute attr = getQueryConfigHandler().addAttribute(FuzzyAttribute.class); - return attr.getFuzzyMinSimilarity(); + FuzzyConfig fuzzyConfig = getQueryConfigHandler().get(ConfigurationKeys.FUZZY_CONFIG); + + if (fuzzyConfig == null) { + return FuzzyQuery.defaultMinSimilarity; + } else { + return fuzzyConfig.getMinSimilarity(); + } } /** @@ -363,16 +366,27 @@ * @return Returns the fuzzyPrefixLength. */ public int getFuzzyPrefixLength() { - FuzzyAttribute attr = getQueryConfigHandler().addAttribute(FuzzyAttribute.class); - return attr.getPrefixLength(); + FuzzyConfig fuzzyConfig = getQueryConfigHandler().get(ConfigurationKeys.FUZZY_CONFIG); + + if (fuzzyConfig == null) { + return FuzzyQuery.defaultPrefixLength; + } else { + return fuzzyConfig.getPrefixLength(); + } } /** * Gets the default slop for phrases. */ public int getPhraseSlop() { - DefaultPhraseSlopAttribute attr = getQueryConfigHandler().addAttribute(DefaultPhraseSlopAttribute.class); - return attr.getDefaultPhraseSlop(); + Integer phraseSlop = getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_PHRASE_SLOP); + + if (phraseSlop == null) { + return 0; + + } else { + return phraseSlop; + } } /** @@ -380,23 +394,27 @@ * {@link FuzzyQuery#defaultMinSimilarity}. */ public void setFuzzyMinSim(float fuzzyMinSim) { - FuzzyAttribute attr = getQueryConfigHandler().addAttribute(FuzzyAttribute.class); - attr.setFuzzyMinSimilarity(fuzzyMinSim); + QueryConfigHandler config = getQueryConfigHandler(); + FuzzyConfig fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG); + + if (fuzzyConfig == null) { + fuzzyConfig = new FuzzyConfig(); + config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig); + } + + fuzzyConfig.setMinSimilarity(fuzzyMinSim); } public void setFieldsBoost(Map boosts) { - FieldBoostMapAttribute attr = getQueryConfigHandler().addAttribute(FieldBoostMapAttribute.class); - attr.setFieldBoostMap(boosts); + getQueryConfigHandler().set(ConfigurationKeys.FIELD_BOOST_MAP, boosts); } public void setDateResolution(DateTools.Resolution dateResolution) { - DateResolutionAttribute attr = getQueryConfigHandler().addAttribute(DateResolutionAttribute.class); - attr.setDateResolution(dateResolution); + getQueryConfigHandler().set(ConfigurationKeys.DATE_RESOLUTION, dateResolution); } public void setDateResolution(Map dateRes) { - FieldDateResolutionMapAttribute attr = getQueryConfigHandler().addAttribute(FieldDateResolutionMapAttribute.class); - attr.setFieldDateResolutionMap(dateRes); + getQueryConfigHandler().set(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP, dateRes); } } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/AbstractQueryConfig.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/AbstractQueryConfig.java (revision 0) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/AbstractQueryConfig.java (revision 0) @@ -0,0 +1,72 @@ +package org.apache.lucene.queryParser.core.config; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.HashMap; + +abstract class AbstractQueryConfig { + + final private HashMap, Object> configMap = new HashMap, Object>(); + + @SuppressWarnings("unchecked") + public T get(ConfigurationKey key) { + + if (key == null) { + throw new IllegalArgumentException("key cannot be null!"); + } + + return (T) this.configMap.get(key); + + } + + public boolean has(ConfigurationKey key) { + + if (key == null) { + throw new IllegalArgumentException("key cannot be null!"); + } + + return this.configMap.containsKey(key); + + } + + public void set(ConfigurationKey key, T value) { + + if (key == null) { + throw new IllegalArgumentException("key cannot be null!"); + } + + if (value == null) { + unset(key); + + } else { + this.configMap.put(key, value); + } + + } + + public boolean unset(ConfigurationKey key) { + + if (key == null) { + throw new IllegalArgumentException("key cannot be null!"); + } + + return this.configMap.remove(key) != null; + + } + +} Property changes on: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/AbstractQueryConfig.java ___________________________________________________________________ Added: svn:keywords + Rev Date Added: svn:eol-style + native Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java (working copy) @@ -40,8 +40,7 @@ import org.apache.lucene.queryParser.core.nodes.TextableQueryNode; import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.AnalyzerAttribute; -import org.apache.lucene.queryParser.standard.config.PositionIncrementsAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode; import org.apache.lucene.queryParser.standard.nodes.StandardBooleanQueryNode; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; @@ -79,24 +78,15 @@ @Override public QueryNode process(QueryNode queryTree) throws QueryNodeException { - - if (getQueryConfigHandler().hasAttribute(AnalyzerAttribute.class)) { - - this.analyzer = getQueryConfigHandler().getAttribute( - AnalyzerAttribute.class).getAnalyzer(); - + Analyzer analyzer = getQueryConfigHandler().get(ConfigurationKeys.ANALYZER); + + if (analyzer != null) { + this.analyzer = analyzer; this.positionIncrementsEnabled = false; + Boolean positionIncrementsEnabled = getQueryConfigHandler().get(ConfigurationKeys.ENABLE_POSITION_INCREMENTS); - if (getQueryConfigHandler().hasAttribute( - PositionIncrementsAttribute.class)) { - - if (getQueryConfigHandler().getAttribute( - PositionIncrementsAttribute.class).isPositionIncrementsEnabled()) { - - this.positionIncrementsEnabled = true; - - } - + if (positionIncrementsEnabled != null) { + this.positionIncrementsEnabled = positionIncrementsEnabled; } if (this.analyzer != null) { Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/config/TestAttributes.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/config/TestAttributes.java (revision 1134981) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/config/TestAttributes.java (working copy) @@ -1,65 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.util._TestUtil; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.search.MultiTermQuery; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; - -public class TestAttributes extends LuceneTestCase { - - // this checks using reflection API if the defaults are correct - public void testAttributes() { - _TestUtil.assertAttributeReflection(new AllowLeadingWildcardAttributeImpl(), - Collections.singletonMap(AllowLeadingWildcardAttribute.class.getName()+"#allowLeadingWildcard", false)); - _TestUtil.assertAttributeReflection(new AnalyzerAttributeImpl(), - Collections.singletonMap(AnalyzerAttribute.class.getName()+"#analyzer", null)); - _TestUtil.assertAttributeReflection(new BoostAttributeImpl(), - Collections.singletonMap(BoostAttribute.class.getName()+"#boost", 1.0f)); - _TestUtil.assertAttributeReflection(new DateResolutionAttributeImpl(), - Collections.singletonMap(DateResolutionAttribute.class.getName()+"#dateResolution", null)); - _TestUtil.assertAttributeReflection(new DefaultOperatorAttributeImpl(), - Collections.singletonMap(DefaultOperatorAttribute.class.getName()+"#operator", DefaultOperatorAttribute.Operator.OR)); - _TestUtil.assertAttributeReflection(new DefaultPhraseSlopAttributeImpl(), - Collections.singletonMap(DefaultPhraseSlopAttribute.class.getName()+"#defaultPhraseSlop", 0)); - _TestUtil.assertAttributeReflection(new FieldBoostMapAttributeImpl(), - Collections.singletonMap(FieldBoostMapAttribute.class.getName()+"#boosts", Collections.emptyMap())); - _TestUtil.assertAttributeReflection(new FieldDateResolutionMapAttributeImpl(), - Collections.singletonMap(FieldDateResolutionMapAttribute.class.getName()+"#dateRes", Collections.emptyMap())); - _TestUtil.assertAttributeReflection(new FuzzyAttributeImpl(), new HashMap() {{ - put(FuzzyAttribute.class.getName()+"#prefixLength", FuzzyQuery.defaultPrefixLength); - put(FuzzyAttribute.class.getName()+"#minSimilarity", FuzzyQuery.defaultMinSimilarity); - }}); - _TestUtil.assertAttributeReflection(new LocaleAttributeImpl(), - Collections.singletonMap(LocaleAttribute.class.getName()+"#locale", Locale.getDefault())); - _TestUtil.assertAttributeReflection(new LowercaseExpandedTermsAttributeImpl(), - Collections.singletonMap(LowercaseExpandedTermsAttribute.class.getName()+"#lowercaseExpandedTerms", true)); - _TestUtil.assertAttributeReflection(new MultiFieldAttributeImpl(), - Collections.singletonMap(MultiFieldAttribute.class.getName()+"#fields", null)); - _TestUtil.assertAttributeReflection(new MultiTermRewriteMethodAttributeImpl(), - Collections.singletonMap(MultiTermRewriteMethodAttribute.class.getName()+"#multiTermRewriteMethod", MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT)); - _TestUtil.assertAttributeReflection(new PositionIncrementsAttributeImpl(), - Collections.singletonMap(PositionIncrementsAttribute.class.getName()+"#positionIncrementsEnabled", false)); - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java (working copy) @@ -27,7 +27,7 @@ import org.apache.lucene.queryParser.core.nodes.GroupQueryNode; import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.MultiFieldAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; /** * This processor is used to expand terms so the query looks for the same term @@ -78,15 +78,13 @@ FieldableNode fieldNode = (FieldableNode) node; if (fieldNode.getField() == null) { + CharSequence[] fields = getQueryConfigHandler().get(ConfigurationKeys.MULTI_FIELDS); - if (!getQueryConfigHandler().hasAttribute(MultiFieldAttribute.class)) { + if (fields == null) { throw new IllegalArgumentException( - "MultiFieldAttribute should be set on the QueryConfigHandler"); + "MULTI_FIELDS should be set on the QueryConfigHandler"); } - CharSequence[] fields = getQueryConfigHandler().getAttribute( - MultiFieldAttribute.class).getFields(); - if (fields != null && fields.length > 0) { fieldNode.setField(fields[0]); Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java (revision 1134981) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java (working copy) @@ -28,7 +28,8 @@ import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.queryParser.core.QueryNodeException; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -133,7 +134,7 @@ assertEquals("(b:one t:one) f:two", q.toString()); // AND mode: - mfqp.setDefaultOperator(Operator.AND); + mfqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); q = mfqp.parse("one two", null); assertEquals("+(b:one t:one) +(b:two t:two)", q.toString()); q = mfqp.parse("\"aa bb cc\" \"dd ee\"", null); @@ -329,7 +330,7 @@ mfqp.setMultiFields(new String[] { "body" }); mfqp.setAnalyzer(analyzer); - mfqp.setDefaultOperator(Operator.AND); + mfqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); Query q = mfqp.parse("the footest", null); IndexSearcher is = new IndexSearcher(ramDir, true); ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs; Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AnalyzerAttributeImpl.java (working copy) @@ -1,90 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AnalyzerQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link AnalyzerQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. It provides to this - * processor the {@link Analyzer}, if there is one, which will be used to - * analyze the query terms.
- * - * @see org.apache.lucene.queryParser.standard.config.AnalyzerAttribute - */ -public class AnalyzerAttributeImpl extends AttributeImpl - implements AnalyzerAttribute { - - private Analyzer analyzer; - - public AnalyzerAttributeImpl() { - analyzer = null; //default value 2.4 - } - - public void setAnalyzer(Analyzer analyzer) { - this.analyzer = analyzer; - } - - public Analyzer getAnalyzer() { - return this.analyzer; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof AnalyzerAttributeImpl) { - AnalyzerAttributeImpl analyzerAttr = (AnalyzerAttributeImpl) other; - - if (analyzerAttr.analyzer == this.analyzer - || (this.analyzer != null && analyzerAttr.analyzer != null && this.analyzer - .equals(analyzerAttr.analyzer))) { - - return true; - - } - - } - - return false; - - } - - @Override - public int hashCode() { - return (this.analyzer == null) ? 0 : this.analyzer.hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/UniqueFieldQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/UniqueFieldQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/UniqueFieldQueryNodeProcessor.java (working copy) @@ -57,14 +57,12 @@ "A config handler is expected by the processor UniqueFieldQueryNodeProcessor!"); } - if (!queryConfig.hasAttribute(UniqueFieldAttribute.class)) { + if (!queryConfig.has(SpansQueryConfigHandler.UNIQUE_FIELD)) { throw new IllegalArgumentException( "UniqueFieldAttribute should be defined in the config handler!"); } - CharSequence uniqueField = queryConfig.getAttribute( - UniqueFieldAttribute.class).getUniqueField(); - + String uniqueField = queryConfig.get(SpansQueryConfigHandler.UNIQUE_FIELD); fieldNode.setField(uniqueField); } Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java (revision 1134869) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java (working copy) @@ -104,9 +104,7 @@ // create a config handler with a attribute used in // UniqueFieldQueryNodeProcessor QueryConfigHandler spanQueryConfigHandler = new SpansQueryConfigHandler(); - UniqueFieldAttribute uniqueFieldAtt = spanQueryConfigHandler - .getAttribute(UniqueFieldAttribute.class); - uniqueFieldAtt.setUniqueField("index"); + spanQueryConfigHandler.set(SpansQueryConfigHandler.UNIQUE_FIELD, "index"); // set up the processor pipeline with the ConfigHandler // and create the pipeline for this simple demo Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java (working copy) @@ -17,8 +17,17 @@ * limitations under the License. */ +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.document.DateTools; +import org.apache.lucene.queryParser.core.config.ConfigurationKey; import org.apache.lucene.queryParser.core.config.QueryConfigHandler; import org.apache.lucene.queryParser.standard.processors.StandardQueryNodeProcessorPipeline; +import org.apache.lucene.search.MultiTermQuery; /** * This query configuration handler is used for almost every processor defined @@ -30,24 +39,63 @@ */ public class StandardQueryConfigHandler extends QueryConfigHandler { + final public static class ConfigurationKeys { + + final public static ConfigurationKey ENABLE_POSITION_INCREMENTS = ConfigurationKey.newInstance(); + + final public static ConfigurationKey LOWERCASE_EXPANDED_TERMS = ConfigurationKey.newInstance(); + + final public static ConfigurationKey ALLOW_LEADING_WILDCARD = ConfigurationKey.newInstance(); + + final public static ConfigurationKey ANALYZER = ConfigurationKey.newInstance(); + + final public static ConfigurationKey DEFAULT_OPERATOR = ConfigurationKey.newInstance(); + + final public static ConfigurationKey DEFAULT_PHRASE_SLOP = ConfigurationKey.newInstance(); + + final public static ConfigurationKey LOCALE = ConfigurationKey.newInstance(); + + final public static ConfigurationKey MULTI_TERM_REWRITE_METHOD = ConfigurationKey.newInstance(); + + final public static ConfigurationKey MULTI_FIELDS = ConfigurationKey.newInstance(); + + final public static ConfigurationKey> FIELD_BOOST_MAP = ConfigurationKey.newInstance(); + + final public static ConfigurationKey> FIELD_DATE_RESOLUTION_MAP = ConfigurationKey.newInstance(); + + final public static ConfigurationKey FUZZY_CONFIG = ConfigurationKey.newInstance(); + + final public static ConfigurationKey DATE_RESOLUTION = ConfigurationKey.newInstance(); + + } + + final public static class FieldConfigurationKeys { + final public static ConfigurationKey BOOST = ConfigurationKey.newInstance(); + + } + public static enum Operator { + AND, OR; + } + public StandardQueryConfigHandler() { // Add listener that will build the FieldConfig attributes. addFieldConfigListener(new FieldBoostMapFCListener(this)); addFieldConfigListener(new FieldDateResolutionFCListener(this)); - + // Default Values - addAttribute(DefaultOperatorAttribute.class); - addAttribute(AnalyzerAttribute.class); - addAttribute(FuzzyAttribute.class); - addAttribute(LowercaseExpandedTermsAttribute.class); - addAttribute(MultiTermRewriteMethodAttribute.class); - addAttribute(AllowLeadingWildcardAttribute.class); - addAttribute(PositionIncrementsAttribute.class); - addAttribute(LocaleAttribute.class); - addAttribute(DefaultPhraseSlopAttribute.class); - addAttribute(MultiTermRewriteMethodAttribute.class); + set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false); // default in 2.9 + set(ConfigurationKeys.ANALYZER, null); //default value 2.4 + set(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR); + set(ConfigurationKeys.DEFAULT_PHRASE_SLOP, 0); //default value 2.4 + set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, true); //default value 2.4 + set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, false); //default value 2.4 + set(ConfigurationKeys.FIELD_BOOST_MAP, new LinkedHashMap()); + set(ConfigurationKeys.FUZZY_CONFIG, new FuzzyConfig()); + set(ConfigurationKeys.LOCALE, Locale.getDefault()); + set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD, MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); + set(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP, new HashMap()); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Locale; - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by processor {@link ParametricRangeQueryNodeProcessor} - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor what is the default {@link Locale} used to parse a date.
- * - */ -public interface LowercaseExpandedTermsAttribute extends Attribute { - public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms); - public boolean isLowercaseExpandedTerms(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttributeImpl.java (working copy) @@ -1,86 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.search.MultiTermQuery; -import org.apache.lucene.search.MultiTermQuery.RewriteMethod; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link ParametricRangeQueryNodeProcessor} processor - * and should be defined in the {@link QueryConfigHandler} used by this - * processor. It basically tells the processor which {@link RewriteMethod} to - * use.
- * - * @see MultiTermRewriteMethodAttribute - */ -public class MultiTermRewriteMethodAttributeImpl extends AttributeImpl - implements MultiTermRewriteMethodAttribute { - - private MultiTermQuery.RewriteMethod multiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT; - - public MultiTermRewriteMethodAttributeImpl() { - // empty constructor - } - - public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method) { - multiTermRewriteMethod = method; - } - - public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod() { - return multiTermRewriteMethod; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof MultiTermRewriteMethodAttributeImpl - && ((MultiTermRewriteMethodAttributeImpl) other).multiTermRewriteMethod == this.multiTermRewriteMethod) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return multiTermRewriteMethod.hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttributeImpl.java (working copy) @@ -1,89 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.HashMap; -import java.util.Map; - -import org.apache.lucene.document.DateTools; -import org.apache.lucene.document.DateTools.Resolution; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute enables the user to define a default DateResolution per field. - * it's used by {@link FieldDateResolutionFCListener#buildFieldConfig(org.apache.lucene.queryParser.core.config.FieldConfig)} - * - * @see FieldDateResolutionMapAttribute - */ -public class FieldDateResolutionMapAttributeImpl extends AttributeImpl - implements FieldDateResolutionMapAttribute { - - private Map dateRes = new HashMap(); - - - public FieldDateResolutionMapAttributeImpl() { - // empty constructor - } - - public void setFieldDateResolutionMap(Map dateRes) { - this.dateRes = dateRes; - } - - public Map getFieldDateResolutionMap() { - return this.dateRes; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof FieldDateResolutionMapAttributeImpl - && ((FieldDateResolutionMapAttributeImpl) other).dateRes.equals(this.dateRes) ) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - final int prime = 97; - if (this.dateRes != null) - return this.dateRes.hashCode() * prime; - else - return Float.valueOf(prime).hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttribute.java (working copy) @@ -1,39 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.GroupQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link GroupQueryNodeProcessor} processor and must - * be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor which is the default boolean operator when no operator is defined - * between terms.
- * - */ -public interface DefaultOperatorAttribute extends Attribute { - public static enum Operator { - AND, OR; - } - - public void setOperator(Operator operator); - public Operator getOperator(); -} - Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (revision 1134869) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (working copy) @@ -38,7 +38,8 @@ import org.apache.lucene.queryParser.TestQueryParser; import org.apache.lucene.queryParser.core.QueryNodeException; import org.apache.lucene.queryParser.core.QueryNodeParseException; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; import org.apache.lucene.queryParser.standard.parser.ParseException; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FuzzyQuery; @@ -128,7 +129,7 @@ a = new MockAnalyzer(random, MockTokenizer.SIMPLE, true); PrecedenceQueryParser qp = new PrecedenceQueryParser(); qp.setAnalyzer(a); - qp.setDefaultOperator(Operator.OR); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR); return qp; } @@ -174,7 +175,7 @@ a = new MockAnalyzer(random, MockTokenizer.SIMPLE, true); PrecedenceQueryParser qp = new PrecedenceQueryParser(); qp.setAnalyzer(a); - qp.setDefaultOperator(Operator.AND); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); return qp.parse(query, "field"); } @@ -234,11 +235,11 @@ PrecedenceQueryParser qp = new PrecedenceQueryParser(); qp.setAnalyzer(new MockAnalyzer(random)); // make sure OR is the default: - assertEquals(Operator.OR, qp.getDefaultOperator()); - qp.setDefaultOperator(Operator.AND); - assertEquals(Operator.AND, qp.getDefaultOperator()); - qp.setDefaultOperator(Operator.OR); - assertEquals(Operator.OR, qp.getDefaultOperator()); + assertEquals(StandardQueryConfigHandler.Operator.OR, qp.getDefaultOperator()); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); + assertEquals(StandardQueryConfigHandler.Operator.AND, qp.getDefaultOperator()); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR); + assertEquals(StandardQueryConfigHandler.Operator.OR, qp.getDefaultOperator()); assertQueryEquals("a OR !b", null, "a -b"); assertQueryEquals("a OR ! b", null, "a -b"); @@ -607,7 +608,7 @@ query2 = parser.parse("A (-B +C)", "field"); assertEquals(query1, query2); - parser.setDefaultOperator(Operator.AND); + parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); query1 = parser.parse("A AND B OR C AND D", "field"); query2 = parser.parse("(A AND B) OR (C AND D)", "field"); assertEquals(query1, query2); Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DateResolutionAttributeImpl.java (working copy) @@ -1,90 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.document.DateTools; -import org.apache.lucene.document.DateTools.Resolution; -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link ParametricRangeQueryNodeProcessor} processor - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor which {@link Resolution} to use when parsing the date.
- * - * @see org.apache.lucene.queryParser.standard.config.DateResolutionAttribute - */ -public class DateResolutionAttributeImpl extends AttributeImpl - implements DateResolutionAttribute { - - private DateTools.Resolution dateResolution = null; - - public DateResolutionAttributeImpl() { - dateResolution = null; //default in 2.4 - } - - public void setDateResolution(DateTools.Resolution dateResolution) { - this.dateResolution = dateResolution; - } - - public DateTools.Resolution getDateResolution() { - return this.dateResolution; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof DateResolutionAttributeImpl) { - DateResolutionAttributeImpl dateResAttr = (DateResolutionAttributeImpl) other; - - if (dateResAttr.getDateResolution() == getDateResolution() - || dateResAttr.getDateResolution().equals(getDateResolution())) { - - return true; - - } - - } - - return false; - - } - - @Override - public int hashCode() { - return (this.dateResolution == null) ? 0 : this.dateResolution.hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttributeImpl.java (working copy) @@ -1,84 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.FieldConfig; -import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and - * it should be defined in a {@link FieldConfig}. This processor uses this - * attribute to define which boost a specific field should have when none is - * defined to it.
- *
- * - * @see org.apache.lucene.queryParser.standard.config.BoostAttribute - */ -public class BoostAttributeImpl extends AttributeImpl - implements BoostAttribute { - - private float boost = 1.0f; - - public BoostAttributeImpl() { - // empty constructor - } - - public void setBoost(float boost) { - this.boost = boost; - } - - public float getBoost() { - return this.boost; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof BoostAttributeImpl - && ((BoostAttributeImpl) other).boost == this.boost) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return Float.valueOf(this.boost).hashCode(); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/WildcardQueryNodeBuilder.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/WildcardQueryNodeBuilder.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/WildcardQueryNodeBuilder.java (working copy) @@ -20,8 +20,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.core.QueryNodeException; import org.apache.lucene.queryParser.core.nodes.QueryNode; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; +import org.apache.lucene.queryParser.standard.processors.MultiTermRewriteMethodProcessor; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.WildcardQuery; @@ -41,7 +41,7 @@ WildcardQuery q = new WildcardQuery(new Term(wildcardNode.getFieldAsString(), wildcardNode.getTextAsString())); - MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodAttribute.TAG_ID); + MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID); if (method != null) { q.setRewriteMethod(method); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionFCListener.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionFCListener.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionFCListener.java (working copy) @@ -17,10 +17,13 @@ * limitations under the License. */ +import java.util.Map; + import org.apache.lucene.document.DateTools; import org.apache.lucene.queryParser.core.config.FieldConfig; import org.apache.lucene.queryParser.core.config.FieldConfigListener; import org.apache.lucene.queryParser.core.config.QueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; /** * This listener listens for every field configuration request and assign a @@ -43,30 +46,22 @@ } public void buildFieldConfig(FieldConfig fieldConfig) { - DateResolutionAttribute fieldDateResAttr = fieldConfig - .addAttribute(DateResolutionAttribute.class); DateTools.Resolution dateRes = null; + Map dateResMap = this.config.get(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP); - if (this.config.hasAttribute(FieldDateResolutionMapAttribute.class)) { - FieldDateResolutionMapAttribute dateResMapAttr = this.config - .addAttribute(FieldDateResolutionMapAttribute.class); - dateRes = dateResMapAttr.getFieldDateResolutionMap().get( + if (dateResMap != null) { + dateRes = dateResMap.get( fieldConfig.getField()); } if (dateRes == null) { + dateRes = this.config.get(ConfigurationKeys.DATE_RESOLUTION); + } - if (this.config.hasAttribute(DateResolutionAttribute.class)) { - DateResolutionAttribute dateResAttr = this.config - .addAttribute(DateResolutionAttribute.class); - dateRes = dateResAttr.getDateResolution(); - - } - + if (dateRes != null) { + fieldConfig.set(ConfigurationKeys.DATE_RESOLUTION, dateRes); } - fieldDateResAttr.setDateResolution(dateRes); - } } Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java (revision 1134981) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java (working copy) @@ -28,7 +28,8 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import org.apache.lucene.queryParser.core.QueryNodeException; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; import org.apache.lucene.util.LuceneTestCase; /** @@ -102,7 +103,7 @@ qp.setDefaultPhraseSlop(0); // non-default operator: - qp.setDefaultOperator(Operator.AND); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); assertEquals("+(multi multi2) +foo", qp.parse("multi foo", "").toString()); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttribute.java (working copy) @@ -1,33 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AnalyzerQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link AnalyzerQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor if the position increment is enabled.
- * - */ -public interface PositionIncrementsAttribute extends Attribute { - public void setPositionIncrementsEnabled(boolean positionIncrementsEnabled); - public boolean isPositionIncrementsEnabled(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionMapAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Map; - -import org.apache.lucene.document.DateTools; -import org.apache.lucene.util.Attribute; - -/** - * This attribute enables the user to define a default DateResolution per field. - * it's used by {@link FieldDateResolutionFCListener#buildFieldConfig(org.apache.lucene.queryParser.core.config.FieldConfig)} - */ -public interface FieldDateResolutionMapAttribute extends Attribute { - /** - * @param dateRes a mapping from field name to its default boost - */ - public void setFieldDateResolutionMap(Map dateRes); - public Map getFieldDateResolutionMap(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/BoostAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.FieldConfig; -import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and - * it should be defined in a {@link FieldConfig}. This processor uses this - * attribute to define which boost a specific field should have when none is - * defined to it.
- *
- * - */ -public interface BoostAttribute extends Attribute { - public void setBoost(float boost); - public float getBoost(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RegexpQueryNodeBuilder.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RegexpQueryNodeBuilder.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/RegexpQueryNodeBuilder.java (working copy) @@ -20,8 +20,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.core.QueryNodeException; import org.apache.lucene.queryParser.core.nodes.QueryNode; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode; +import org.apache.lucene.queryParser.standard.processors.MultiTermRewriteMethodProcessor; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.RegexpQuery; @@ -41,7 +41,7 @@ regexpNode.textToBytesRef())); MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode - .getTag(MultiTermRewriteMethodAttribute.TAG_ID); + .getTag(MultiTermRewriteMethodProcessor.TAG_ID); if (method != null) { q.setRewriteMethod(method); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttribute.java (working copy) @@ -1,33 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor to which fields the terms in the query should be expanded.
- * - */ -public interface MultiFieldAttribute extends Attribute { - public void setFields(CharSequence[] fields); - public CharSequence[] getFields(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/ConfigurationKey.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/ConfigurationKey.java (revision 0) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/ConfigurationKey.java (revision 0) @@ -0,0 +1,28 @@ +package org.apache.lucene.queryParser.core.config; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +final public class ConfigurationKey { + + private ConfigurationKey() {} + + public static ConfigurationKey newInstance() { + return new ConfigurationKey(); + } + +} Property changes on: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/ConfigurationKey.java ___________________________________________________________________ Added: svn:keywords + Rev Date Added: svn:eol-style + native Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java (working copy) @@ -26,7 +26,7 @@ import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryParser.core.util.UnescapedCharSequence; -import org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; import org.apache.lucene.queryParser.standard.parser.EscapeQuerySyntaxImpl; @@ -47,11 +47,11 @@ @Override public QueryNode process(QueryNode queryTree) throws QueryNodeException { + Boolean allowsLeadingWildcard = getQueryConfigHandler().get(ConfigurationKeys.ALLOW_LEADING_WILDCARD); - if (getQueryConfigHandler().hasAttribute(AllowLeadingWildcardAttribute.class)) { + if (allowsLeadingWildcard != null) { - AllowLeadingWildcardAttribute alwAttr= getQueryConfigHandler().getAttribute(AllowLeadingWildcardAttribute.class); - if (!alwAttr.isAllowLeadingWildcard()) { + if (!allowsLeadingWildcard) { return super.process(queryTree); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/AllowLeadingWildcardAttributeImpl.java (working copy) @@ -1,79 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AllowLeadingWildcardProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link AllowLeadingWildcardProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. It basically tells the - * processor if it should allow leading wildcard.
- * - * @see org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute - */ -public class AllowLeadingWildcardAttributeImpl extends AttributeImpl - implements AllowLeadingWildcardAttribute { - - private boolean allowLeadingWildcard = false; // default in 2.9 - - public void setAllowLeadingWildcard(boolean allowLeadingWildcard) { - this.allowLeadingWildcard = allowLeadingWildcard; - } - - public boolean isAllowLeadingWildcard() { - return this.allowLeadingWildcard; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof AllowLeadingWildcardAttributeImpl - && ((AllowLeadingWildcardAttributeImpl) other).allowLeadingWildcard == this.allowLeadingWildcard) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return this.allowLeadingWildcard ? -1 : Integer.MAX_VALUE; - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/DefaultOperatorAttributeImpl.java (working copy) @@ -1,92 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.GroupQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link GroupQueryNodeProcessor} processor and must - * be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor which is the default boolean operator when no operator is defined - * between terms.
- * - * @see org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute - */ -public class DefaultOperatorAttributeImpl extends AttributeImpl - implements DefaultOperatorAttribute { - - private Operator operator = Operator.OR; - - public DefaultOperatorAttributeImpl() { - // empty constructor - } - - public void setOperator(Operator operator) { - - if (operator == null) { - throw new IllegalArgumentException("default operator cannot be null!"); - } - - this.operator = operator; - - } - - public Operator getOperator() { - return this.operator; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof DefaultOperatorAttributeImpl) { - DefaultOperatorAttributeImpl defaultOperatorAttr = (DefaultOperatorAttributeImpl) other; - - if (defaultOperatorAttr.getOperator() == this.getOperator()) { - return true; - - } - - } - - return false; - - } - - @Override - public int hashCode() { - return getOperator().hashCode() * 31; - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java (working copy) @@ -24,7 +24,8 @@ import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode; import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.FuzzyAttribute; +import org.apache.lucene.queryParser.standard.config.FuzzyConfig; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.search.FuzzyQuery; /** @@ -54,18 +55,17 @@ FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) node; QueryConfigHandler config = getQueryConfigHandler(); - if (config != null && config.hasAttribute(FuzzyAttribute.class)) { - FuzzyAttribute fuzzyAttr = config.getAttribute(FuzzyAttribute.class); - fuzzyNode.setPrefixLength(fuzzyAttr.getPrefixLength()); + FuzzyConfig fuzzyConfig = null; + + if (config != null && (fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG)) != null) { + fuzzyNode.setPrefixLength(fuzzyConfig.getPrefixLength()); if (fuzzyNode.getSimilarity() < 0) { - fuzzyNode.setSimilarity(fuzzyAttr.getFuzzyMinSimilarity()); - + fuzzyNode.setSimilarity(fuzzyConfig.getMinSimilarity()); } - + } else if (fuzzyNode.getSimilarity() < 0) { - throw new IllegalArgumentException("No " - + FuzzyAttribute.class.getName() + " set in the config"); + throw new IllegalArgumentException("No FUZZY_CONFIG set in the config"); } } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttribute.java (working copy) @@ -1,35 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Map; - -import org.apache.lucene.queryParser.core.config.FieldConfig; -import org.apache.lucene.util.Attribute; - -/** - * This attribute enables the user to define a default boost per field. - * it's used by {@link FieldBoostMapFCListener#buildFieldConfig(FieldConfig)} - */ -public interface FieldBoostMapAttribute extends Attribute { - /** - * @param boosts a mapping from field name to its default boost - */ - public void setFieldBoostMap(Map boosts); - public Map getFieldBoostMap(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttribute.java (working copy) @@ -1,40 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.search.MultiTermQuery; -import org.apache.lucene.search.MultiTermQuery.RewriteMethod; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link ParametricRangeQueryNodeProcessor} processor - * and should be defined in the {@link QueryConfigHandler} used by this - * processor. It basically tells the processor which {@link RewriteMethod} to - * use.
- * - */ -public interface MultiTermRewriteMethodAttribute extends Attribute { - - public static final String TAG_ID = "MultiTermRewriteMethodAttribute"; - - public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method); - - public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/PositionIncrementsAttributeImpl.java (working copy) @@ -1,83 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.AnalyzerQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link AnalyzerQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor if the position increment is enabled.
- * - * @see org.apache.lucene.queryParser.standard.config.PositionIncrementsAttribute - */ -public class PositionIncrementsAttributeImpl extends AttributeImpl - implements PositionIncrementsAttribute { - - private boolean positionIncrementsEnabled = false; - - public PositionIncrementsAttributeImpl() { - positionIncrementsEnabled = false; //default in 2.4 - } - - public void setPositionIncrementsEnabled(boolean positionIncrementsEnabled) { - this.positionIncrementsEnabled = positionIncrementsEnabled; - } - - public boolean isPositionIncrementsEnabled() { - return this.positionIncrementsEnabled; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof PositionIncrementsAttributeImpl - && ((PositionIncrementsAttributeImpl) other).positionIncrementsEnabled == this.positionIncrementsEnabled) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return this.positionIncrementsEnabled ? -1 : Integer.MAX_VALUE; - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java (working copy) @@ -22,7 +22,7 @@ import org.apache.lucene.queryParser.core.nodes.ParametricRangeQueryNode; import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; import org.apache.lucene.search.MultiTermQuery; @@ -35,6 +35,8 @@ */ public class MultiTermRewriteMethodProcessor extends QueryNodeProcessorImpl { + public static final String TAG_ID = "MultiTermRewriteMethodAttribute"; + @Override protected QueryNode postProcessNode(QueryNode node) { @@ -42,22 +44,19 @@ // PrefixWildcardQueryNode if (node instanceof WildcardQueryNode || node instanceof ParametricRangeQueryNode || node instanceof RegexpQueryNode) { + + MultiTermQuery.RewriteMethod rewriteMethod = getQueryConfigHandler().get(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD); - if (!getQueryConfigHandler().hasAttribute( - MultiTermRewriteMethodAttribute.class)) { + if (rewriteMethod == null) { // This should not happen, this attribute is created in the // StandardQueryConfigHandler throw new IllegalArgumentException( - "MultiTermRewriteMethodAttribute should be set on the QueryConfigHandler"); + "MULTI_TERM_REWRITE_METHOD should be set on the QueryConfigHandler"); } - // read the attribute value and use a TAG to take the value to the Builder - MultiTermQuery.RewriteMethod rewriteMethod = getQueryConfigHandler() - .getAttribute(MultiTermRewriteMethodAttribute.class) - .getMultiTermRewriteMethod(); + // use a TAG to take the value to the Builder + node.setTag(MultiTermRewriteMethodProcessor.TAG_ID, rewriteMethod); - node.setTag(MultiTermRewriteMethodAttribute.TAG_ID, rewriteMethod); - } return node; Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/precedence/processors/BooleanModifiersQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/precedence/processors/BooleanModifiersQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/precedence/processors/BooleanModifiersQueryNodeProcessor.java (working copy) @@ -29,8 +29,9 @@ import org.apache.lucene.queryParser.core.nodes.ModifierQueryNode.Modifier; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryParser.precedence.PrecedenceQueryParser; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; /** *

@@ -59,14 +60,14 @@ @Override public QueryNode process(QueryNode queryTree) throws QueryNodeException { - - if (!getQueryConfigHandler().hasAttribute(DefaultOperatorAttribute.class)) { + Operator op = getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR); + + if (op == null) { throw new IllegalArgumentException( "DefaultOperatorAttribute should be set on the QueryConfigHandler"); } - this.usingAnd = Operator.AND == getQueryConfigHandler().getAttribute( - DefaultOperatorAttribute.class).getOperator(); + this.usingAnd = StandardQueryConfigHandler.Operator.AND == op; return super.process(queryTree); Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (revision 1134981) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (working copy) @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.Reader; -import java.text.Collator; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; @@ -52,7 +51,7 @@ import org.apache.lucene.queryParser.core.nodes.QueryNode; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorPipeline; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; @@ -195,7 +194,7 @@ StandardQueryParser qp = new StandardQueryParser(); qp.setAnalyzer(a); - qp.setDefaultOperator(Operator.OR); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR); return qp; @@ -284,7 +283,7 @@ a = new MockAnalyzer(random, MockTokenizer.SIMPLE, true); StandardQueryParser qp = new StandardQueryParser(); qp.setAnalyzer(a); - qp.setDefaultOperator(Operator.AND); + qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); return qp.parse(query, "field"); Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapFCListener.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapFCListener.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapFCListener.java (working copy) @@ -17,9 +17,13 @@ * limitations under the License. */ +import java.util.Map; + import org.apache.lucene.queryParser.core.config.FieldConfig; import org.apache.lucene.queryParser.core.config.FieldConfigListener; import org.apache.lucene.queryParser.core.config.QueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.FieldConfigurationKeys; /** * This listener listens for every field configuration request and assign a @@ -40,15 +44,14 @@ this.config = config; } - public void buildFieldConfig(FieldConfig fieldConfig) { - if (this.config.hasAttribute(FieldBoostMapAttribute.class)) { - FieldBoostMapAttribute fieldBoostMapAttr = this.config.getAttribute(FieldBoostMapAttribute.class); - BoostAttribute boostAttr = fieldConfig.addAttribute(BoostAttribute.class); - - Float boost = fieldBoostMapAttr.getFieldBoostMap().get(fieldConfig.getField()); + public void buildFieldConfig(FieldConfig fieldConfig) { + Map fieldBoostMap = this.config.get(ConfigurationKeys.FIELD_BOOST_MAP); + + if (fieldBoostMap != null) { + Float boost = fieldBoostMap.get(fieldConfig.getField()); if (boost != null) { - boostAttr.setBoost(boost.floatValue()); + fieldConfig.set(FieldConfigurationKeys.BOOST, boost); } } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/PrefixWildcardQueryNodeBuilder.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/PrefixWildcardQueryNodeBuilder.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/PrefixWildcardQueryNodeBuilder.java (working copy) @@ -20,8 +20,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.core.QueryNodeException; import org.apache.lucene.queryParser.core.nodes.QueryNode; -import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute; import org.apache.lucene.queryParser.standard.nodes.PrefixWildcardQueryNode; +import org.apache.lucene.queryParser.standard.processors.MultiTermRewriteMethodProcessor; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.PrefixQuery; @@ -42,7 +42,7 @@ String text = wildcardNode.getText().subSequence(0, wildcardNode.getText().length() - 1).toString(); PrefixQuery q = new PrefixQuery(new Term(wildcardNode.getFieldAsString(), text)); - MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodAttribute.TAG_ID); + MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID); if (method != null) { q.setRewriteMethod(method); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiFieldAttributeImpl.java (working copy) @@ -1,84 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Arrays; - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor to which fields the terms in the query should be expanded.
- * - * @see org.apache.lucene.queryParser.standard.config.MultiFieldAttribute - */ -public class MultiFieldAttributeImpl extends AttributeImpl - implements MultiFieldAttribute { - - private CharSequence[] fields; - - public MultiFieldAttributeImpl() { - // empty constructor - } - - public void setFields(CharSequence[] fields) { - this.fields = fields; - } - - public CharSequence[] getFields() { - return this.fields; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof MultiFieldAttributeImpl) { - MultiFieldAttributeImpl fieldsAttr = (MultiFieldAttributeImpl) other; - - return Arrays.equals(this.fields, fieldsAttr.fields); - - } - - return false; - - } - - @Override - public int hashCode() { - return Arrays.hashCode(this.fields); - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/FieldConfig.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/FieldConfig.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/FieldConfig.java (working copy) @@ -26,7 +26,7 @@ * @see QueryConfigHandler * @see org.apache.lucene.util.Attribute */ -public class FieldConfig extends AttributeSource { +public class FieldConfig extends AbstractQueryConfig { private String fieldName; Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttribute.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttribute.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FuzzyAttribute.java (working copy) @@ -1,36 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.PhraseSlopQueryNodeProcessor; -import org.apache.lucene.util.Attribute; - -/** - * This attribute is used by {@link PhraseSlopQueryNodeProcessor} processor and - * must be defined in the {@link QueryConfigHandler}. This attribute tells the - * processor what is the default phrase slop when no slop is defined in a - * phrase.
- * - */ -public interface FuzzyAttribute extends Attribute { - public void setPrefixLength(int prefixLength); - public int getPrefixLength(); - public void setFuzzyMinSimilarity(float minSimilarity); - public float getFuzzyMinSimilarity(); -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttributeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttributeImpl.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/LowercaseExpandedTermsAttributeImpl.java (working copy) @@ -1,85 +0,0 @@ -package org.apache.lucene.queryParser.standard.config; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.util.Locale; - -import org.apache.lucene.queryParser.core.config.QueryConfigHandler; -import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor; -import org.apache.lucene.util.AttributeImpl; - -/** - * This attribute is used by processor {@link ParametricRangeQueryNodeProcessor} - * and must be defined in the {@link QueryConfigHandler}. This attribute tells - * the processor what is the default {@link Locale} used to parse a date.
- * - * @see org.apache.lucene.queryParser.standard.config.LowercaseExpandedTermsAttribute - */ -public class LowercaseExpandedTermsAttributeImpl extends AttributeImpl - implements LowercaseExpandedTermsAttribute { - - private boolean lowercaseExpandedTerms = true; - - public LowercaseExpandedTermsAttributeImpl() { - lowercaseExpandedTerms = true; // default in 2.4 - } - - public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) { - this.lowercaseExpandedTerms = lowercaseExpandedTerms; - } - - public boolean isLowercaseExpandedTerms() { - return this.lowercaseExpandedTerms; - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public void copyTo(AttributeImpl target) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object other) { - - if (other instanceof LowercaseExpandedTermsAttributeImpl - && ((LowercaseExpandedTermsAttributeImpl) other).lowercaseExpandedTerms == this.lowercaseExpandedTerms) { - - return true; - - } - - return false; - - } - - @Override - public int hashCode() { - return this.lowercaseExpandedTerms ? -1 : Integer.MAX_VALUE; - } - - @Override - public String toString() { - return ""; - } - -} Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/GroupQueryNodeProcessor.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/GroupQueryNodeProcessor.java (revision 1134869) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/GroupQueryNodeProcessor.java (working copy) @@ -31,8 +31,9 @@ import org.apache.lucene.queryParser.core.nodes.ModifierQueryNode.Modifier; import org.apache.lucene.queryParser.core.parser.SyntaxParser; import org.apache.lucene.queryParser.core.processors.QueryNodeProcessor; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute; -import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys; +import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator; import org.apache.lucene.queryParser.standard.nodes.BooleanModifierNode; /** @@ -64,14 +65,14 @@ } public QueryNode process(QueryNode queryTree) throws QueryNodeException { - - if (!getQueryConfigHandler().hasAttribute(DefaultOperatorAttribute.class)) { + Operator defaultOperator = getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR); + + if (defaultOperator == null) { throw new IllegalArgumentException( - "DefaultOperatorAttribute should be set on the QueryConfigHandler"); + "DEFAULT_OPERATOR should be set on the QueryConfigHandler"); } - this.usingAnd = Operator.AND == getQueryConfigHandler() - .getAttribute(DefaultOperatorAttribute.class).getOperator(); + this.usingAnd = StandardQueryConfigHandler.Operator.AND == defaultOperator; if (queryTree instanceof GroupQueryNode) { queryTree = ((GroupQueryNode) queryTree).getChild();