diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 008ea321916..5cbdc3bdd54 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -426,6 +426,9 @@ Bug Fixes * SOLR-2955: Fixed IllegalStateException when querying with group.sort=score desc in sharded environment. (Steffen Elberg Godskesen, Martijn van Groningen) + +* SOLR-2956: Fixed inconsistencies in the flags (and flag key) reported by + the LukeRequestHandler (hossman) Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index 841dbf26865..0342243850e 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -35,6 +35,9 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.Fields; import org.apache.lucene.index.FieldsEnum; +import org.apache.lucene.index.FieldInfo.IndexOptions; +import static org.apache.lucene.index.FieldInfo.IndexOptions.DOCS_ONLY; +import static org.apache.lucene.index.FieldInfo.IndexOptions.DOCS_AND_FREQS; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; @@ -168,7 +171,10 @@ public class LukeRequestHandler extends RequestHandlerBase */ private static String getFieldFlags( IndexableField f ) { + IndexOptions opts = (f == null) ? null : f.fieldType().indexOptions(); + StringBuilder flags = new StringBuilder(); + flags.append( (f != null && f.fieldType().indexed()) ? FieldFlag.INDEXED.getAbbreviation() : '-' ); flags.append( (f != null && f.fieldType().tokenized()) ? FieldFlag.TOKENIZED.getAbbreviation() : '-' ); flags.append( (f != null && f.fieldType().stored()) ? FieldFlag.STORED.getAbbreviation() : '-' ); @@ -177,6 +183,13 @@ public class LukeRequestHandler extends RequestHandlerBase flags.append( (f != null && f.fieldType().storeTermVectorOffsets()) ? FieldFlag.TERM_VECTOR_OFFSET.getAbbreviation() : '-' ); flags.append( (f != null && f.fieldType().storeTermVectorPositions()) ? FieldFlag.TERM_VECTOR_POSITION.getAbbreviation() : '-' ); flags.append( (f != null && f.fieldType().omitNorms()) ? FieldFlag.OMIT_NORMS.getAbbreviation() : '-' ); + + flags.append( (f != null && DOCS_ONLY == opts ) ? + FieldFlag.OMIT_TF.getAbbreviation() : '-' ); + + flags.append( (f != null && DOCS_AND_FREQS == opts ) ? + FieldFlag.OMIT_POSITIONS.getAbbreviation() : '-' ); + flags.append( (f != null && f.getClass().getSimpleName().equals("LazyField")) ? FieldFlag.LAZY.getAbbreviation() : '-' ); flags.append( (f != null && f.binaryValue()!=null) ? FieldFlag.BINARY.getAbbreviation() : '-' ); flags.append( (false) ? FieldFlag.SORT_MISSING_FIRST.getAbbreviation() : '-' ); // SchemaField Specific @@ -217,21 +230,11 @@ public class LukeRequestHandler extends RequestHandlerBase /** * @return a key to what each character means */ - public static SimpleOrderedMap getFieldFlagsKey() - { + public static SimpleOrderedMap getFieldFlagsKey() { SimpleOrderedMap key = new SimpleOrderedMap(); - key.add(String.valueOf(FieldFlag.INDEXED.getAbbreviation()), FieldFlag.INDEXED.getDisplay() ); - key.add(String.valueOf(FieldFlag.TOKENIZED.getAbbreviation()), FieldFlag.TOKENIZED.getDisplay() ); - key.add( String.valueOf(FieldFlag.STORED.getAbbreviation()), FieldFlag.STORED.getDisplay() ); - key.add( String.valueOf(FieldFlag.MULTI_VALUED.getAbbreviation()), FieldFlag.MULTI_VALUED.getDisplay() ); - key.add( String.valueOf(FieldFlag.TERM_VECTOR_STORED.getAbbreviation()), FieldFlag.TERM_VECTOR_STORED.getDisplay() ); - key.add( String.valueOf(FieldFlag.TERM_VECTOR_OFFSET.getAbbreviation()), FieldFlag.TERM_VECTOR_OFFSET.getDisplay() ); - key.add( String.valueOf(FieldFlag.TERM_VECTOR_POSITION.getAbbreviation()), FieldFlag.TERM_VECTOR_POSITION.getDisplay() ); - key.add( String.valueOf(FieldFlag.OMIT_NORMS.getAbbreviation()), FieldFlag.OMIT_NORMS.getDisplay() ); - key.add( String.valueOf(FieldFlag.LAZY.getAbbreviation()), FieldFlag.LAZY.getDisplay() ); - key.add( String.valueOf(FieldFlag.BINARY.getAbbreviation()), FieldFlag.BINARY.getDisplay() ); - key.add( String.valueOf(FieldFlag.SORT_MISSING_FIRST.getAbbreviation()), FieldFlag.SORT_MISSING_FIRST.getDisplay() ); - key.add( String.valueOf(FieldFlag.SORT_MISSING_LAST.getAbbreviation()), FieldFlag.SORT_MISSING_LAST.getDisplay() ); + for (FieldFlag f : FieldFlag.values()) { + key.add(String.valueOf(f.getAbbreviation()), f.getDisplay() ); + } return key; } diff --git a/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java index 39668cec13d..a1274e73379 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java @@ -17,8 +17,12 @@ package org.apache.solr.handler.admin; +import org.apache.solr.common.luke.FieldFlag; import org.apache.solr.util.AbstractSolrTestCase; +import java.util.EnumSet; +import java.util.Arrays; + /** * :TODO: currently only tests some of the utilities in the LukeRequestHandler */ @@ -93,7 +97,40 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase { // test that Luke can handle all of the field types assertQ(req("qt","/admin/luke", "id","SOLR1000")); + + final int numFlags = EnumSet.allOf(FieldFlag.class).size(); + + assertQ("Not all flags ("+numFlags+") mentioned in info->key", + req("qt","/admin/luke"), + numFlags+"=count(//lst[@name='info']/lst[@name='key']/str)"); + + // code should be the same for all fields, but just in case do several + for (String f : Arrays.asList("solr_t","solr_s","solr_ti", + "solr_td","solr_pl","solr_dt","solr_b", + "solr_sS","solr_sI")) { + + final String xp = getFieldXPathPrefix(f); + assertQ("Not as many schema flags as expected ("+numFlags+") for " + f, + req("qt","/admin/luke", "fl", f), + numFlags+"=string-length("+xp+"[@name='schema'])"); + + } + + // diff loop for checking 'index' flags, + // only valid for fields that are indexed & stored + for (String f : Arrays.asList("solr_t","solr_s","solr_ti", + "solr_td","solr_pl","solr_dt","solr_b")) { + + final String xp = getFieldXPathPrefix(f); + assertQ("Not as many index flags as expected ("+numFlags+") for " + f, + req("qt","/admin/luke", "fl", f), + numFlags+"=string-length("+xp+"[@name='index'])"); + } + } - + private static String getFieldXPathPrefix(String field) { + return "//lst[@name='fields']/lst[@name='"+field+"']/str"; + } + } diff --git a/solr/solrj/src/java/org/apache/solr/common/luke/FieldFlag.java b/solr/solrj/src/java/org/apache/solr/common/luke/FieldFlag.java index 5380016068a..a63281e8afa 100644 --- a/solr/solrj/src/java/org/apache/solr/common/luke/FieldFlag.java +++ b/solr/solrj/src/java/org/apache/solr/common/luke/FieldFlag.java @@ -30,7 +30,7 @@ public enum FieldFlag { TERM_VECTOR_OFFSET('o', "Store Offset With TermVector"), TERM_VECTOR_POSITION('p', "Store Position With TermVector"), OMIT_NORMS('O', "Omit Norms"), - OMIT_TF('F', "Omit Tf"), + OMIT_TF('F', "Omit Term Frequencies & Positions"), OMIT_POSITIONS('P', "Omit Positions"), LAZY('L', "Lazy"), BINARY('B', "Binary"),