org.apache.lucene.index.IndexOptions Java Examples

The following examples show how to use org.apache.lucene.index.IndexOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleDocumentPercolatorIndex.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(PercolateContext context, ParsedDocument parsedDocument) {
    MemoryIndex memoryIndex = cache.get();
    for (IndexableField field : parsedDocument.rootDoc().getFields()) {
        if (field.fieldType().indexOptions() == IndexOptions.NONE && field.name().equals(UidFieldMapper.NAME)) {
            continue;
        }
        try {
            Analyzer analyzer = context.mapperService().documentMapper(parsedDocument.type()).mappers().indexAnalyzer();
            // TODO: instead of passing null here, we can have a CTL<Map<String,TokenStream>> and pass previous,
            // like the indexer does
            try (TokenStream tokenStream = field.tokenStream(analyzer, null)) {
                if (tokenStream != null) {
                    memoryIndex.addField(field.name(), tokenStream, field.boost());
                }
             }
        } catch (Exception e) {
            throw new ElasticsearchException("Failed to create token stream for [" + field.name() + "]", e);
        }
    }
    context.initialize(new DocEngineSearcher(memoryIndex), parsedDocument);
}
 
Example #2
Source File: TypeFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (indexCreatedBefore2x == false) {
        return builder;
    }
    boolean includeDefaults = params.paramAsBoolean("include_defaults", false);

    // if all are defaults, no sense to write it at all
    boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
    boolean defaultIndexed = Defaults.FIELD_TYPE.indexOptions() != IndexOptions.NONE;
    if (!includeDefaults && fieldType().stored() == Defaults.FIELD_TYPE.stored() && indexed == defaultIndexed) {
        return builder;
    }
    builder.startObject(CONTENT_TYPE);
    if (includeDefaults || fieldType().stored() != Defaults.FIELD_TYPE.stored()) {
        builder.field("store", fieldType().stored());
    }
    if (includeDefaults || indexed != defaultIndexed) {
        builder.field("index", indexTokenizeOptionToString(indexed, fieldType().tokenized()));
    }
    builder.endObject();
    return builder;
}
 
Example #3
Source File: PreAnalyzedField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to create a {@link org.apache.lucene.document.FieldType}
 * based on the {@link SchemaField}
 */
public static org.apache.lucene.document.FieldType createFieldType(SchemaField field) {
  if (!field.indexed() && !field.stored()) {
    log.trace("Ignoring unindexed/unstored field: {}", field);
    return null;
  }
  org.apache.lucene.document.FieldType newType = new org.apache.lucene.document.FieldType();
  newType.setTokenized(field.isTokenized());
  newType.setStored(field.stored());
  newType.setOmitNorms(field.omitNorms());
  IndexOptions options = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
  if (field.omitTermFreqAndPositions()) {
    options = IndexOptions.DOCS;
  } else if (field.omitPositions()) {
    options = IndexOptions.DOCS_AND_FREQS;
  } else if (field.storeOffsetsWithPositions()) {
    options = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
  }
  newType.setIndexOptions(options);
  newType.setStoreTermVectors(field.storeTermVector());
  newType.setStoreTermVectorOffsets(field.storeTermOffsets());
  newType.setStoreTermVectorPositions(field.storeTermPositions());
  newType.setStoreTermVectorPayloads(field.storeTermPayloads());
  return newType;
}
 
Example #4
Source File: TestUnifiedHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private IndexReader indexSomeFields() throws IOException {
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir, indexAnalyzer);
  FieldType ft = new FieldType();
  ft.setIndexOptions(IndexOptions.NONE);
  ft.setTokenized(false);
  ft.setStored(true);
  ft.freeze();

  Field title = new Field("title", "", fieldType);
  Field text = new Field("text", "", fieldType);
  Field category = new Field("category", "", fieldType);

  Document doc = new Document();
  doc.add(title);
  doc.add(text);
  doc.add(category);
  title.setStringValue("This is the title field.");
  text.setStringValue("This is the text field. You can put some text if you want.");
  category.setStringValue("This is the category field.");
  iw.addDocument(doc);

  IndexReader ir = iw.getReader();
  iw.close();
  return ir;
}
 
Example #5
Source File: ReadTokensTask.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public int doLogic() throws Exception {
  List<IndexableField> fields = doc.getFields();
  Analyzer analyzer = getRunData().getAnalyzer();
  int tokenCount = 0;
  for(final IndexableField field : fields) {
    if (field.fieldType().indexOptions() == IndexOptions.NONE ||
        field.fieldType().tokenized() == false) {
      continue;
    }
    
    final TokenStream stream = field.tokenStream(analyzer, null);
    // reset the TokenStream to the first token
    stream.reset();

    TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
    while(stream.incrementToken()) {
      termAtt.getBytesRef();
      tokenCount++;
    }
    stream.end();
    stream.close();
  }
  totalTokenCount += tokenCount;
  return tokenCount;
}
 
Example #6
Source File: Lucene60FieldInfosFormat.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static IndexOptions getIndexOptions(IndexInput input, byte b) throws IOException {
  switch (b) {
  case 0:
    return IndexOptions.NONE;
  case 1:
    return IndexOptions.DOCS;
  case 2:
    return IndexOptions.DOCS_AND_FREQS;
  case 3:
    return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
  case 4:
    return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
  default:
    // BUG
    throw new CorruptIndexException("invalid IndexOptions byte: " + b, input);
  }
}
 
Example #7
Source File: TestBooleanSimilarity.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testSameNormsAsBM25() {
  BooleanSimilarity sim1 = new BooleanSimilarity();
  BM25Similarity sim2 = new BM25Similarity();
  sim2.setDiscountOverlaps(true);
  for (int iter = 0; iter < 100; ++iter) {
    final int length = TestUtil.nextInt(random(), 1, 100);
    final int position = random().nextInt(length);
    final int numOverlaps = random().nextInt(length);
    final int maxTermFrequency = 1;
    final int uniqueTermCount = 1;
    FieldInvertState state = new FieldInvertState(Version.LATEST.major, "foo", IndexOptions.DOCS_AND_FREQS, position, length, numOverlaps, 100, maxTermFrequency, uniqueTermCount);
    assertEquals(
        sim2.computeNorm(state),
        sim1.computeNorm(state),
        0f);
  }
}
 
Example #8
Source File: Field.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create field with Reader value.
 * @param name field name
 * @param reader reader value
 * @param type field type
 * @throws IllegalArgumentException if either the name or type
 *         is null, or if the field's type is stored(), or
 *         if tokenized() is false.
 * @throws NullPointerException if the reader is null
 */
public Field(String name, Reader reader, IndexableFieldType type) {
  if (name == null) {
    throw new IllegalArgumentException("name must not be null");
  }
  if (type == null) {
    throw new IllegalArgumentException("type must not be null");
  }
  if (reader == null) {
    throw new NullPointerException("reader must not be null");
  }
  if (type.stored()) {
    throw new IllegalArgumentException("fields with a Reader value cannot be stored");
  }
  if (type.indexOptions() != IndexOptions.NONE && !type.tokenized()) {
    throw new IllegalArgumentException("non-tokenized fields must use String values");
  }
  
  this.name = name;
  this.fieldsData = reader;
  this.type = type;
}
 
Example #9
Source File: PresearcherTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testNonStringTermHandling() throws IOException {

    FieldType ft = new FieldType();
    ft.setTokenized(true);
    ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS);

    try (Monitor monitor = newMonitor()) {
      monitor.register(new MonitorQuery("1", new TermQuery(new Term("f", NON_STRING_TERM))));

      Document doc = new Document();
      doc.add(new Field("f", new NonStringTokenStream(), ft));
      MatchingQueries<QueryMatch> m = monitor.match(doc, QueryMatch.SIMPLE_MATCHER);
      assertEquals(1, m.getMatchCount());
      assertEquals(1, m.getQueriesRun());
    }

  }
 
Example #10
Source File: StandardnumberMapper.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public StandardnumberMapper build(BuilderContext context) {
    if (fieldType.indexOptions() != IndexOptions.NONE && !fieldType.tokenized()) {
        defaultFieldType.setOmitNorms(true);
        defaultFieldType.setIndexOptions(IndexOptions.DOCS);
        if (!omitNormsSet && Float.compare(fieldType.boost(), 1.0f) == 0) {
            fieldType.setOmitNorms(true);
        }
        if (!indexOptionsSet) {
            fieldType.setIndexOptions(IndexOptions.DOCS);
        }
    }
    setupFieldType(context);
    return new StandardnumberMapper(settingsBuilder.build(),
            name,
            fieldType,
            defaultFieldType,
            context.indexSettings(),
            multiFieldsBuilder.build(this, context),
            copyTo,
            service);
}
 
Example #11
Source File: TestBlockPostingsFormat2.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Document newDocument() {
  Document doc = new Document();
  for (IndexOptions option : IndexOptions.values()) {
    if (option == IndexOptions.NONE) {
      continue;
    }
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    // turn on tvs for a cross-check, since we rely upon checkindex in this test (for now)
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorOffsets(true);
    ft.setStoreTermVectorPositions(true);
    ft.setStoreTermVectorPayloads(true);
    ft.setIndexOptions(option);
    doc.add(new Field(option.toString(), "", ft));
  }
  return doc;
}
 
Example #12
Source File: LegacyFieldType.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Prints a Field for human consumption. */
@Override
public String toString() {
  StringBuilder result = new StringBuilder();
  result.append(super.toString());
  if (indexOptions() != IndexOptions.NONE) {
    if (result.length() > 0) {
      result.append(",");
    }
    if (numericType != null) {
      result.append(",numericType=");
      result.append(numericType);
      result.append(",numericPrecisionStep=");
      result.append(numericPrecisionStep);
    }
  }
  return result.toString();
}
 
Example #13
Source File: GeoPointFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void parse(ParseContext context, GeoPoint point, String geoHash) throws IOException {
    if (ignoreMalformed.value() == false) {
        if (point.lat() > 90.0 || point.lat() < -90.0) {
            throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
        }
        if (point.lon() > 180.0 || point.lon() < -180) {
            throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
        }
    } else {
        // LUCENE WATCH: This will be folded back into Lucene's GeoPointField
        GeoUtils.normalizePoint(point);
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        context.doc().add(new GeoPointField(fieldType().names().indexName(), point.lon(), point.lat(), fieldType() ));
    }
    super.parse(context, point, geoHash);
}
 
Example #14
Source File: StringFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    ValueAndBoost valueAndBoost = parseCreateFieldForString(context, fieldType().nullValueAsString(), fieldType().boost());
    if (valueAndBoost.value() == null) {
        return;
    }
    if (ignoreAbove > 0 && valueAndBoost.value().length() > ignoreAbove) {
        return;
    }
    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().names().fullName(), valueAndBoost.value(), valueAndBoost.boost());
    }

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().names().indexName(), valueAndBoost.value(), fieldType());
        field.setBoost(valueAndBoost.boost());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().names().indexName(), new BytesRef(valueAndBoost.value())));
    }
}
 
Example #15
Source File: Lucene50FieldInfosFormat.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static IndexOptions getIndexOptions(IndexInput input, byte b) throws IOException {
  switch (b) {
  case 0:
    return IndexOptions.NONE;
  case 1:
    return IndexOptions.DOCS;
  case 2:
    return IndexOptions.DOCS_AND_FREQS;
  case 3:
    return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
  case 4:
    return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
  default:
    // BUG
    throw new CorruptIndexException("invalid IndexOptions byte: " + b, input);
  }
}
 
Example #16
Source File: IdFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) {
        BytesRef id = Uid.encodeId(context.sourceToParse().id());
        fields.add(new Field(NAME, id, fieldType));
    }
}
 
Example #17
Source File: FSTTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public FSTTermsReader(SegmentReadState state, PostingsReaderBase postingsReader) throws IOException {
  final String termsFileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, FSTTermsWriter.TERMS_EXTENSION);

  this.postingsReader = postingsReader;
  final IndexInput in = state.directory.openInput(termsFileName, state.context);

  boolean success = false;
  try {
    CodecUtil.checkIndexHeader(in, FSTTermsWriter.TERMS_CODEC_NAME,
                                     FSTTermsWriter.TERMS_VERSION_START,
                                     FSTTermsWriter.TERMS_VERSION_CURRENT,
                                     state.segmentInfo.getId(), state.segmentSuffix);
    CodecUtil.checksumEntireFile(in);
    this.postingsReader.init(in, state);
    seekDir(in);

    final FieldInfos fieldInfos = state.fieldInfos;
    final int numFields = in.readVInt();
    for (int i = 0; i < numFields; i++) {
      int fieldNumber = in.readVInt();
      FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
      long numTerms = in.readVLong();
      long sumTotalTermFreq = in.readVLong();
      // if frequencies are omitted, sumTotalTermFreq=sumDocFreq and we only write one value
      long sumDocFreq = fieldInfo.getIndexOptions() == IndexOptions.DOCS ? sumTotalTermFreq : in.readVLong();
      int docCount = in.readVInt();
      TermsReader current = new TermsReader(fieldInfo, in, numTerms, sumTotalTermFreq, sumDocFreq, docCount);
      TermsReader previous = fields.put(fieldInfo.name, current);
      checkFieldSummary(state.segmentInfo, in, current, previous);
    }
    success = true;
  } finally {
    if (success) {
      IOUtils.close(in);
    } else {
      IOUtils.closeWhileHandlingException(in);
    }
  }
}
 
Example #18
Source File: SimilarityBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Encodes the document length in the same way as {@link BM25Similarity}. */
@Override
public final long computeNorm(FieldInvertState state) {
  final int numTerms;
  if (state.getIndexOptions() == IndexOptions.DOCS && state.getIndexCreatedVersionMajor() >= 8) {
    numTerms = state.getUniqueTermCount();
  } else if (discountOverlaps) {
    numTerms = state.getLength() - state.getNumOverlap();
  } else {
    numTerms = state.getLength();
  }
  return SmallFloat.intToByte4(numTerms);
}
 
Example #19
Source File: Lucene50PostingsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void decodeTerm(DataInput in, FieldInfo fieldInfo, BlockTermState _termState, boolean absolute)
  throws IOException {
  final IntBlockTermState termState = (IntBlockTermState) _termState;
  final boolean fieldHasPositions = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  final boolean fieldHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  final boolean fieldHasPayloads = fieldInfo.hasPayloads();

  if (absolute) {
    termState.docStartFP = 0;
    termState.posStartFP = 0;
    termState.payStartFP = 0;
  }

  termState.docStartFP += in.readVLong();
  if (fieldHasPositions) {
    termState.posStartFP += in.readVLong();
    if (fieldHasOffsets || fieldHasPayloads) {
      termState.payStartFP += in.readVLong();
    }
  }
  if (termState.docFreq == 1) {
    termState.singletonDocID = in.readVInt();
  } else {
    termState.singletonDocID = -1;
  }
  if (fieldHasPositions) {
    if (termState.totalTermFreq > BLOCK_SIZE) {
      termState.lastPosBlockOffset = in.readVLong();
    } else {
      termState.lastPosBlockOffset = -1;
    }
  }
  if (termState.docFreq > BLOCK_SIZE) {
    termState.skipOffset = in.readVLong();
  } else {
    termState.skipOffset = -1;
  }
}
 
Example #20
Source File: BBoxStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Creates this strategy.
 * {@code fieldType} is used to customize the indexing options of the 4 number fields, and to a lesser degree the XDL
 * field too. Search requires pointValues (or legacy numerics), and relevancy requires docValues. If these features
 * aren't needed then disable them.
 */
public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix, FieldType fieldType) {
  super(ctx, fieldNamePrefix);
  field_bbox = fieldNamePrefix;
  field_minX = fieldNamePrefix + SUFFIX_MINX;
  field_maxX = fieldNamePrefix + SUFFIX_MAXX;
  field_minY = fieldNamePrefix + SUFFIX_MINY;
  field_maxY = fieldNamePrefix + SUFFIX_MAXY;
  field_xdl = fieldNamePrefix + SUFFIX_XDL;

  fieldType.freeze();
  this.optionsFieldType = fieldType;

  int numQuads = 0;
  if ((this.hasStored = fieldType.stored())) {
    numQuads++;
  }
  if ((this.hasDocVals = fieldType.docValuesType() != DocValuesType.NONE)) {
    numQuads++;
  }
  if ((this.hasPointVals = fieldType.pointDimensionCount() > 0)) {
    numQuads++;
  }

  if (hasPointVals) { // if we have an index...
    xdlFieldType = new FieldType(StringField.TYPE_NOT_STORED);
    xdlFieldType.setIndexOptions(IndexOptions.DOCS);
    xdlFieldType.freeze();
  } else {
    xdlFieldType = null;
  }

  this.fieldsLen = numQuads * 4 + (xdlFieldType != null ? 1 : 0);
}
 
Example #21
Source File: IntegerFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void addIntegerFields(ParseContext context, List<Field> fields, int value, float boost) {
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomIntegerNumericField field = new CustomIntegerNumericField(value, fieldType());
        field.setBoost(boost);
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}
 
Example #22
Source File: RoutingFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    String routing = context.sourceToParse().routing();
    if (routing != null) {
        if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
            fields.add(new Field(fieldType().name(), routing, fieldType()));
            createFieldNamesField(context, fields);
        }
    }
}
 
Example #23
Source File: AnalyzingInfixSuggester.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Subclass can override this method to change the field type of the text field
 * e.g. to change the index options
 */
protected FieldType getTextFieldType(){
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setIndexOptions(IndexOptions.DOCS);
  ft.setOmitNorms(true);

  return ft;
}
 
Example #24
Source File: GeoPointFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void parse(ParseContext context, GeoPoint point) throws IOException {

        if (ignoreMalformed.value() == false) {
            if (point.lat() > 90.0 || point.lat() < -90.0) {
                throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name());
            }
            if (point.lon() > 180.0 || point.lon() < -180) {
                throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name());
            }
        } else {
            GeoUtils.normalizePoint(point);
        }
        if (fieldType().indexOptions() != IndexOptions.NONE) {
            context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon()));
        }
        if (fieldType().stored()) {
            context.doc().add(new StoredField(fieldType().name(), point.toString()));
        }
        if (fieldType.hasDocValues()) {
            context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon()));
        } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) {
            List<IndexableField> fields = new ArrayList<>(1);
            createFieldNamesField(context, fields);
            for (IndexableField field : fields) {
                context.doc().add(field);
            }
        }
        // if the mapping contains multifields then use the geohash string
        if (multiFields.iterator().hasNext()) {
            multiFields.parse(this, context.createExternalValueContext(point.geohash()));
        }
    }
 
Example #25
Source File: FieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void setupFieldType(BuilderContext context) {
    fieldType.setName(buildFullName(context));
    if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) {
        fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
        fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER);
    }
    boolean defaultDocValues = defaultDocValues(context.indexCreatedVersion());
    defaultFieldType.setHasDocValues(defaultDocValues);
    if (docValuesSet == false) {
        fieldType.setHasDocValues(defaultDocValues);
    }
}
 
Example #26
Source File: LukeRequestHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * @return a string representing a IndexableField's flags.  
 */
private static String getFieldFlags( IndexableField f )
{
  IndexOptions opts = (f == null) ? null : f.fieldType().indexOptions();

  StringBuilder flags = new StringBuilder();

  flags.append( (f != null && f.fieldType().indexOptions() != IndexOptions.NONE)                     ? FieldFlag.INDEXED.getAbbreviation() : '-' );
  flags.append( (f != null && f.fieldType().tokenized())                   ? FieldFlag.TOKENIZED.getAbbreviation() : '-' );
  flags.append( (f != null && f.fieldType().stored())                      ? FieldFlag.STORED.getAbbreviation() : '-' );
  flags.append( (f != null && f.fieldType().docValuesType() != DocValuesType.NONE)        ? FieldFlag.DOC_VALUES.getAbbreviation() : "-" );
  flags.append( (false)                                          ? FieldFlag.UNINVERTIBLE.getAbbreviation() : '-' ); // SchemaField Specific
  flags.append( (false)                                          ? FieldFlag.MULTI_VALUED.getAbbreviation() : '-' ); // SchemaField Specific
  flags.append( (f != null && f.fieldType().storeTermVectors())            ? FieldFlag.TERM_VECTOR_STORED.getAbbreviation() : '-' );
  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().storeTermVectorPayloads())   ? FieldFlag.TERM_VECTOR_PAYLOADS.getAbbreviation() : '-' );
  flags.append( (f != null && f.fieldType().omitNorms())                  ? FieldFlag.OMIT_NORMS.getAbbreviation() : '-' );

  flags.append( (f != null && DOCS == opts ) ?
      FieldFlag.OMIT_TF.getAbbreviation() : '-' );

  flags.append((f != null && DOCS_AND_FREQS == opts) ?
      FieldFlag.OMIT_POSITIONS.getAbbreviation() : '-');
  
  flags.append((f != null && DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS == opts) ?
      FieldFlag.STORE_OFFSETS_WITH_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
  flags.append( (false)                                          ? FieldFlag.SORT_MISSING_LAST.getAbbreviation() : '-' ); // SchemaField Specific
  return flags.toString();
}
 
Example #27
Source File: FieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {

        builder.field("type", contentType());

        if (includeDefaults || fieldType().boost() != 1.0f) {
            builder.field("boost", fieldType().boost());
        }

        boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
        boolean defaultIndexed = defaultFieldType.indexOptions() != IndexOptions.NONE;
        if (includeDefaults || indexed != defaultIndexed) {
            builder.field("index", indexed);
        }
        if (position != null) {
            builder.field("position", position);
        }
        if (defaultExpression != null) {
            builder.field("default_expr", defaultExpression);
        }
        if (includeDefaults || fieldType().stored() != defaultFieldType.stored()) {
            builder.field("store", fieldType().stored());
        }
        doXContentDocValues(builder, includeDefaults);
        if (includeDefaults || fieldType().storeTermVectors() != defaultFieldType.storeTermVectors()) {
            builder.field("term_vector", termVectorOptionsToString(fieldType()));
        }
        if (includeDefaults || fieldType().omitNorms() != defaultFieldType.omitNorms()) {
            builder.field("norms", fieldType().omitNorms() == false);
        }
        if (indexed && (includeDefaults || fieldType().indexOptions() != defaultFieldType.indexOptions())) {
            builder.field("index_options", indexOptionToString(fieldType().indexOptions()));
        }
        if (includeDefaults || fieldType().eagerGlobalOrdinals() != defaultFieldType.eagerGlobalOrdinals()) {
            builder.field("eager_global_ordinals", fieldType().eagerGlobalOrdinals());
        }

        multiFields.toXContent(builder, params);
        copyTo.toXContent(builder, params);
    }
 
Example #28
Source File: PerFieldMergeState.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
FilterFieldInfos(FieldInfos src, Collection<String> filterFields) {
  // Copy all the input FieldInfo objects since the field numbering must be kept consistent
  super(toArray(src));

  boolean hasVectors = false;
  boolean hasProx = false;
  boolean hasPayloads = false;
  boolean hasOffsets = false;
  boolean hasFreq = false;
  boolean hasNorms = false;
  boolean hasDocValues = false;
  boolean hasPointValues = false;

  this.filteredNames = new HashSet<>(filterFields);
  this.filtered = new ArrayList<>(filterFields.size());
  for (FieldInfo fi : src) {
    if (this.filteredNames.contains(fi.name)) {
      this.filtered.add(fi);
      hasVectors |= fi.hasVectors();
      hasProx |= fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
      hasFreq |= fi.getIndexOptions() != IndexOptions.DOCS;
      hasOffsets |= fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
      hasNorms |= fi.hasNorms();
      hasDocValues |= fi.getDocValuesType() != DocValuesType.NONE;
      hasPayloads |= fi.hasPayloads();
      hasPointValues |= (fi.getPointDimensionCount() != 0);
    }
  }

  this.filteredHasVectors = hasVectors;
  this.filteredHasProx = hasProx;
  this.filteredHasPayloads = hasPayloads;
  this.filteredHasOffsets = hasOffsets;
  this.filteredHasFreq = hasFreq;
  this.filteredHasNorms = hasNorms;
  this.filteredHasDocValues = hasDocValues;
  this.filteredHasPointValues = hasPointValues;
}
 
Example #29
Source File: IntegerFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) {
    if (fieldType().indexOptions() != IndexOptions.NONE) {
        return getCachedStream().setIntValue(number);
    }
    return null;
}
 
Example #30
Source File: TypeParsers.java    From crate with Apache License 2.0 5 votes vote down vote up
private static IndexOptions nodeIndexOptionValue(final Object propNode) {
    final String value = propNode.toString();
    if (INDEX_OPTIONS_OFFSETS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
    } else if (INDEX_OPTIONS_POSITIONS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
    } else if (INDEX_OPTIONS_FREQS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS_AND_FREQS;
    } else if (INDEX_OPTIONS_DOCS.equalsIgnoreCase(value)) {
        return IndexOptions.DOCS;
    } else {
        throw new ElasticsearchParseException("failed to parse index option [{}]", value);
    }
}