Package org.eclipse.rdf4j.sail.lucene
Class AbstractSearchIndex
- java.lang.Object
-
- org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
-
- All Implemented Interfaces:
SearchIndex
- Direct Known Subclasses:
AbstractLuceneIndex
public abstract class AbstractSearchIndex extends java.lang.Object implements SearchIndex
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>indexedLangsprivate java.util.Map<IRI,java.util.Set<IRI>>indexedTypeMappingprivate org.slf4j.Loggerloggerprotected intmaxDocsprivate static java.util.Set<java.lang.String>REJECTED_DATATYPESprivate ValueFactoryvfprotected java.util.Set<java.lang.String>wktFields
-
Constructor Summary
Constructors Constructor Description AbstractSearchIndex()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanaccept(Literal literal)Returns whether the provided literal is accepted by the LuceneIndex to be indexed.protected abstract voidaddDocument(SearchDocument doc)voidaddDocuments(Resource subject, java.util.List<Statement> statements)Add a complete Lucene Document based on these statements.private voidaddProperty(java.lang.String field, java.lang.String value, SearchDocument document)private voidaddProperty(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.voidaddRemoveStatements(java.util.Collection<Statement> added, java.util.Collection<Statement> removed)Add many statements at the same time, remove many statements at the same time.voidaddStatement(Statement statement)Indexes the specified Statement.protected abstract SearchDocumentcopyDocument(SearchDocument doc)private booleancopyDocument(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.private static intcountPropertyValues(SearchDocument document)protected abstract voiddeleteDocument(SearchDocument doc)java.util.Collection<BindingSet>evaluate(SearchQueryEvaluator evaluator)private java.lang.Iterable<? extends DocumentDistance>evaluateQuery(DistanceQuerySpec query)private java.lang.Iterable<? extends DocumentResult>evaluateQuery(GeoRelationQuerySpec query)private java.lang.Iterable<? extends DocumentScore>evaluateQuery(QuerySpec query)Evaluates one Lucene Query.private BindingSetCollectiongenerateBindingSets(DistanceQuerySpec query, java.lang.Iterable<? extends DocumentDistance> hits)private BindingSetCollectiongenerateBindingSets(GeoRelationQuerySpec query, java.lang.Iterable<? extends DocumentResult> hits)private BindingSetCollectiongenerateBindingSets(QuerySpec query, java.lang.Iterable<? extends DocumentScore> hits)This method generates bindings from the given result of a Lucene query.protected abstract java.lang.Iterable<? extends DocumentDistance>geoQuery(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, java.lang.String distanceVar, Var context)protected abstract java.lang.Iterable<? extends DocumentResult>geoRelationQuery(java.lang.String relation, IRI geoProperty, java.lang.String wkt, Var context)protected abstract SearchDocumentgetDocument(java.lang.String id)protected abstract java.lang.Iterable<? extends SearchDocument>getDocuments(java.lang.String resourceId)java.util.Map<IRI,java.util.Set<IRI>>getIndexedTypeMapping()protected ResourcegetResource(SearchDocument document)Returns the Resource corresponding with the specified Document.protected abstract org.locationtech.spatial4j.context.SpatialContextgetSpatialContext(java.lang.String property)private static java.lang.StringgetUnitSymbol(IRI units)voidinitialize(java.util.Properties parameters)booleanisGeoField(java.lang.String fieldName)Returns true if the given property contains a geometry.booleanisIndexedTypeStatement(Statement statement)Returns true if the given statement is a type statement of the right type, seeLuceneSail.INDEXEDTYPESto use.booleanisTypeFilteringEnabled()is theLuceneSail.INDEXEDTYPESparameter set for this index.booleanisTypeStatement(Statement statement)Returns true if the given statement is a type statement, seeLuceneSail.INDEXEDTYPESto use.protected abstract BulkUpdaternewBulkUpdate()protected abstract SearchDocumentnewDocument(java.lang.String id, java.lang.String resourceId, java.lang.String context)protected java.lang.ObjectparseLuceneQueryShape(java.lang.String property, java.lang.String value)protected org.locationtech.spatial4j.shape.ShapeparseQueryPoint(java.lang.String property, java.lang.String value)protected org.locationtech.spatial4j.shape.ShapeparseQueryShape(java.lang.String property, java.lang.String value)protected abstract java.lang.Iterable<? extends DocumentScore>query(Resource subject, QuerySpec param)voidremoveStatement(Statement statement)Removes the specified Statement from the indexes.This should be called from within a begin-commit-rollbackprotected abstract voidupdateDocument(SearchDocument doc)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.sail.lucene.SearchIndex
begin, clear, clearContexts, commit, rollback, shutDown
-
-
-
-
Field Detail
-
logger
private final org.slf4j.Logger logger
-
vf
private final ValueFactory vf
-
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
-
-
Method Detail
-
initialize
public void initialize(java.util.Properties parameters) throws java.lang.Exception- Specified by:
initializein interfaceSearchIndex- 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:
acceptin interfaceSearchIndex- 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:SearchIndexReturns true if the given property contains a geometry.- Specified by:
isGeoFieldin interfaceSearchIndex- Returns:
- boolean
-
isTypeStatement
public boolean isTypeStatement(Statement statement)
Description copied from interface:SearchIndexReturns true if the given statement is a type statement, seeLuceneSail.INDEXEDTYPESto use. This method should return false ifSearchIndex.isTypeFilteringEnabled()returns false.- Specified by:
isTypeStatementin interfaceSearchIndex- Parameters:
statement- statement- Returns:
- boolean
-
isTypeFilteringEnabled
public boolean isTypeFilteringEnabled()
Description copied from interface:SearchIndexis theLuceneSail.INDEXEDTYPESparameter set for this index.- Specified by:
isTypeFilteringEnabledin interfaceSearchIndex- Returns:
- boolean
-
isIndexedTypeStatement
public boolean isIndexedTypeStatement(Statement statement)
Description copied from interface:SearchIndexReturns true if the given statement is a type statement of the right type, seeLuceneSail.INDEXEDTYPESto use. This method should return false ifSearchIndex.isTypeFilteringEnabled()returns false.- Specified by:
isIndexedTypeStatementin interfaceSearchIndex- Parameters:
statement- statement- Returns:
- boolean
-
getIndexedTypeMapping
public java.util.Map<IRI,java.util.Set<IRI>> getIndexedTypeMapping()
- Specified by:
getIndexedTypeMappingin interfaceSearchIndex- 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:
addStatementin interfaceSearchIndex- Throws:
java.io.IOException
-
removeStatement
public final void removeStatement(Statement statement) throws java.io.IOException
Description copied from interface:SearchIndexRemoves the specified Statement from the indexes.This should be called from within a begin-commit-rollbackblock.
- Specified by:
removeStatementin interfaceSearchIndex- 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:
addRemoveStatementsin interfaceSearchIndex- Parameters:
added- all added statements, can have multiple subjectsremoved- 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:
addDocumentsin interfaceSearchIndex- 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 adddocument- the document to add to
-
addProperty
private void addProperty(java.lang.String field, java.lang.String value, SearchDocument document)
-
evaluate
public final java.util.Collection<BindingSet> evaluate(SearchQueryEvaluator evaluator) throws SailException
- Specified by:
evaluatein interfaceSearchIndex- Throws:
SailException
-
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
-
evaluateQuery
private java.lang.Iterable<? extends DocumentDistance> evaluateQuery(DistanceQuerySpec query)
-
getUnitSymbol
private static java.lang.String getUnitSymbol(IRI units)
-
generateBindingSets
private BindingSetCollection generateBindingSets(DistanceQuerySpec query, java.lang.Iterable<? extends DocumentDistance> hits) throws SailException
- Throws:
SailException
-
evaluateQuery
private java.lang.Iterable<? extends DocumentResult> evaluateQuery(GeoRelationQuerySpec query)
-
generateBindingSets
private BindingSetCollection generateBindingSets(GeoRelationQuerySpec query, java.lang.Iterable<? extends DocumentResult> hits) throws SailException
- Throws:
SailException
-
parseLuceneQueryShape
protected java.lang.Object parseLuceneQueryShape(java.lang.String property, java.lang.String value) throws java.text.ParseException, java.io.IOException- Throws:
java.text.ParseExceptionjava.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)
-
copyDocument
protected abstract SearchDocument copyDocument(SearchDocument doc)
-
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
-
query
protected abstract java.lang.Iterable<? extends DocumentScore> query(Resource subject, QuerySpec param) throws MalformedQueryException, java.io.IOException
- Throws:
MalformedQueryExceptionjava.io.IOException
-
geoQuery
protected abstract java.lang.Iterable<? extends DocumentDistance> geoQuery(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, java.lang.String distanceVar, Var context) throws MalformedQueryException, java.io.IOException
- Throws:
MalformedQueryExceptionjava.io.IOException
-
geoRelationQuery
protected abstract java.lang.Iterable<? extends DocumentResult> geoRelationQuery(java.lang.String relation, IRI geoProperty, java.lang.String wkt, Var context) throws MalformedQueryException, java.io.IOException
- Throws:
MalformedQueryExceptionjava.io.IOException
-
newBulkUpdate
protected abstract BulkUpdater newBulkUpdate()
-
-