public class LuceneSail extends NotifyingSailWrapper
// create a sesame memory sail MemoryStore memoryStore = new MemoryStore(); // create a lucenesail to wrap the memorystore LuceneSail lucenesail = new LuceneSail(); // set this parameter to store the lucene index on disk lucenesail.setParameter(LuceneSail.LUCENE_DIR_KEY, "./data/mydirectory"); // wrap memorystore in a lucenesail lucenesail.setBaseSail(memoryStore); // create a Repository to access the sails SailRepository repository = new SailRepository(lucenesail); repository.initialize();Example with storage in a RAM directory:
// create a sesame memory sail MemoryStore memoryStore = new MemoryStore(); // create a lucenesail to wrap the memorystore LuceneSail lucenesail = new LuceneSail(); // set this parameter to let the lucene index store its data in ram lucenesail.setParameter(LuceneSail.LUCENE_RAMDIR_KEY, "true"); // wrap memorystore in a lucenesail lucenesail.setBaseSail(memoryStore); // create a Repository to access the sails SailRepository repository = new SailRepository(lucenesail); repository.initialize();
SELECT Subject, Score, Snippet
FROM {Subject} {}
{};
{"my Lucene query"};
{Score};
{Snippet}
When defining queries, these properties type and query are mandatory. Also, the matches
relation is mandatory. When one of these misses, the query will not be executed as expected. The
failure behavior can be configured, setting the Sail property "incompletequeryfail" to true will throw a
SailException when such patterns are found, this is the default behavior to help finding inaccurate
queries. Set it to false to have warnings logged instead. Multiple queries can be issued to the
sail, the results of the queries will be integrated. Note that you cannot use the same variable for
multiple Text queries, if you want to combine text searches, use Lucenes query syntax.
RepositoryConnection.clear(org.eclipse.rdf4j.model.Resource[])
method with no arguments. clear(). This will delete the index.LuceneIndex#CONTEXT_NULL ("null")
and stored in the lucene field LuceneIndex#CONTEXT_FIELD_NAME ("context"). This means that when
adding/appending to a document, all additional context-uris are added to the document. When deleting
individual triples, the context is ignored. In clear(Resource ...) we make a query on all Lucene-Documents
that were possibly created by this context(s). Given a document D that context C(1-n) contributed to. D' is
the new document after clear(). - if there is only one C then D can be safely removed. There is no D' (I
hope this is the standard case: like in ontologies, where all triples about a resource are in one document)
- if there are multiple C, remember the uri of D, delete D, and query (s,p,o, ?) from the underlying store
after committing the operation- this returns the literals of D', add D' as new document This will probably
be both fast in the common case and capable enough in the multiple-C case.
INDEXEDFIELDS is to
configure which fields to index and to project a property to another. Syntax:
# only index label and comment index.1=http://www.w3.org/2000/01/rdf-schema#label index.2=http://www.w3.org/2000/01/rdf-schema#comment # project http://xmlns.com/foaf/0.1/name to rdfs:label http\://xmlns.com/foaf/0.1/name=http\://www.w3.org/2000/01/rdf-schema#label
| Modifier and Type | Field and Description |
|---|---|
static String |
ANALYZER_CLASS_KEY
Set this key as sail parameter to configure the Lucene analyzer class implementation to use for text
analysis.
|
static String |
DEFAULT_INDEX_CLASS |
static String |
INCOMPLETE_QUERY_FAIL_KEY
Set this key as sail parameter to influence whether incomplete queries are treated as failure
(Malformed queries) or whether they are ignored.
|
static String |
INDEX_CLASS_KEY
Set this key to configure the SearchIndex class implementation.
|
static String |
INDEXEDFIELDS
Set the parameter "indexedfields=..." to configure a selection of fields to index, and projections of
properties.
|
static String |
LUCENE_DIR_KEY
Set the key "lucenedir=<path>" as sail parameter to configure the Lucene Directory on the
filesystem where to store the lucene index.
|
static String |
LUCENE_RAMDIR_KEY
Set the key "useramdir=true" as sail parameter to let the LuceneSail store its Lucene index in RAM.
|
static String |
MAX_DOCUMENTS_KEY
Set the key "maxDocuments=<n>" as sail parameter to limit the maximum number of documents to
return from a search query.
|
protected Properties |
parameters |
static String |
REINDEX_QUERY_KEY
Set the parameter "reindexQuery=" to configure the statements to index over.
|
static String |
WKT_FIELDS
Set this key to configure which fields contain WKT and should be spatially indexed.
|
| Constructor and Description |
|---|
LuceneSail() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptStatementToIndex(org.eclipse.rdf4j.model.Statement s) |
NotifyingSailConnection |
getConnection() |
SearchIndex |
getLuceneIndex() |
String |
getParameter(String key) |
Set<String> |
getParameterNames() |
String |
getReindexQuery()
See REINDEX_QUERY_KEY parameter.
|
protected Collection<SearchQueryInterpreter> |
getSearchQueryInterpreters() |
void |
initialize() |
protected void |
initializeLuceneIndex() |
boolean |
isIncompleteQueryFails()
When this is true, incomplete queries will trigger a SailException.
|
org.eclipse.rdf4j.model.Statement |
mapStatement(org.eclipse.rdf4j.model.Statement statement) |
void |
registerStatementFilter(IndexableStatementFilter filter)
Sets a filter which determines whether a statement should be considered for indexing when performing
complete reindexing.
|
void |
reindex()
Starts a reindexation process of the whole sail.
|
void |
setDataDir(File dataDir) |
void |
setIncompleteQueryFails(boolean incompleteQueryFails)
Set this to true, so that incomplete queries will trigger a SailException.
|
void |
setLuceneIndex(SearchIndex luceneIndex) |
void |
setParameter(String key,
String value) |
void |
setReindexQuery(String query)
See REINDEX_QUERY_KEY parameter.
|
void |
shutDown() |
addSailChangedListener, getBaseSail, removeSailChangedListener, setBaseSailgetDataDir, getDefaultIsolationLevel, getSupportedIsolationLevels, getValueFactory, isWritable, setFederatedServiceResolver, verifyBaseSailSetclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDataDir, getDefaultIsolationLevel, getSupportedIsolationLevels, getValueFactory, isWritablepublic static final String REINDEX_QUERY_KEY
public static final String INDEXEDFIELDS
public static final String LUCENE_DIR_KEY
public static final String LUCENE_RAMDIR_KEY
public static final String MAX_DOCUMENTS_KEY
public static final String WKT_FIELDS
public static final String INDEX_CLASS_KEY
public static final String DEFAULT_INDEX_CLASS
public static final String ANALYZER_CLASS_KEY
public static final String INCOMPLETE_QUERY_FAIL_KEY
isIncompleteQueryFails()protected final Properties parameters
public void setLuceneIndex(SearchIndex luceneIndex)
public SearchIndex getLuceneIndex()
public NotifyingSailConnection getConnection() throws SailException
getConnection in interface NotifyingSailgetConnection in interface SailgetConnection in class NotifyingSailWrapperSailExceptionpublic void shutDown()
throws SailException
shutDown in interface SailshutDown in class SailWrapperSailExceptionpublic void setDataDir(File dataDir)
setDataDir in interface SailsetDataDir in class SailWrapperpublic void initialize()
throws SailException
initialize in interface Sailinitialize in class SailWrapperSailExceptionpublic String getReindexQuery()
public void setReindexQuery(String query)
public boolean isIncompleteQueryFails()
setIncompleteQueryFails(boolean) or using the parameter "incompletequeryfail"public void setIncompleteQueryFails(boolean incompleteQueryFails)
incompleteQueryFails - true or falsepublic void reindex()
throws Exception
IOExceptionExceptionpublic void registerStatementFilter(IndexableStatementFilter filter)
protected boolean acceptStatementToIndex(org.eclipse.rdf4j.model.Statement s)
public org.eclipse.rdf4j.model.Statement mapStatement(org.eclipse.rdf4j.model.Statement statement)
protected Collection<SearchQueryInterpreter> getSearchQueryInterpreters()
Copyright © 2015-2016 Eclipse Foundation. All Rights Reserved.