public class LuceneIndex extends AbstractLuceneIndex
LuceneSail
Modifier and Type | Field and Description |
---|---|
protected ReaderMonitor |
currentMonitor
This holds IndexReader and IndexSearcher.
|
oldmonitors
maxDocs, wktFields
Constructor and Description |
---|
LuceneIndex() |
LuceneIndex(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.
|
Modifier and Type | Method and Description |
---|---|
static void |
addContextField(String context,
org.apache.lucene.document.Document document)
Add the "context" value to the doc
|
protected void |
addDocument(SearchDocument doc) |
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 |
copyDocument(SearchDocument doc) |
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 |
deleteDocument(SearchDocument doc) |
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,
org.locationtech.spatial4j.shape.Shape shape,
Var contextVar) |
org.apache.lucene.analysis.Analyzer |
getAnalyzer() |
ReaderMonitor |
getCurrentMonitor()
Current monitor holds instance of IndexReader and IndexSearcher It is used to keep track of readers
|
org.apache.lucene.store.Directory |
getDirectory() |
org.apache.lucene.document.Document |
getDocument(int docId,
Set<String> fieldsToLoad)
Returns the lucene hit with the given id of the respective lucene query
|
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 SearchDocument |
getDocument(String id) |
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
context
|
protected Iterable<? extends SearchDocument> |
getDocuments(String resourceId) |
org.apache.lucene.index.IndexReader |
getIndexReader() |
org.apache.lucene.search.IndexSearcher |
getIndexSearcher() |
org.apache.lucene.index.IndexWriter |
getIndexWriter() |
String |
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> |
getSpatialStrategyMapper() |
void |
initialize(Properties parameters) |
protected BulkUpdater |
newBulkUpdate() |
protected SearchDocument |
newDocument(String id,
String resourceId,
String context) |
protected SearchQuery |
parseQuery(String query,
IRI propertyURI)
Deprecated.
|
protected Iterable<? extends DocumentScore> |
query(Resource subject,
String query,
IRI propertyURI,
boolean highlight)
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 |
search(Resource resource,
org.apache.lucene.search.Query query)
Evaluates the given query only for the given resource.
|
void |
shutDown() |
protected void |
updateDocument(SearchDocument doc) |
beginReading, endReading, getOldMonitors
accept, addDocuments, addRemoveStatements, addStatement, evaluate, evaluate, getResource, isGeoField, parseQueryShape, removeStatement
protected volatile ReaderMonitor currentMonitor
public LuceneIndex()
public LuceneIndex(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer) throws IOException
directory
- analyzer
- IOException
public LuceneIndex(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.similarities.Similarity similarity) throws IOException
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.IOException
- When the Directory could not be unlocked.public void initialize(Properties parameters) throws Exception
initialize
in interface SearchIndex
initialize
in class AbstractSearchIndex
Exception
protected org.apache.lucene.store.Directory createDirectory(Properties parameters) throws IOException
IOException
protected org.apache.lucene.analysis.Analyzer createAnalyzer(Properties parameters) throws Exception
Exception
protected org.apache.lucene.search.similarities.Similarity createSimilarity(Properties parameters) throws Exception
Exception
protected com.google.common.base.Function<String,? extends org.apache.lucene.spatial.SpatialStrategy> createSpatialStrategyMapper(Map<String,String> parameters)
protected org.locationtech.spatial4j.context.SpatialContext getSpatialContext(String property)
getSpatialContext
in class AbstractSearchIndex
public org.apache.lucene.store.Directory getDirectory()
public org.apache.lucene.analysis.Analyzer getAnalyzer()
public com.google.common.base.Function<? super String,? extends org.apache.lucene.spatial.SpatialStrategy> getSpatialStrategyMapper()
public org.apache.lucene.index.IndexReader getIndexReader() throws IOException
IOException
public org.apache.lucene.search.IndexSearcher getIndexSearcher() throws IOException
IOException
public ReaderMonitor getCurrentMonitor()
getCurrentMonitor
in class AbstractLuceneIndex
public org.apache.lucene.index.IndexWriter getIndexWriter() throws IOException
IOException
public void shutDown() throws IOException
IOException
protected SearchDocument getDocument(String id) throws IOException
getDocument
in class AbstractSearchIndex
IOException
protected Iterable<? extends SearchDocument> getDocuments(String resourceId) throws IOException
getDocuments
in class AbstractSearchIndex
IOException
protected SearchDocument newDocument(String id, String resourceId, String context)
newDocument
in class AbstractSearchIndex
protected SearchDocument copyDocument(SearchDocument doc)
copyDocument
in class AbstractSearchIndex
protected void addDocument(SearchDocument doc) throws IOException
addDocument
in class AbstractSearchIndex
IOException
protected void updateDocument(SearchDocument doc) throws IOException
updateDocument
in class AbstractSearchIndex
IOException
protected void deleteDocument(SearchDocument doc) throws IOException
deleteDocument
in class AbstractSearchIndex
IOException
protected BulkUpdater newBulkUpdate()
newBulkUpdate
in class AbstractSearchIndex
public org.apache.lucene.document.Document getDocument(Resource subject, Resource context) throws IOException
subject
- context
- IOException
public List<org.apache.lucene.document.Document> getDocuments(Resource subject) throws IOException
subject
- IOException
public static void addIDField(String id, org.apache.lucene.document.Document document)
id
- document
- public static void addContextField(String context, org.apache.lucene.document.Document document)
context
- the context or null, if null-contextdocument
- the documentpublic static void addResourceField(String resourceId, org.apache.lucene.document.Document document)
resourceId
- document
- public static void addPredicateField(String predicate, String text, org.apache.lucene.document.Document document)
public static void addStoredOnlyPredicateField(String predicate, String text, org.apache.lucene.document.Document document)
public static void addTextField(String text, org.apache.lucene.document.Document document)
public void begin() throws IOException
SearchIndex
IOException
public void commit() throws IOException
IOException
public void rollback() throws IOException
IOException
@Deprecated protected SearchQuery parseQuery(String query, IRI propertyURI) throws MalformedQueryException
parseQuery
in class AbstractSearchIndex
query
- stringorg.apache.lucene.queryparser.classic.ParseException
- when the parsing brakesMalformedQueryException
protected Iterable<? extends DocumentScore> query(Resource subject, String query, IRI propertyURI, boolean highlight) throws MalformedQueryException, IOException
query
in class AbstractSearchIndex
query
- stringorg.apache.lucene.queryparser.classic.ParseException
- when the parsing brakesMalformedQueryException
IOException
protected Iterable<? extends DocumentDistance> geoQuery(IRI geoProperty, org.locationtech.spatial4j.shape.Point p, IRI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException
geoQuery
in class AbstractSearchIndex
MalformedQueryException
IOException
protected Iterable<? extends DocumentResult> geoRelationQuery(String relation, IRI geoProperty, org.locationtech.spatial4j.shape.Shape shape, Var contextVar) throws MalformedQueryException, IOException
geoRelationQuery
in class AbstractSearchIndex
MalformedQueryException
IOException
public org.apache.lucene.document.Document getDocument(int docId, Set<String> fieldsToLoad)
docId
- the id of the document to returnfieldsToLoad
- public String getSnippet(String fieldName, String text, org.apache.lucene.search.highlight.Highlighter highlighter)
public org.apache.lucene.search.TopDocs search(Resource resource, org.apache.lucene.search.Query query) throws IOException
resource
- query
- IOException
public org.apache.lucene.search.TopDocs search(org.apache.lucene.search.Query query) throws IOException
query
- IOException
public void clearContexts(Resource... contexts) throws IOException
SearchIndex
contexts
- IOException
public void clear() throws IOException
SearchIndex
IOException
Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.