Java Code Examples for org.apache.lucene.index.IndexableFieldType

The following examples show how to use org.apache.lucene.index.IndexableFieldType. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: FieldType.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a new mutable FieldType with all of the properties from <code>ref</code>
 */
public FieldType(IndexableFieldType ref) {
  this.stored = ref.stored();
  this.tokenized = ref.tokenized();
  this.storeTermVectors = ref.storeTermVectors();
  this.storeTermVectorOffsets = ref.storeTermVectorOffsets();
  this.storeTermVectorPositions = ref.storeTermVectorPositions();
  this.storeTermVectorPayloads = ref.storeTermVectorPayloads();
  this.omitNorms = ref.omitNorms();
  this.indexOptions = ref.indexOptions();
  this.docValuesType = ref.docValuesType();
  this.dimensionCount = ref.pointDimensionCount();
  this.indexDimensionCount = ref.pointIndexDimensionCount();
  this.dimensionNumBytes = ref.pointNumBytes();
  if (ref.getAttributes() != null) {
    this.attributes = new HashMap<>(ref.getAttributes());
  }
  // Do not copy frozen!
}
 
Example 2
Source Project: lucene-solr   Source File: Field.java    License: 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 3
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create field with TokenStream value.
 * @param name field name
 * @param tokenStream TokenStream 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, or if indexed() is false.
 * @throws NullPointerException if the tokenStream is null
 */
public Field(String name, TokenStream tokenStream, IndexableFieldType type) {
  if (name == null) {
    throw new IllegalArgumentException("name must not be null");
  }
  if (tokenStream == null) {
    throw new NullPointerException("tokenStream must not be null");
  }
  if (type.indexOptions() == IndexOptions.NONE || !type.tokenized()) {
    throw new IllegalArgumentException("TokenStream fields must be indexed and tokenized");
  }
  if (type.stored()) {
    throw new IllegalArgumentException("TokenStream fields cannot be stored");
  }
  
  this.name = name;
  this.fieldsData = null;
  this.tokenStream = tokenStream;
  this.type = type;
}
 
Example 4
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create field with String value.
 * @param name field name
 * @param value string value
 * @param type field type
 * @throws IllegalArgumentException if either the name, value or type
 *         is null, or if the field's type is neither indexed() nor stored(), 
 *         or if indexed() is false but storeTermVectors() is true.
 */
public Field(String name, CharSequence value, IndexableFieldType type) {
  if (name == null) {
    throw new IllegalArgumentException("name must not be null");
  }
  if (value == null) {
    throw new IllegalArgumentException("value must not be null");
  }
  if (type == null) {
    throw new IllegalArgumentException("type must not be null");
  }
  if (!type.stored() && type.indexOptions() == IndexOptions.NONE) {
    throw new IllegalArgumentException("it doesn't make sense to have a field that "
      + "is neither indexed nor stored");
  }
  this.name = name;
  this.fieldsData = value;
  this.type = type;
}
 
Example 5
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Expert: creates a field with no initial value.
 * Intended only for custom Field subclasses.
 * @param name field name
 * @param type field type
 * @throws IllegalArgumentException if either the name or type
 *         is null.
 */
protected Field(String name, IndexableFieldType type) {
  if (name == null) {
    throw new IllegalArgumentException("name must not be null");
  }
  this.name = name;
  if (type == null) {
    throw new IllegalArgumentException("type must not be null");
  }
  this.type = type;
}
 
Example 6
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create field with binary value.
 *
 * <p>NOTE: the provided BytesRef is not copied so be sure
 * not to change it until you're done with this field.
 * @param name field name
 * @param bytes BytesRef pointing to binary content (not copied)
 * @param type field type
 * @throws IllegalArgumentException if the field name, bytes or type
 *         is null, or the field's type is indexed().
 */
public Field(String name, BytesRef bytes, IndexableFieldType type) {
  if (name == null) {
    throw new IllegalArgumentException("name must not be null");
  }
  if (bytes == null) {
    throw new IllegalArgumentException("bytes must not be null");
  }
  if (type == null) {
    throw new IllegalArgumentException("type must not be null");
  }
  this.name = name;
  this.fieldsData = bytes;
  this.type = type;
}
 
Example 7
Source Project: lucene-solr   Source File: BinaryPoint.java    License: Apache License 2.0 5 votes vote down vote up
/** Expert API */
public BinaryPoint(String name, byte[] packedPoint, IndexableFieldType type) {
  super(name, packedPoint, type);
  if (packedPoint.length != type.pointDimensionCount() * type.pointNumBytes()) {
    throw new IllegalArgumentException("packedPoint is length=" + packedPoint.length + " but type.pointDimensionCount()=" + type.pointDimensionCount() + " and type.pointNumBytes()=" + type.pointNumBytes());
  }
}
 
Example 8
Source Project: lucene-solr   Source File: RankField.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected IndexableField createField(String name, String val, IndexableFieldType type) {
  if (val == null || val.isEmpty()) {
    return null;
  }
  float featureValue;
  try {
    featureValue = Float.parseFloat(val);
  } catch (NumberFormatException nfe) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error while creating field '" + name + "' from value '" + val + "'. Expecting float.", nfe);
  }
  // Internally, we always use the same field
  return new FeatureField(INTERNAL_RANK_FIELD_NAME, name, featureValue);
}
 
Example 9
Source Project: Elasticsearch   Source File: NumberFieldMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
    return TYPE;
}
 
Example 10
Source Project: lucene-solr   Source File: NewField.java    License: Apache License 2.0 4 votes vote down vote up
public IndexableFieldType getFieldType() {
  return fieldType;
}
 
Example 11
Source Project: lucene-solr   Source File: IndexOptionsDialogFactory.java    License: Apache License 2.0 4 votes vote down vote up
public void setNewField(NewField nf) {
  this.nf = nf;

  storedCB.setSelected(nf.isStored());

  IndexableFieldType fieldType = nf.getFieldType();
  tokenizedCB.setSelected(fieldType.tokenized());
  omitNormsCB.setSelected(fieldType.omitNorms());
  idxOptCombo.setSelectedItem(fieldType.indexOptions().name());
  storeTVCB.setSelected(fieldType.storeTermVectors());
  storeTVPosCB.setSelected(fieldType.storeTermVectorPositions());
  storeTVOffCB.setSelected(fieldType.storeTermVectorOffsets());
  storeTVPayCB.setSelected(fieldType.storeTermVectorPayloads());
  dvTypeCombo.setSelectedItem(fieldType.docValuesType().name());
  dimCountTF.setText(String.valueOf(fieldType.pointDimensionCount()));
  dimNumBytesTF.setText(String.valueOf(fieldType.pointNumBytes()));

  if (nf.getType().equals(org.apache.lucene.document.TextField.class) ||
      nf.getType().equals(StringField.class) ||
      nf.getType().equals(Field.class)) {
    storedCB.setEnabled(true);
  } else {
    storedCB.setEnabled(false);
  }

  if (nf.getType().equals(Field.class)) {
    tokenizedCB.setEnabled(true);
    omitNormsCB.setEnabled(true);
    idxOptCombo.setEnabled(true);
    storeTVCB.setEnabled(true);
    storeTVPosCB.setEnabled(true);
    storeTVOffCB.setEnabled(true);
    storeTVPosCB.setEnabled(true);
  } else {
    tokenizedCB.setEnabled(false);
    omitNormsCB.setEnabled(false);
    idxOptCombo.setEnabled(false);
    storeTVCB.setEnabled(false);
    storeTVPosCB.setEnabled(false);
    storeTVOffCB.setEnabled(false);
    storeTVPayCB.setEnabled(false);
  }

  // TODO
  dvTypeCombo.setEnabled(false);
  dimCountTF.setEnabled(false);
  dimNumBytesTF.setEnabled(false);
}
 
Example 12
Source Project: lucene-solr   Source File: LazyDocument.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
  return getRealValue().fieldType();
}
 
Example 13
Source Project: lucene-solr   Source File: StoredFieldsWriter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
  return StoredField.TYPE;
}
 
Example 14
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the {@link FieldType} for this field. */
@Override
public IndexableFieldType fieldType() {
  return type;
}
 
Example 15
Source Project: lucene-solr   Source File: SolrDocumentFetcher.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
  return searcher.getSchema().getField(name());
}
 
Example 16
Source Project: elasticsearch-minhash   Source File: MinHashFieldMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
    return TYPE;
}
 
Example 17
Source Project: BioSolr   Source File: MergeAbstractFieldType.java    License: Apache License 2.0 4 votes vote down vote up
private ObjectField(String name, Object object, IndexableFieldType type, float boost) {
  this.name = name;
  this.object = object;
  this.type = type;
  this.boost = boost;
}
 
Example 18
Source Project: BioSolr   Source File: MergeAbstractFieldType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
  return type;
}
 
Example 19
Source Project: crate   Source File: CustomDocValuesField.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IndexableFieldType fieldType() {
    return TYPE;
}
 
Example 20
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create field with binary value.
 * 
 * <p>NOTE: the provided byte[] is not copied so be sure
 * not to change it until you're done with this field.
 * @param name field name
 * @param value byte array pointing to binary content (not copied)
 * @param type field type
 * @throws IllegalArgumentException if the field name, value or type
 *         is null, or the field's type is indexed().
 */
public Field(String name, byte[] value, IndexableFieldType type) {
  this(name, value, 0, value.length, type);
}
 
Example 21
Source Project: lucene-solr   Source File: Field.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create field with binary value.
 * 
 * <p>NOTE: the provided byte[] is not copied so be sure
 * not to change it until you're done with this field.
 * @param name field name
 * @param value byte array pointing to binary content (not copied)
 * @param offset starting position of the byte array
 * @param length valid length of the byte array
 * @param type field type
 * @throws IllegalArgumentException if the field name, value or type
 *         is null, or the field's type is indexed().
 */
public Field(String name, byte[] value, int offset, int length, IndexableFieldType type) {
  this(name, value != null ? new BytesRef(value, offset, length) : null, type);
}