/** Returns a field with the given name if any exist in this document, or * null. If multiple fields exists with this name, this method returns the * first value added. */ public final IndexableField getField(String name) { for (IndexableField field : fields) { if (field.name().equals(name)) { return field; } } return null; }
@Override protected boolean isStoredField( IndexableField field ) { return !field.name().endsWith( CustomType.EXACT_FIELD_SUFFIX ) && super.isStoredField( field ); }
private void removeAllValueFields() { Iterator<IndexableField> it = document.getFields().iterator(); while ( it.hasNext() ) { IndexableField field = it.next(); String fieldName = field.name(); if ( !fieldName.equals( NODE_ID_KEY ) ) { it.remove(); } } }
private void removeAllValueFields() { Iterator<IndexableField> it = document.getFields().iterator(); while ( it.hasNext() ) { IndexableField field = it.next(); String fieldName = field.name(); if ( !fieldName.equals( FIELD_ENTITY_ID ) ) { it.remove(); } } } }
/** * Returns an array of {@link IndexableField}s with the given name. * This method returns an empty array when there are no * matching fields. It never returns null. * * @param name the name of the field * @return a <code>Field[]</code> array */ public IndexableField[] getFields(String name) { List<IndexableField> result = new ArrayList<>(); for (IndexableField field : fields) { if (field.name().equals(name)) { result.add(field); } } return result.toArray(new IndexableField[result.size()]); }
/** * <p>Removes all fields with the given name from the document. * If there is no field with the specified name, the document remains unchanged.</p> * <p> Note that the removeField(s) methods like the add method only make sense * prior to adding a document to an index. These methods cannot * be used to change the content of an existing index! In order to achieve this, * a document has to be deleted from an index and a new changed version of that * document has to be added.</p> */ public final void removeFields(String name) { Iterator<IndexableField> it = fields.iterator(); while (it.hasNext()) { IndexableField field = it.next(); if (field.name().equals(name)) { it.remove(); } } }
/** * <p>Removes field with the specified name from the document. * If multiple fields exist with this name, this method removes the first field that has been added. * If there is no field with the specified name, the document remains unchanged.</p> * <p> Note that the removeField(s) methods like the add method only make sense * prior to adding a document to an index. These methods cannot * be used to change the content of an existing index! In order to achieve this, * a document has to be deleted from an index and a new changed version of that * document has to be added.</p> */ public final void removeField(String name) { Iterator<IndexableField> it = fields.iterator(); while (it.hasNext()) { IndexableField field = it.next(); if (field.name().equals(name)) { it.remove(); return; } } }
static boolean documentIsEmpty( Document document ) { List<IndexableField> fields = document.getFields(); for ( IndexableField field : fields ) { if ( LuceneExplicitIndex.isValidKey( field.name() ) ) { return false; } } return true; }
private Collection<IndexableField> getNotIndexedStoredFields( Document document ) { Map<String,IndexableField> nameFieldMap = new HashMap<>(); List<String> indexedFields = new ArrayList<>(); for ( IndexableField field : document.getFields() ) { if ( isStoredField( field ) ) { nameFieldMap.put( field.name(), field ); } else if ( !DocValuesType.NONE.equals( field.fieldType().docValuesType() ) ) { indexedFields.add( field.name() ); } } indexedFields.forEach( nameFieldMap::remove ); return nameFieldMap.values(); }
/** * Returns an array of bytes for the first (or only) field that has the name * specified as the method parameter. This method will return <code>null</code> * if no binary fields with the specified name are available. * There may be non-binary fields with the same name. * * @param name the name of the field. * @return a <code>BytesRef</code> containing the binary field value or <code>null</code> */ public final BytesRef getBinaryValue(String name) { for (IndexableField field : fields) { if (field.name().equals(name)) { final BytesRef bytes = field.binaryValue(); if (bytes != null) { return bytes; } } } return null; }
/** * Returns an array of byte arrays for of the fields that have the name specified * as the method parameter. This method returns an empty * array when there are no matching fields. It never * returns null. * * @param name the name of the field * @return a <code>BytesRef[]</code> of binary field values */ public final BytesRef[] getBinaryValues(String name) { final List<BytesRef> result = new ArrayList<>(); for (IndexableField field : fields) { if (field.name().equals(name)) { final BytesRef bytes = field.binaryValue(); if (bytes != null) { result.add(bytes); } } } return result.toArray(new BytesRef[result.size()]); }
private void clearDocument( Document document ) { Set<String> names = new HashSet<>(); for ( IndexableField field : document.getFields() ) { String name = field.name(); if ( LuceneExplicitIndex.isValidKey( name ) ) { names.add( name ); } } for ( String name : names ) { document.removeFields( name ); } }
/** * Returns an array of values of the field specified as the method parameter. * This method returns an empty array when there are no * matching fields. It never returns null. * For a numeric {@link StoredField} it returns the string value of the number. If you want * the actual numeric field instances back, use {@link #getFields}. * @param name the name of the field * @return a <code>String[]</code> of field values */ public final String[] getValues(String name) { List<String> result = new ArrayList<>(); for (IndexableField field : fields) { if (field.name().equals(name) && field.stringValue() != null) { result.add(field.stringValue()); } } if (result.size() == 0) { return NO_STRINGS; } return result.toArray(new String[result.size()]); }
/** Returns the string value of the field with the given name if any exist in * this document, or null. If multiple fields exist with this name, this * method returns the first value added. If only binary fields with this name * exist, returns null. * For a numeric {@link StoredField} it returns the string value of the number. If you want * the actual numeric field instance back, use {@link #getField}. */ public final String get(String name) { for (IndexableField field : fields) { if (field.name().equals(name) && field.stringValue() != null) { return field.stringValue(); } } return null; }
void restoreSortFields( Document document ) { Collection<IndexableField> notIndexedStoredFields = getNotIndexedStoredFields( document ); for ( IndexableField field : notIndexedStoredFields ) { Object fieldValue = getFieldValue( field ); String name = field.name(); removeFieldsFromDocument( document, name, fieldValue ); addNewFieldToDocument( document, name, fieldValue ); } }
private void removeFromCache( long entityId ) throws IOException { IndexSearcher searcher = searcherManager.acquire(); try { Query query = type.idTermQuery( entityId ); TopDocs docs = searcher.search( query, 1 ); if ( docs.totalHits > 0 ) { Document document = searcher.doc( docs.scoreDocs[0].doc ); for ( IndexableField field : document.getFields() ) { String key = field.name(); Object value = field.stringValue(); removeFromCache( entityId, key, value ); } } } finally { searcherManager.release( searcher ); } }
string = field.stringValue(); if (string == null) { throw new IllegalArgumentException("field " + field.name() + " is stored but does not have binaryValue, stringValue nor numericValue");
if (field.fieldType().storeTermVectorPayloads()) { throw new IllegalArgumentException("cannot index term vector payloads without term vector positions (field=\"" + field.name() + "\")"); throw new IllegalArgumentException("cannot index term vector offsets when term vectors are not indexed (field=\"" + field.name() + "\")"); throw new IllegalArgumentException("cannot index term vector positions when term vectors are not indexed (field=\"" + field.name() + "\")"); throw new IllegalArgumentException("cannot index term vector payloads when term vectors are not indexed (field=\"" + field.name() + "\")"); throw new IllegalArgumentException("all instances of a given field name must have the same term vectors settings (storeTermVectors changed for field=\"" + field.name() + "\")"); throw new IllegalArgumentException("all instances of a given field name must have the same term vectors settings (storeTermVectorPositions changed for field=\"" + field.name() + "\")"); throw new IllegalArgumentException("all instances of a given field name must have the same term vectors settings (storeTermVectorOffsets changed for field=\"" + field.name() + "\")"); throw new IllegalArgumentException("all instances of a given field name must have the same term vectors settings (storeTermVectorPayloads changed for field=\"" + field.name() + "\")");
private int processField(IndexableField field, long fieldGen, int fieldCount) throws IOException { String fieldName = field.name(); IndexableFieldType fieldType = field.fieldType(); throw new NullPointerException("IndexOptions must not be null (field: \"" + field.name() + "\")"); String value = field.stringValue(); if (value != null && value.length() > IndexWriter.MAX_STORED_STRING_LENGTH) { throw new IllegalArgumentException("stored field \"" + field.name() + "\" is too large (" + value.length() + " characters) to store");