final DocValuesType dvType = f.fieldType().docValuesType(); if (dvType == null) { throw new NullPointerException("DocValuesType must not be null (field: \"" + f.name() + "\")"); throw new IllegalArgumentException("can only update NUMERIC or BINARY fields! field=" + f.name()); if (globalFieldNumberMap.contains(f.name(), dvType) == false) { globalFieldNumberMap.addOrGet(f.name(), -1, dvType, 0, 0, 0, f.name().equals(config.softDeletesField)); assert globalFieldNumberMap.contains(f.name(), dvType); if (config.getIndexSortFields().contains(f.name())) { throw new IllegalArgumentException("cannot update docvalues field involved in the index sort, field=" + f.name() + ", sort=" + config.getIndexSort()); case NUMERIC: Long value = (Long)f.numericValue(); dvUpdates[i] = new NumericDocValuesUpdate(term, f.name(), value); break; case BINARY: dvUpdates[i] = new BinaryDocValuesUpdate(term, f.name(), f.binaryValue()); break; default: throw new IllegalArgumentException("can only update NUMERIC or BINARY fields: field=" + f.name() + ", type=" + dvType);
/** * Fixes problems with broken analysis chains if positions and offsets are messed up that can lead to * {@link StringIndexOutOfBoundsException} in the {@link FastVectorHighlighter} */ public static WeightedFragInfo fixWeightedFragInfo(MappedFieldType fieldType, Field[] values, WeightedFragInfo fragInfo) { assert fragInfo != null : "FragInfo must not be null"; assert fieldType.name().equals(values[0].name()) : "Expected MappedFieldType for field " + values[0].name(); if (!fragInfo.getSubInfos().isEmpty() && containsBrokenAnalysis(fieldType.indexAnalyzer())) { /* This is a special case where broken analysis like WDF is used for term-vector creation at index-time * which can potentially mess up the offsets. To prevent a SAIIOBException we need to resort * the fragments based on their offsets rather than using solely the positions as it is done in * the FastVectorHighlighter. Yet, this is really a lucene problem and should be fixed in lucene rather * than in this hack... aka. "we are are working on in!" */ final List<SubInfo> subInfos = fragInfo.getSubInfos(); CollectionUtil.introSort(subInfos, new Comparator<SubInfo>() { @Override public int compare(SubInfo o1, SubInfo o2) { int startOffset = o1.getTermsOffsets().get(0).getStartOffset(); int startOffset2 = o2.getTermsOffsets().get(0).getStartOffset(); return FragmentBuilderHelper.compare(startOffset, startOffset2); } }); return new WeightedFragInfo(Math.min(fragInfo.getSubInfos().get(0).getTermsOffsets().get(0).getStartOffset(), fragInfo.getStartOffset()), fragInfo.getEndOffset(), subInfos, fragInfo.getTotalBoost()); } else { return fragInfo; } }
public String getName() { return field.name(); }
public String getName() { return field.name(); }
/** * Adds a field to this document.<p> * * @param f the field to add */ private void add(Field f) { m_fields.put(f.name(), f); m_doc.add(f); } }
@Override final public void accept(final String genericFieldName, final String concreteFieldName, final Field field) { // We will not update the internal ID of the document if (FieldDefinition.ID_FIELD.equals(field.name())) return; fieldList.add(field); }
/** 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 Field getField(String name) { for (int i = 0; i < fields.size(); i++) { Field field = (Field)fields.get(i); if (field.name().equals(name)) return field; } return null; }
/** 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. * Do not use this method with lazy loaded fields. */ public final Field getField(String name) { for (int i = 0; i < fields.size(); i++) { Field field = (Field)fields.get(i); if (field.name().equals(name)) return field; } return null; }
/** 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. * Do not use this method with lazy loaded fields. */ public final Field getField(String name) { for (int i = 0; i < fields.size(); i++) { Field field = (Field)fields.get(i); if (field.name().equals(name)) return field; } return null; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); Enumeration en = doc.fields(); while (en.hasMoreElements()) { Field f = (Field)en.nextElement(); sb.append(f.name()); sb.append(":"); sb.append(f.stringValue()); sb.append("\n"); } return sb.toString(); }
/** * By default field whose value is greater than 1000 are not indexed. * @param document * @param field */ private void add(Document document, Field field) { if (field.stringValue().length()>1000) { log.trace("field "+field.name()+" too long; not indexed"); } else { document.add(field); log.trace("adding "+field.name()+"["+field.getClass().getSimpleName()+"]: " + field); } }
public static Map<String, String> documentToMap(Document doc) { HashMap<String, String> result = new HashMap<String, String>(); for (Object f : doc.getFields()) { Field field = (Field) f; result.put(field.name(), field.stringValue()); } return result; }
private static Map<String,String> getObject(Document doc) { TreeMap<String, String> result = new TreeMap<String, String>(); for (Object s : doc.getFields()) { if (s instanceof Field) { Field f = (Field) s; result.put(f.name(), f.stringValue()); } } return result; }
private static Map<String, String> getObject(Document doc) { TreeMap<String, String> result = new TreeMap<String, String>(); for (Object s : doc.getFields()) { if (s instanceof Field) { Field f = (Field) s; result.put(f.name(), f.stringValue()); } } return result; }
private int numberOfFieldsWithPrefix(String prefix, List<Field> fields) { int size = 0; for (Field field : fields) { if (field.name().startsWith(prefix)) size++; } System.out.println("Fields with prefix[" + prefix + "]:" + size); return size; }
private int numberOfFieldsWithKey(String key, List<Field> fields) { int size = 0; for (Field field : fields) { if (field.name().equals(key)) size++; } System.out.println("Fields with name[" + key + "]:" + size); return size; }
/** Adds field info for a Document. */ public void add(Document doc) { Enumeration fields = doc.fields(); while (fields.hasMoreElements()) { Field field = (Field) fields.nextElement(); add(field.name(), field.isIndexed(), field.isTermVectorStored()); } }
public void writeField( Field field ) throws IOException { int flags = ( field.isIndexed() ? F_INDEXED : 0 ) // + ( field.isTokenized() ? F_TOKENIZED : 0 ) // + ( field.isStored() ? F_STORED : 0 ) // + ( field.isCompressed() ? F_COMPRESSED : 0 ); String name = field.name(); String value = field.stringValue(); dos.write( flags ); dos.writeUTF( name ); writeUTF( value, dos ); }
private static void assertFieldEquality(Field original, Field copy) { assertThat( copy.name() ).isEqualTo( original.name() ); assertThat( copy.binaryValue() ).isEqualTo( original.binaryValue() ); assertThat( copy.boost() ).isEqualTo( original.boost() ); assertFieldType( copy.fieldType(), original.fieldType() ); assertThat( compareReaders( copy.readerValue(), original.readerValue() ) ).isTrue(); assertThat( compareTokenStreams( original.tokenStreamValue(), copy.tokenStreamValue() ) ).isTrue(); assertThat( copy.stringValue() ).isEqualTo( original.stringValue() ); }