Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java (revision 1057986) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/SpansQueryConfigHandler.java (working copy) @@ -33,7 +33,7 @@ } @Override - public FieldConfig getFieldConfig(CharSequence fieldName) { + public FieldConfig getFieldConfig(String fieldName) { // there is no field configuration, always return null return null; Index: contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java =================================================================== --- contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java (revision 1057986) +++ contrib/queryparser/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java (working copy) @@ -27,6 +27,7 @@ import org.apache.lucene.analysis.standard.StandardTokenizer; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.Version; /** * @version $Revision$, $Date$ @@ -112,7 +113,7 @@ @Override public TokenStream tokenStream(String fieldName, Reader reader) { TokenStream result = new StandardTokenizer(LuceneTestCase.TEST_VERSION_CURRENT, reader); - result = new StandardFilter(result); + result = new StandardFilter(Version.LUCENE_31, result); result = new ASCIIFoldingFilter(result); result = new LowerCaseFilter(LuceneTestCase.TEST_VERSION_CURRENT, result); return result; 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java (working copy) @@ -98,9 +98,16 @@ } - FieldConfig fieldConfig = getQueryConfigHandler().getFieldConfig( - parametricRangeNode.getField()); + CharSequence field = parametricRangeNode.getField(); + String fieldStr = null; + if (field != null) { + fieldStr = field.toString(); + } + + FieldConfig fieldConfig = getQueryConfigHandler() + .getFieldConfig(fieldStr); + if (fieldConfig != null) { if (fieldConfig.hasAttribute(DateResolutionAttribute.class)) { 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/BoostQueryNodeProcessor.java (working copy) @@ -26,6 +26,7 @@ import org.apache.lucene.queryParser.core.nodes.FieldableNode; 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; /** @@ -49,7 +50,8 @@ QueryConfigHandler config = getQueryConfigHandler(); if (config != null) { - FieldConfig fieldConfig = config.getFieldConfig(fieldNode.getField()); + CharSequence field = fieldNode.getField(); + FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field)); if (fieldConfig != null && fieldConfig.hasAttribute(BoostAttribute.class)) { BoostAttribute boostAttr = fieldConfig.getAttribute(BoostAttribute.class); 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/MultiTermRewriteMethodAttribute.java (working copy) @@ -32,7 +32,7 @@ */ public interface MultiTermRewriteMethodAttribute extends Attribute { - public static final CharSequence TAG_ID = "MultiTermRewriteMethodAttribute"; + public static final String TAG_ID = "MultiTermRewriteMethodAttribute"; public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldDateResolutionFCListener.java (working copy) @@ -53,7 +53,7 @@ FieldDateResolutionMapAttribute dateResMapAttr = this.config .addAttribute(FieldDateResolutionMapAttribute.class); dateRes = dateResMapAttr.getFieldDateResolutionMap().get( - fieldConfig.getFieldName().toString()); + fieldConfig.getField()); } if (dateRes == null) { 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapFCListener.java (working copy) @@ -47,7 +47,7 @@ FieldBoostMapAttribute fieldBoostMapAttr = this.config.getAttribute(FieldBoostMapAttribute.class); BoostAttribute boostAttr = fieldConfig.addAttribute(BoostAttribute.class); - Float boost = fieldBoostMapAttr.getFieldBoostMap().get(fieldConfig.getFieldName()); + Float boost = fieldBoostMapAttr.getFieldBoostMap().get(fieldConfig.getField()); if (boost != null) { boostAttr.setBoost(boost.floatValue()); 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/FieldConfig.java (working copy) @@ -17,6 +17,7 @@ * limitations under the License. */ +import org.apache.lucene.queryParser.core.util.StringUtils; import org.apache.lucene.util.AttributeSource; /** @@ -28,18 +29,29 @@ */ public class FieldConfig extends AttributeSource { - private CharSequence fieldName; + private String fieldName; /** * Constructs a {@link FieldConfig} * - * @param fieldName - * the field name, it cannot be null - * @throws IllegalArgumentException - * if the field name is null + * @param fieldName the field name, it cannot be null + * @throws IllegalArgumentException if the field name is null + * + * @deprecated use {@link #FieldConfig(String)} instead */ + @Deprecated public FieldConfig(CharSequence fieldName) { + this(StringUtils.toString(fieldName)); + } + /** + * Constructs a {@link FieldConfig} + * + * @param fieldName the field name, it cannot be null + * @throws IllegalArgumentException if the field name is null + */ + public FieldConfig(String fieldName) { + if (fieldName == null) { throw new IllegalArgumentException("field name should not be null!"); } @@ -52,14 +64,27 @@ * Returns the field name this configuration represents. * * @return the field name + * + * @deprecated use {@link #getField()} instead */ + @Deprecated public CharSequence getFieldName() { return this.fieldName; } - + + /** + * Returns the field name this configuration represents. + * + * @return the field name + */ + public String getField() { + return this.fieldName; + } + @Override - public String toString(){ - return ""; + 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 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/config/QueryConfigHandler.java (working copy) @@ -20,6 +20,7 @@ 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; @@ -59,8 +60,29 @@ * @return a {@link FieldConfig} object containing the field name * configuration or null, if the implemented * {@link QueryConfigHandler} has no configuration for that field + * + * @deprecated use {@link #getFieldConfig(String)} instead + * */ + @Deprecated public FieldConfig getFieldConfig(CharSequence fieldName) { + return getFieldConfig(StringUtils.toString(fieldName)); + } + + /** + * 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(fieldName); for (FieldConfigListener listener : this.listeners) { Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNode.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNode.java (revision 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNode.java (working copy) @@ -43,12 +43,27 @@ public boolean isLeaf(); /** verify if a node contains a tag */ + public boolean containsTag(String tagName); + + /** verify if a node contains a tag + * @deprecated use {@link #containsTag(String)} instead + */ + @Deprecated public boolean containsTag(CharSequence tagName); /** * @param tagName * @return of stored on under that tag name */ + public Object getTag(String tagName); + + /** + * @param tagName + * @return of stored on under that tag name + * + * @deprecated use {@link #getTag(String)} instead + */ + @Deprecated public Object getTag(CharSequence tagName); public QueryNode getParent(); @@ -81,6 +96,19 @@ * @param tagName * @param value */ + public void setTag(String tagName, Object value); + + /** + * Associate the specified value with the specified tagName. If the tagName + * already exists, the old value is replaced. The tagName and value cannot be + * null. tagName will be converted to lowercase. + * + * @param tagName + * @param value + * + * @deprecated use {@link #setTag(String, Object)} instead + */ + @Deprecated public void setTag(CharSequence tagName, Object value); /** @@ -88,8 +116,32 @@ * * @param tagName */ + public void unsetTag(String tagName); + + /** + * Unset a tag. tagName will be converted to lowercase. + * + * @param tagName + * + * @deprecated use {@link #unsetTag(String)} instead + */ + @Deprecated public void unsetTag(CharSequence tagName); + /** + * Returns a map containing all tags attached to this query node. + * + * @return a map containing all tags attached to this query node + * + * @deprecated use {@link #getTagMap()} + */ public Map getTags(); + + /** + * Returns a map containing all tags attached to this query node. + * + * @return a map containing all tags attached to this query node + */ + public Map getTagMap(); } Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNodeImpl.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNodeImpl.java (revision 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/QueryNodeImpl.java (working copy) @@ -18,6 +18,7 @@ */ import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -25,6 +26,7 @@ import org.apache.lucene.messages.NLS; import org.apache.lucene.queryParser.core.messages.QueryParserMessages; +import org.apache.lucene.queryParser.core.util.StringUtils; /** * A {@link QueryNodeImpl} is the default implementation of the interface @@ -40,7 +42,7 @@ private boolean isLeaf = true; - private Hashtable tags = new Hashtable(); + private Hashtable tags = new Hashtable(); private List clauses = null; @@ -117,7 +119,7 @@ clone.isLeaf = this.isLeaf; // Reset all tags - clone.tags = new Hashtable(); + clone.tags = new Hashtable(); // copy children if (this.clauses != null) { @@ -151,22 +153,56 @@ return this.clauses; } + /** + * @deprecated use {@link #setTag(String, Object)} instead + */ + @Deprecated public void setTag(CharSequence tagName, Object value) { this.tags.put(tagName.toString().toLowerCase(), value); } + public void setTag(String tagName, Object value) { + this.tags.put(tagName.toLowerCase(), value); + } + + public void unsetTag(String tagName) { + this.tags.remove(tagName.toLowerCase()); + } + + /** + * @deprecated use {@link #unsetTag(String)} + */ + @Deprecated public void unsetTag(CharSequence tagName) { this.tags.remove(tagName.toString().toLowerCase()); } + /** + * verify if a node contains a tag + * + * @deprecated use {@link #containsTag(String)} instead + */ public boolean containsTag(CharSequence tagName) { return this.tags.containsKey(tagName.toString().toLowerCase()); } + /** verify if a node contains a tag */ + public boolean containsTag(String tagName) { + return this.tags.containsKey(tagName); + } + + /** + * @deprecated use {@link #getTag(String)} instead + */ + @Deprecated public Object getTag(CharSequence tagName) { return this.tags.get(tagName.toString().toLowerCase()); } + public Object getTag(String tagName) { + return this.tags.get(tagName.toString().toLowerCase()); + } + private QueryNode parent = null; private void setParent(QueryNode parent) { @@ -189,16 +225,20 @@ /** * This method is use toQueryString to detect if fld is the default field * - * @param fld - * - field name + * @param fld - field name * @return true if fld is the default field */ + // TODO: remove this method, it's commonly used by {@link + // #toQueryString(org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax)} + // to figure out what is the default field, however, {@link + // #toQueryString(org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax)} + // should receive the default field value directly by parameter protected boolean isDefaultField(CharSequence fld) { if (this.toQueryStringIgnoreFields) return true; if (fld == null) return true; - if (QueryNodeImpl.PLAINTEXT_FIELD_NAME.equals(fld.toString())) + if (QueryNodeImpl.PLAINTEXT_FIELD_NAME.equals(StringUtils.toString(fld))) return true; return false; } @@ -216,12 +256,35 @@ } /** - * @see org.apache.lucene.queryParser.core.nodes.QueryNode#getTag(CharSequence) + * @see org.apache.lucene.queryParser.core.nodes.QueryNode#getTag(String) * @return a Map with all tags for this QueryNode + * + * @deprecated use {@link #getTagMap()} instead */ @SuppressWarnings( { "unchecked" }) + @Deprecated public Map getTags() { - return (Map) this.tags.clone(); + Map map = (Map) this.tags.clone(); + Map charSeqMap = new HashMap(); + + for (String key : map.keySet()) { + Object obj = map.get(key); + charSeqMap.put(key, obj); + + } + + return charSeqMap; + } + /** + * Returns a map containing all tags attached to this query node. + * + * @return a map containing all tags attached to this query node + */ + @SuppressWarnings("unchecked") + public Map getTagMap() { + return (Map) this.tags.clone(); + } + } // end class QueryNodeImpl Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java (revision 1057986) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java (working copy) @@ -25,6 +25,7 @@ import org.apache.lucene.queryParser.core.messages.QueryParserMessages; import org.apache.lucene.queryParser.core.nodes.FieldableNode; import org.apache.lucene.queryParser.core.nodes.QueryNode; +import org.apache.lucene.queryParser.core.util.StringUtils; import org.apache.lucene.queryParser.standard.parser.EscapeQuerySyntaxImpl; /** @@ -76,7 +77,7 @@ * @param fieldName the field name * @param builder the builder to be associated */ - public void setBuilder(CharSequence fieldName, QueryBuilder builder) { + public void setBuilder(String fieldName, QueryBuilder builder) { if (this.fieldNameBuilders == null) { this.fieldNameBuilders = new HashMap(); @@ -84,7 +85,19 @@ this.fieldNameBuilders.put(fieldName.toString(), builder); + } + /** + * Associates a field name with a builder. + * + * @param fieldName the field name + * @param builder the builder to be associated + * + * @deprecated use {@link #setBuilder(String, QueryBuilder)} instead + */ + @Deprecated + public void setBuilder(CharSequence fieldName, QueryBuilder builder) { + setBuilder(StringUtils.toString(fieldName), builder); } /** @@ -132,14 +145,8 @@ QueryBuilder builder = null; if (this.fieldNameBuilders != null && node instanceof FieldableNode) { - CharSequence field = ((FieldableNode) node).getField(); - - if (field != null) { - field = field.toString(); - } - - builder = this.fieldNameBuilders.get(field); - + builder = this.fieldNameBuilders.get(StringUtils + .toString(((FieldableNode) node).getField())); } if (builder == null && this.queryNodeBuilders != null) { Index: contrib/CHANGES.txt =================================================================== --- contrib/CHANGES.txt (revision 1057986) +++ contrib/CHANGES.txt (working copy) @@ -105,6 +105,10 @@ API Changes +* LUCENE-2867: Some contrib queryparser methods that receives CharSequence as + identifier, such as QueryNode#unsetTag(CharSequence), were deprecated and + will be removed on version 4. (Adriano Crestani) + * LUCENE-2147: Spatial GeoHashUtils now always decode GeoHash strings with full precision. GeoHash#decode_exactly(String) was merged into GeoHash#decode(String). (Chris Male, Simon Willnauer)