Class LuceneIndex
java.lang.Object
org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
org.eclipse.rdf4j.sail.lucene.AbstractLuceneIndex
org.eclipse.rdf4j.sail.lucene.impl.LuceneIndex
- All Implemented Interfaces:
SearchIndex
- Direct Known Subclasses:
LuceneIndexNIOFS
A LuceneIndex is a one-stop-shop abstraction of a Lucene index. It takes care of proper synchronization of
IndexReaders, IndexWriters and IndexSearchers in a way that is suitable for a LuceneSail.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected ReaderMonitor
This holds IndexReader and IndexSearcher.Fields inherited from class org.eclipse.rdf4j.sail.lucene.AbstractLuceneIndex
oldmonitors
Fields inherited from class org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
maxDocs, wktFields
-
Constructor Summary
ConstructorDescriptionLuceneIndex
(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer) Constructor for keeping backwards compatibility.LuceneIndex
(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.similarities.Similarity similarity) Creates a new LuceneIndex. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addContextField
(String context, org.apache.lucene.document.Document document) Add the "context" value to the docprotected void
static void
addIDField
(String id, org.apache.lucene.document.Document document) Stores and indexes an ID in a Document.static void
addPredicateField
(String predicate, String text, org.apache.lucene.document.Document document) static void
addResourceField
(String resourceId, org.apache.lucene.document.Document document) Stores and indexes the resource ID in a Document.static void
addStoredOnlyPredicateField
(String predicate, String text, org.apache.lucene.document.Document document) static void
addTextField
(String text, org.apache.lucene.document.Document document) void
begin()
Begins a transaction.void
clear()
Clears the indexes.void
clearContexts
(Resource... contexts) This should be called from within a begin-commit-rollback block.void
commit()
Commits any changes done to the LuceneIndex since the last commit.protected SearchDocument
protected org.apache.lucene.analysis.Analyzer
createAnalyzer
(Properties parameters) protected org.apache.lucene.store.Directory
createDirectory
(Properties parameters) protected org.apache.lucene.search.similarities.Similarity
createSimilarity
(Properties parameters) protected com.google.common.base.Function<String,
? extends org.apache.lucene.spatial.SpatialStrategy> createSpatialStrategyMapper
(Map<String, String> parameters) protected void
protected Iterable<? extends DocumentDistance>
geoQuery
(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, String distanceVar, Var contextVar) protected Iterable<? extends DocumentResult>
geoRelationQuery
(String relation, IRI geoProperty, String wkt, Var contextVar) org.apache.lucene.analysis.Analyzer
Current monitor holds instance of IndexReader and IndexSearcher It is used to keep track of readersorg.apache.lucene.store.Directory
org.apache.lucene.document.Document
getDocument
(int docId, Set<String> fieldsToLoad) Returns the lucene hit with the given id of the respective lucene queryprotected SearchDocument
getDocument
(String id) org.apache.lucene.document.Document
getDocument
(Resource subject, Resource context) Returns a Document representing the specified Resource and Context combination, or null when no such Document exists yet.protected Iterable<? extends SearchDocument>
getDocuments
(String resourceId) List<org.apache.lucene.document.Document>
getDocuments
(Resource subject) Returns a list of Documents representing the specified Resource (empty when no such Document exists yet).Each document represent a set of statements with the specified Resource as a subject, which are stored in a specific contextorg.apache.lucene.index.IndexReader
org.apache.lucene.search.IndexSearcher
org.apache.lucene.index.IndexWriter
getSnippet
(String fieldName, String text, org.apache.lucene.search.highlight.Highlighter highlighter) protected org.locationtech.spatial4j.context.SpatialContext
getSpatialContext
(String property) com.google.common.base.Function<? super String,
? extends org.apache.lucene.spatial.SpatialStrategy> void
initialize
(Properties parameters) protected BulkUpdater
protected SearchDocument
newDocument
(String id, String resourceId, String context) protected Iterable<? extends DocumentScore>
Parse the passed query.void
rollback()
org.apache.lucene.search.TopDocs
search
(org.apache.lucene.search.Query query) Evaluates the given query and returns the results as a TopDocs instance.org.apache.lucene.search.TopDocs
Evaluates the given query only for the given resource.void
shutDown()
protected void
Methods inherited from class org.eclipse.rdf4j.sail.lucene.AbstractLuceneIndex
getOldMonitors
Methods inherited from class org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
accept, addDocuments, addRemoveStatements, addStatement, evaluate, getIndexedTypeMapping, getResource, isGeoField, isIndexedTypeStatement, isTypeFilteringEnabled, isTypeStatement, parseLuceneQueryShape, parseQueryPoint, parseQueryShape, removeStatement
-
Field Details
-
currentMonitor
This holds IndexReader and IndexSearcher.
-
-
Constructor Details
-
LuceneIndex
public LuceneIndex() -
LuceneIndex
public LuceneIndex(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer) throws IOException Constructor for keeping backwards compatibility.- Parameters:
directory
-analyzer
-- Throws:
IOException
-
LuceneIndex
public LuceneIndex(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.similarities.Similarity similarity) throws IOException Creates a new LuceneIndex.- Parameters:
directory
- The Directory in which an index can be found and/or in which index files are written.analyzer
- The Analyzer that will be used for tokenizing strings to index and queries.similarity
- The Similarity that will be used for scoring.- Throws:
IOException
- When the Directory could not be unlocked.
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfaceSearchIndex
- Overrides:
initialize
in classAbstractSearchIndex
- Throws:
Exception
-
createDirectory
protected org.apache.lucene.store.Directory createDirectory(Properties parameters) throws IOException - Throws:
IOException
-
createAnalyzer
protected org.apache.lucene.analysis.Analyzer createAnalyzer(Properties parameters) throws Exception - Throws:
Exception
-
createSimilarity
protected org.apache.lucene.search.similarities.Similarity createSimilarity(Properties parameters) throws Exception - Throws:
Exception
-
createSpatialStrategyMapper
-
getSpatialContext
- Specified by:
getSpatialContext
in classAbstractSearchIndex
-
getDirectory
public org.apache.lucene.store.Directory getDirectory() -
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer() -
getSpatialStrategyMapper
public com.google.common.base.Function<? super String,? extends org.apache.lucene.spatial.SpatialStrategy> getSpatialStrategyMapper() -
getIndexReader
- Throws:
IOException
-
getIndexSearcher
- Throws:
IOException
-
getCurrentMonitor
Current monitor holds instance of IndexReader and IndexSearcher It is used to keep track of readers- Specified by:
getCurrentMonitor
in classAbstractLuceneIndex
-
getIndexWriter
- Throws:
IOException
-
shutDown
- Throws:
IOException
-
getDocument
- Specified by:
getDocument
in classAbstractSearchIndex
- Throws:
IOException
-
getDocuments
- Specified by:
getDocuments
in classAbstractSearchIndex
- Throws:
IOException
-
newDocument
- Specified by:
newDocument
in classAbstractSearchIndex
-
copyDocument
- Specified by:
copyDocument
in classAbstractSearchIndex
-
addDocument
- Specified by:
addDocument
in classAbstractSearchIndex
- Throws:
IOException
-
updateDocument
- Specified by:
updateDocument
in classAbstractSearchIndex
- Throws:
IOException
-
deleteDocument
- Specified by:
deleteDocument
in classAbstractSearchIndex
- Throws:
IOException
-
newBulkUpdate
- Specified by:
newBulkUpdate
in classAbstractSearchIndex
-
getDocument
public org.apache.lucene.document.Document getDocument(Resource subject, Resource context) throws IOException Returns a Document representing the specified Resource and Context combination, or null when no such Document exists yet.- Parameters:
subject
-context
-- Returns:
- document
- Throws:
IOException
-
getDocuments
Returns a list of Documents representing the specified Resource (empty when no such Document exists yet).Each document represent a set of statements with the specified Resource as a subject, which are stored in a specific context- Parameters:
subject
-- Returns:
- list of documents
- Throws:
IOException
-
addIDField
Stores and indexes an ID in a Document.- Parameters:
id
-document
-
-
addContextField
Add the "context" value to the doc- Parameters:
context
- the context or null, if null-contextdocument
- the document
-
addResourceField
public static void addResourceField(String resourceId, org.apache.lucene.document.Document document) Stores and indexes the resource ID in a Document.- Parameters:
resourceId
-document
-
-
addPredicateField
-
addStoredOnlyPredicateField
-
addTextField
-
begin
Description copied from interface:SearchIndex
Begins a transaction.- Throws:
IOException
-
commit
Commits any changes done to the LuceneIndex since the last commit. The semantics is synchronous to SailConnection.commit(), i.e. the LuceneIndex should be committed/rolled back whenever the LuceneSailConnection is committed/rolled back.- Throws:
IOException
-
rollback
- Throws:
IOException
-
query
protected Iterable<? extends DocumentScore> query(Resource subject, String query, IRI propertyURI, boolean highlight) throws MalformedQueryException, IOException Parse the passed query.- Specified by:
query
in classAbstractSearchIndex
- Parameters:
subject
-query
- stringpropertyURI
-highlight
-- Returns:
- the parsed query
- Throws:
MalformedQueryException
- when the parsing breaksIOException
-
geoQuery
protected Iterable<? extends DocumentDistance> geoQuery(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException - Specified by:
geoQuery
in classAbstractSearchIndex
- Throws:
MalformedQueryException
IOException
-
geoRelationQuery
protected Iterable<? extends DocumentResult> geoRelationQuery(String relation, IRI geoProperty, String wkt, Var contextVar) throws MalformedQueryException, IOException - Specified by:
geoRelationQuery
in classAbstractSearchIndex
- Throws:
MalformedQueryException
IOException
-
getDocument
Returns the lucene hit with the given id of the respective lucene query- Parameters:
docId
- the id of the document to returnfieldsToLoad
-- Returns:
- the requested hit, or null if it fails
-
getSnippet
-
search
public org.apache.lucene.search.TopDocs search(Resource resource, org.apache.lucene.search.Query query) throws IOException Evaluates the given query only for the given resource.- Parameters:
resource
-query
-- Returns:
- top documents
- Throws:
IOException
-
search
public org.apache.lucene.search.TopDocs search(org.apache.lucene.search.Query query) throws IOException Evaluates the given query and returns the results as a TopDocs instance.- Parameters:
query
-- Returns:
- top documents
- Throws:
IOException
-
clearContexts
Description copied from interface:SearchIndex
This should be called from within a begin-commit-rollback block.- Parameters:
contexts
-- Throws:
IOException
-
clear
Description copied from interface:SearchIndex
Clears the indexes.- Throws:
IOException
-