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
FieldsModifier and TypeFieldDescriptionprotected ReaderMonitorThis holds IndexReader and IndexSearcher.Fields inherited from class org.eclipse.rdf4j.sail.lucene.AbstractLuceneIndex
oldmonitorsFields inherited from class org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex
maxDocs, wktFields -
Constructor Summary
ConstructorsConstructorDescriptionLuceneIndex(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 voidaddContextField(String context, org.apache.lucene.document.Document document) Add the "context" value to the docprotected voidstatic voidaddIDField(String id, org.apache.lucene.document.Document document) Stores and indexes an ID in a Document.static voidaddPredicateField(String predicate, String text, org.apache.lucene.document.Document document) static voidaddResourceField(String resourceId, org.apache.lucene.document.Document document) Stores and indexes the resource ID in a Document.static voidaddStoredOnlyPredicateField(String predicate, String text, org.apache.lucene.document.Document document) static voidaddTextField(String text, org.apache.lucene.document.Document document) voidbegin()Begins a transaction.voidclear()Clears the indexes.voidclearContexts(Resource... contexts) This should be called from within a begin-commit-rollback block.voidcommit()Commits any changes done to the LuceneIndex since the last commit.protected SearchDocumentprotected org.apache.lucene.analysis.AnalyzercreateAnalyzer(Properties parameters) protected org.apache.lucene.store.DirectorycreateDirectory(Properties parameters) protected org.apache.lucene.analysis.AnalyzercreateQueryAnalyzer(Properties parameters) protected org.apache.lucene.search.similarities.SimilaritycreateSimilarity(Properties parameters) protected com.google.common.base.Function<String,? extends org.apache.lucene.spatial.SpatialStrategy> createSpatialStrategyMapper(Map<String, String> parameters) protected voidprotected 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.AnalyzerCurrent monitor holds instance of IndexReader and IndexSearcher It is used to keep track of readersorg.apache.lucene.store.Directoryorg.apache.lucene.document.DocumentgetDocument(int docId, Set<String> fieldsToLoad) Returns the lucene hit with the given id of the respective lucene queryprotected SearchDocumentgetDocument(String id) org.apache.lucene.document.DocumentgetDocument(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.IndexReaderorg.apache.lucene.search.IndexSearcherorg.apache.lucene.index.IndexWritergetSnippet(String fieldName, String text, org.apache.lucene.search.highlight.Highlighter highlighter) protected org.locationtech.spatial4j.context.SpatialContextgetSpatialContext(String property) com.google.common.base.Function<? super String,? extends org.apache.lucene.spatial.SpatialStrategy> voidinitialize(Properties parameters) protected BulkUpdaterprotected SearchDocumentnewDocument(String id, String resourceId, String context) protected Iterable<? extends DocumentScore>Parse the passed query.voidrollback()org.apache.lucene.search.TopDocssearch(org.apache.lucene.search.Query query) Evaluates the given query and returns the results as a TopDocs instance.org.apache.lucene.search.TopDocsEvaluates the given query only for the given resource.voidshutDown()protected voidMethods inherited from class org.eclipse.rdf4j.sail.lucene.AbstractLuceneIndex
getOldMonitorsMethods 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:
initializein interfaceSearchIndex- Overrides:
initializein 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
-
createQueryAnalyzer
protected org.apache.lucene.analysis.Analyzer createQueryAnalyzer(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:
getSpatialContextin 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:
getCurrentMonitorin classAbstractLuceneIndex
-
getIndexWriter
- Throws:
IOException
-
shutDown
- Throws:
IOException
-
getDocument
- Specified by:
getDocumentin classAbstractSearchIndex- Throws:
IOException
-
getDocuments
- Specified by:
getDocumentsin classAbstractSearchIndex- Throws:
IOException
-
newDocument
- Specified by:
newDocumentin classAbstractSearchIndex
-
copyDocument
- Specified by:
copyDocumentin classAbstractSearchIndex
-
addDocument
- Specified by:
addDocumentin classAbstractSearchIndex- Throws:
IOException
-
updateDocument
- Specified by:
updateDocumentin classAbstractSearchIndex- Throws:
IOException
-
deleteDocument
- Specified by:
deleteDocumentin classAbstractSearchIndex- Throws:
IOException
-
newBulkUpdate
- Specified by:
newBulkUpdatein 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:SearchIndexBegins 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, QuerySpec spec) throws MalformedQueryException, IOException Parse the passed query.- Specified by:
queryin classAbstractSearchIndex- Parameters:
subject- subjectspec- spec- 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:
geoQueryin classAbstractSearchIndex- Throws:
MalformedQueryExceptionIOException
-
geoRelationQuery
protected Iterable<? extends DocumentResult> geoRelationQuery(String relation, IRI geoProperty, String wkt, Var contextVar) throws MalformedQueryException, IOException - Specified by:
geoRelationQueryin classAbstractSearchIndex- Throws:
MalformedQueryExceptionIOException
-
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:SearchIndexThis should be called from within a begin-commit-rollback block.- Parameters:
contexts-- Throws:
IOException
-
clear
Description copied from interface:SearchIndexClears the indexes.- Throws:
IOException
-