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>
indexedLangs
private java.util.Map<IRI,java.util.Set<IRI>>
indexedTypeMapping
private org.slf4j.Logger
logger
protected int
maxDocs
private static java.util.Set<java.lang.String>
REJECTED_DATATYPES
private ValueFactory
vf
protected 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 boolean
accept(Literal literal)
Returns whether the provided literal is accepted by the LuceneIndex to be indexed.protected abstract void
addDocument(SearchDocument doc)
void
addDocuments(Resource subject, java.util.List<Statement> statements)
Add a complete Lucene Document based on these statements.private void
addProperty(java.lang.String field, java.lang.String value, SearchDocument document)
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.void
addRemoveStatements(java.util.Collection<Statement> added, java.util.Collection<Statement> removed)
Add many statements at the same time, remove many statements at the same time.void
addStatement(Statement statement)
Indexes the specified Statement.protected abstract SearchDocument
copyDocument(SearchDocument doc)
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.private static int
countPropertyValues(SearchDocument document)
protected abstract void
deleteDocument(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 BindingSetCollection
generateBindingSets(DistanceQuerySpec query, java.lang.Iterable<? extends DocumentDistance> hits)
private BindingSetCollection
generateBindingSets(GeoRelationQuerySpec query, java.lang.Iterable<? extends DocumentResult> hits)
private BindingSetCollection
generateBindingSets(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 SearchDocument
getDocument(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 Resource
getResource(SearchDocument document)
Returns the Resource corresponding with the specified Document.protected abstract org.locationtech.spatial4j.context.SpatialContext
getSpatialContext(java.lang.String property)
private static java.lang.String
getUnitSymbol(IRI units)
void
initialize(java.util.Properties parameters)
boolean
isGeoField(java.lang.String fieldName)
Returns true if the given property contains a geometry.boolean
isIndexedTypeStatement(Statement statement)
Returns true if the given statement is a type statement of the right type, seeLuceneSail.INDEXEDTYPES
to use.boolean
isTypeFilteringEnabled()
is theLuceneSail.INDEXEDTYPES
parameter set for this index.boolean
isTypeStatement(Statement statement)
Returns true if the given statement is a type statement, seeLuceneSail.INDEXEDTYPES
to use.protected abstract BulkUpdater
newBulkUpdate()
protected abstract SearchDocument
newDocument(java.lang.String id, java.lang.String resourceId, java.lang.String context)
protected java.lang.Object
parseLuceneQueryShape(java.lang.String property, java.lang.String value)
protected org.locationtech.spatial4j.shape.Shape
parseQueryPoint(java.lang.String property, java.lang.String value)
protected org.locationtech.spatial4j.shape.Shape
parseQueryShape(java.lang.String property, java.lang.String value)
protected abstract java.lang.Iterable<? extends DocumentScore>
query(Resource subject, QuerySpec param)
void
removeStatement(Statement statement)
Removes the specified Statement from the indexes.This should be called from within a begin-commit-rollbackprotected abstract void
updateDocument(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:
initialize
in 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:
accept
in 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:SearchIndex
Returns true if the given property contains a geometry.- Specified by:
isGeoField
in interfaceSearchIndex
- Returns:
- boolean
-
isTypeStatement
public boolean isTypeStatement(Statement statement)
Description copied from interface:SearchIndex
Returns true if the given statement is a type statement, seeLuceneSail.INDEXEDTYPES
to use. This method should return false ifSearchIndex.isTypeFilteringEnabled()
returns false.- Specified by:
isTypeStatement
in interfaceSearchIndex
- Parameters:
statement
- statement- Returns:
- boolean
-
isTypeFilteringEnabled
public boolean isTypeFilteringEnabled()
Description copied from interface:SearchIndex
is theLuceneSail.INDEXEDTYPES
parameter set for this index.- Specified by:
isTypeFilteringEnabled
in interfaceSearchIndex
- Returns:
- boolean
-
isIndexedTypeStatement
public boolean isIndexedTypeStatement(Statement statement)
Description copied from interface:SearchIndex
Returns true if the given statement is a type statement of the right type, seeLuceneSail.INDEXEDTYPES
to use. This method should return false ifSearchIndex.isTypeFilteringEnabled()
returns false.- Specified by:
isIndexedTypeStatement
in interfaceSearchIndex
- Parameters:
statement
- statement- Returns:
- boolean
-
getIndexedTypeMapping
public java.util.Map<IRI,java.util.Set<IRI>> getIndexedTypeMapping()
- Specified by:
getIndexedTypeMapping
in 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:
addStatement
in interfaceSearchIndex
- 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-rollbackblock.
- Specified by:
removeStatement
in 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:
addRemoveStatements
in 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:
addDocuments
in 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:
evaluate
in 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.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)
-
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:
MalformedQueryException
java.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:
MalformedQueryException
java.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:
MalformedQueryException
java.io.IOException
-
newBulkUpdate
protected abstract BulkUpdater newBulkUpdate()
-
-