Search in sources :

Example 1 with Annotation

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));
    }
}
Also used : NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) List(java.util.List) IntField(org.apache.lucene.document.IntField) Annotation(nl.inl.blacklab.search.indexmetadata.Annotation)

Example 2 with Annotation

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());
}
Also used : AnnotationForwardIndex(nl.inl.blacklab.forwardindex.AnnotationForwardIndex) Annotation(nl.inl.blacklab.search.indexmetadata.Annotation)

Example 3 with Annotation

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);
    }
}
Also used : BlackLabRuntimeException(nl.inl.blacklab.exceptions.BlackLabRuntimeException) MatchSensitivity(nl.inl.blacklab.search.indexmetadata.MatchSensitivity) Annotation(nl.inl.blacklab.search.indexmetadata.Annotation)

Example 4 with Annotation

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);
}
Also used : MatchSensitivity(nl.inl.blacklab.search.indexmetadata.MatchSensitivity) Annotation(nl.inl.blacklab.search.indexmetadata.Annotation)

Example 5 with Annotation

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);
}
Also used : Terms(nl.inl.blacklab.forwardindex.Terms) MatchSensitivity(nl.inl.blacklab.search.indexmetadata.MatchSensitivity) Annotation(nl.inl.blacklab.search.indexmetadata.Annotation)

Aggregations

Annotation (nl.inl.blacklab.search.indexmetadata.Annotation)30 AnnotatedField (nl.inl.blacklab.search.indexmetadata.AnnotatedField)8 MatchSensitivity (nl.inl.blacklab.search.indexmetadata.MatchSensitivity)8 Terms (nl.inl.blacklab.forwardindex.Terms)7 BlackLabIndex (nl.inl.blacklab.search.BlackLabIndex)6 ArrayList (java.util.ArrayList)5 AnnotationForwardIndex (nl.inl.blacklab.forwardindex.AnnotationForwardIndex)5 HitPropertyHitText (nl.inl.blacklab.resultproperty.HitPropertyHitText)5 MetadataField (nl.inl.blacklab.search.indexmetadata.MetadataField)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 BlackLabRuntimeException (nl.inl.blacklab.exceptions.BlackLabRuntimeException)4 HitProperty (nl.inl.blacklab.resultproperty.HitProperty)4 Document (org.apache.lucene.document.Document)4 IOException (java.io.IOException)3 IndexMetadata (nl.inl.blacklab.search.indexmetadata.IndexMetadata)3 SearchHits (nl.inl.blacklab.searches.SearchHits)3 File (java.io.File)2 HashSet (java.util.HashSet)2