Class AbstractSearchIndex

    • Field Detail

      • logger

        private final org.slf4j.Logger logger
      • REJECTED_DATATYPES

        private static final java.util.Set<java.lang.String> REJECTED_DATATYPES
      • maxDocs

        protected int maxDocs
      • wktFields

        protected java.util.Set<java.lang.String> wktFields
      • indexedLangs

        private java.util.Set<java.lang.String> indexedLangs
      • indexedTypeMapping

        private java.util.Map<IRI,​java.util.Set<IRI>> indexedTypeMapping
    • Constructor Detail

      • AbstractSearchIndex

        public AbstractSearchIndex()
    • Method Detail

      • initialize

        public void initialize​(java.util.Properties parameters)
                        throws java.lang.Exception
        Specified by:
        initialize in interface SearchIndex
        Throws:
        java.lang.Exception
      • getSpatialContext

        protected abstract org.locationtech.spatial4j.context.SpatialContext getSpatialContext​(java.lang.String property)
      • accept

        public boolean accept​(Literal literal)
        Returns whether the provided literal is accepted by the LuceneIndex to be indexed. It for instance does not make much since to index xsd:float.
        Specified by:
        accept in interface SearchIndex
        Parameters:
        literal - the literal to be accepted
        Returns:
        true if the given literal will be indexed by this LuceneIndex
      • isGeoField

        public boolean isGeoField​(java.lang.String fieldName)
        Description copied from interface: SearchIndex
        Returns true if the given property contains a geometry.
        Specified by:
        isGeoField in interface SearchIndex
        Returns:
        boolean
      • getIndexedTypeMapping

        public java.util.Map<IRI,​java.util.Set<IRI>> getIndexedTypeMapping()
        Specified by:
        getIndexedTypeMapping in interface SearchIndex
        Returns:
        the accepted types for a particular predicate map (predicate -> [objects])
      • addStatement

        public final void addStatement​(Statement statement)
                                throws java.io.IOException
        Indexes the specified Statement.
        Specified by:
        addStatement in interface SearchIndex
        Throws:
        java.io.IOException
      • removeStatement

        public final void removeStatement​(Statement statement)
                                   throws java.io.IOException
        Description copied from interface: SearchIndex
        Removes the specified Statement from the indexes.This should be called from within a begin-commit-rollback

        block.

        Specified by:
        removeStatement in interface SearchIndex
        Throws:
        java.io.IOException
      • addRemoveStatements

        public final void addRemoveStatements​(java.util.Collection<Statement> added,
                                              java.util.Collection<Statement> removed)
                                       throws java.io.IOException
        Add many statements at the same time, remove many statements at the same time. Ordering by resource has to be done inside this method. The passed added/removed sets are disjunct, no statement can be in both
        Specified by:
        addRemoveStatements in interface SearchIndex
        Parameters:
        added - all added statements, can have multiple subjects
        removed - all removed statements, can have multiple subjects
        Throws:
        java.io.IOException
      • copyDocument

        private boolean copyDocument​(SearchDocument newDocument,
                                     SearchDocument document,
                                     java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> removedProperties)
        Creates a copy of the old document; updating the retrieved Document instance works ok for stored properties but indexed data gets lost when doing an IndexWriter.updateDocument with it.
      • countPropertyValues

        private static int countPropertyValues​(SearchDocument document)
      • addDocuments

        public final void addDocuments​(Resource subject,
                                       java.util.List<Statement> statements)
                                throws java.io.IOException
        Add a complete Lucene Document based on these statements. Do not search for an existing document with the same subject id. (assume the existing document was deleted)
        Specified by:
        addDocuments in interface SearchIndex
        Parameters:
        statements - the statements that make up the resource
        Throws:
        java.io.IOException
      • addProperty

        private void addProperty​(Statement statement,
                                 SearchDocument document)
        check if the passed statement should be added (is it indexed? is it stored?) and add it as predicate to the passed document. No checks whether the predicate was already there.
        Parameters:
        statement - the statement to add
        document - the document to add to
      • addProperty

        private void addProperty​(java.lang.String field,
                                 java.lang.String value,
                                 SearchDocument document)
      • evaluateQuery

        private java.lang.Iterable<? extends DocumentScore> evaluateQuery​(QuerySpec query)
        Evaluates one Lucene Query. It distinguishes between two cases, the one where no subject is given and the one were it is given.
        Parameters:
        query - the Lucene query to evaluate
        Returns:
        QueryResult consisting of hits and highlighter
      • generateBindingSets

        private BindingSetCollection generateBindingSets​(QuerySpec query,
                                                         java.lang.Iterable<? extends DocumentScore> hits)
                                                  throws SailException
        This method generates bindings from the given result of a Lucene query.
        Parameters:
        query - the Lucene query
        Returns:
        a LinkedHashSet containing generated bindings
        Throws:
        SailException
      • getUnitSymbol

        private static java.lang.String getUnitSymbol​(IRI units)
      • parseLuceneQueryShape

        protected java.lang.Object parseLuceneQueryShape​(java.lang.String property,
                                                         java.lang.String value)
                                                  throws java.text.ParseException,
                                                         java.io.IOException
        Throws:
        java.text.ParseException
        java.io.IOException
      • parseQueryShape

        protected org.locationtech.spatial4j.shape.Shape parseQueryShape​(java.lang.String property,
                                                                         java.lang.String value)
                                                                  throws java.text.ParseException
        Throws:
        java.text.ParseException
      • parseQueryPoint

        protected org.locationtech.spatial4j.shape.Shape parseQueryPoint​(java.lang.String property,
                                                                         java.lang.String value)
                                                                  throws java.text.ParseException
        Throws:
        java.text.ParseException
      • getResource

        protected Resource getResource​(SearchDocument document)
        Returns the Resource corresponding with the specified Document.
      • getDocument

        protected abstract SearchDocument getDocument​(java.lang.String id)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getDocuments

        protected abstract java.lang.Iterable<? extends SearchDocument> getDocuments​(java.lang.String resourceId)
                                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • newDocument

        protected abstract SearchDocument newDocument​(java.lang.String id,
                                                      java.lang.String resourceId,
                                                      java.lang.String context)
      • addDocument

        protected abstract void addDocument​(SearchDocument doc)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • updateDocument

        protected abstract void updateDocument​(SearchDocument doc)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteDocument

        protected abstract void deleteDocument​(SearchDocument doc)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • newBulkUpdate

        protected abstract BulkUpdater newBulkUpdate()