use of nl.inl.blacklab.search.indexmetadata.Annotation in project BlackLab by INL.
the class ForwardIndexImplSeparate method addDocument.
@Override
public void addDocument(Map<Annotation, List<String>> content, Map<Annotation, List<Integer>> posIncr, Document document) {
for (Entry<Annotation, List<String>> e : content.entrySet()) {
Annotation annotation = e.getKey();
AnnotationForwardIndex afi = get(annotation);
List<Integer> posIncrThisAnnot = posIncr.get(annotation);
int fiid = afi.addDocument(e.getValue(), posIncrThisAnnot);
String fieldName = annotation.forwardIndexIdField();
document.add(new IntField(fieldName, fiid, Store.YES));
// for fast retrieval (FiidLookup)
document.add(new NumericDocValuesField(fieldName, fiid));
}
}
use of nl.inl.blacklab.search.indexmetadata.Annotation in project BlackLab by INL.
the class IndexerImpl method addToForwardIndex.
/**
* Add a list of tokens to an annotation forward index
*
* @param prop the annotation to get values and position increments from
* @return the id assigned to the content
* @deprecated add a whole field at a time using {@link #addToForwardIndex(AnnotatedFieldWriter, Document)}
*/
@Override
@Deprecated
public int addToForwardIndex(AnnotationWriter prop) {
Annotation annotation = indexWriter.getOrCreateAnnotation(prop.field(), prop.name());
AnnotationForwardIndex forwardIndex = indexWriter.annotationForwardIndex(annotation);
if (forwardIndex == null)
throw new IllegalArgumentException("No forward index for field " + AnnotatedFieldNameUtil.annotationField(prop.field().name(), prop.name()));
return forwardIndex.addDocument(prop.values(), prop.positionIncrements());
}
use of nl.inl.blacklab.search.indexmetadata.Annotation in project BlackLab by INL.
the class HitPropertyContextBase method deserializeProp.
protected static <T extends HitPropertyContextBase> T deserializeProp(Class<T> cls, BlackLabIndex index, AnnotatedField field, String info) {
String[] parts = PropertySerializeUtil.splitParts(info);
String propName = parts[0];
if (propName.length() == 0)
propName = AnnotatedFieldNameUtil.getDefaultMainAnnotationName();
MatchSensitivity sensitivity = parts.length > 1 ? MatchSensitivity.fromLuceneFieldSuffix(parts[1]) : MatchSensitivity.SENSITIVE;
// ContextSize contextSize = parts.length > 2 ? ContextSize.get(Integer.parseInt(parts[2]))
// : index.defaultContextSize();
Annotation annotation = field.annotation(propName);
try {
Constructor<T> ctor = cls.getConstructor(BlackLabIndex.class, Annotation.class, MatchSensitivity.class);
return ctor.newInstance(index, annotation, sensitivity);
} catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
throw new BlackLabRuntimeException("Couldn't deserialize hit property: " + cls.getName() + ":" + info, e);
}
}
use of nl.inl.blacklab.search.indexmetadata.Annotation in project BlackLab by INL.
the class HitPropertyContextWords method deserializeProp.
static HitPropertyContextWords deserializeProp(BlackLabIndex index, AnnotatedField field, String info) {
String[] parts = PropertySerializeUtil.splitParts(info);
String propName = parts[0];
if (propName.length() == 0)
propName = AnnotatedFieldNameUtil.getDefaultMainAnnotationName();
MatchSensitivity sensitivity = parts.length > 1 ? MatchSensitivity.fromLuceneFieldSuffix(parts[1]) : MatchSensitivity.SENSITIVE;
List<ContextPart> whichWords = null;
if (parts.length > 2)
whichWords = parseContextWordSpec(parts[2]);
Annotation annotation = field.annotation(propName);
return new HitPropertyContextWords(index, annotation, sensitivity, whichWords);
}
use of nl.inl.blacklab.search.indexmetadata.Annotation in project BlackLab by INL.
the class PropertyValueContextWord method deserialize.
public static PropertyValue deserialize(BlackLabIndex index, AnnotatedField field, String info) {
String[] parts = PropertySerializeUtil.splitParts(info);
String propName = parts[0];
Annotation annotation = field.annotation(propName);
MatchSensitivity sensitivity = MatchSensitivity.fromLuceneFieldSuffix(parts[1]);
String term = parts[2];
Terms termsObj = index.annotationForwardIndex(annotation).terms();
int termId = termsObj.deserializeToken(term);
return new PropertyValueContextWord(index, annotation, sensitivity, termId);
}
Aggregations