Skip to content

Commit 86aa4d4

Browse files
author
James Leigh
authored
Merge pull request #758 from jgrzebyta/issues/#739-spin-lucene
Fix #739: spin lucene
2 parents 6b1b26d + f8af7e6 commit 86aa4d4

27 files changed

Lines changed: 2048 additions & 406 deletions

File tree

core/sail/fts/elasticsearch/src/test/java/org/eclipse/rdf4j/sail/elasticsearch/ElasticsearchSailSpinTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

core/sail/fts/elasticsearch/src/test/java/org/eclipse/rdf4j/sail/elasticsearch/ElasticsearchSailTupleFunctionTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

core/sail/fts/elasticsearch/src/test/resources/logback-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
<logger name="org.eclipse.rdf4j.sail.lucene.AbstractLuceneSailSpinTest">
17-
<level value="warn"/>
17+
<level value="info"/>
1818
</logger>
1919

2020

core/sail/fts/lucene-api/src/main/java/org/eclipse/rdf4j/sail/lucene/LuceneSail.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.eclipse.rdf4j.sail.SailException;
4242
import org.eclipse.rdf4j.sail.evaluation.TupleFunctionEvaluationMode;
4343
import org.eclipse.rdf4j.sail.helpers.NotifyingSailWrapper;
44+
import org.eclipse.rdf4j.sail.lucene.util.SearchIndexUtils;
4445
import org.slf4j.Logger;
4546
import org.slf4j.LoggerFactory;
4647

@@ -196,9 +197,9 @@ public class LuceneSail extends NotifyingSailWrapper {
196197
final private Logger logger = LoggerFactory.getLogger(this.getClass());
197198

198199
/**
199-
* Set the parameter "reindexQuery=" to configure the statements to index over. Default value is
200-
* "SELECT ?s ?p ?o ?c WHERE {{?s ?p ?o} UNION {GRAPH ?c {?s ?p ?o.}}} ORDER BY ?s" . NB: the query must
201-
* contain the bindings ?s, ?p, ?o and ?c and must be ordered by ?s.
200+
* Set the parameter "reindexQuery=" to configure the statements to index over. Default value is "SELECT
201+
* ?s ?p ?o ?c WHERE {{?s ?p ?o} UNION {GRAPH ?c {?s ?p ?o.}}} ORDER BY ?s" . NB: the query must contain
202+
* the bindings ?s, ?p, ?o and ?c and must be ordered by ?s.
202203
*/
203204
public static final String REINDEX_QUERY_KEY = "reindexQuery";
204205

@@ -249,6 +250,12 @@ public class LuceneSail extends NotifyingSailWrapper {
249250
*/
250251
public static final String ANALYZER_CLASS_KEY = "analyzer";
251252

253+
/**
254+
* Set this key as sail parameter to configure {@link org.apache.lucene.search.similarities.Similarity}
255+
* class implementation to use for text analysis.
256+
*/
257+
public static final String SIMILARITY_CLASS_KEY = "similarity";
258+
252259
/**
253260
* Set this key as sail parameter to influence whether incomplete queries are treated as failure
254261
* (Malformed queries) or whether they are ignored. Set to either "true" or "false". When ommitted in the
@@ -387,19 +394,25 @@ public void initialize()
387394
}
388395
}
389396

397+
/**
398+
* The method is relocated to {@link SearchIndexUtils#createSearchIndex(java.util.Properties) }.
399+
*
400+
* @param parameters
401+
* @return
402+
* @throws Exception
403+
* @deprecated
404+
*/
405+
@Deprecated
390406
protected static SearchIndex createSearchIndex(Properties parameters)
391407
throws Exception
392408
{
393-
String indexClassName = parameters.getProperty(INDEX_CLASS_KEY, DEFAULT_INDEX_CLASS);
394-
SearchIndex index = (SearchIndex)Class.forName(indexClassName).newInstance();
395-
index.initialize(parameters);
396-
return index;
409+
return SearchIndexUtils.createSearchIndex(parameters);
397410
}
398411

399412
protected void initializeLuceneIndex()
400413
throws Exception
401414
{
402-
SearchIndex index = createSearchIndex(parameters);
415+
SearchIndex index = SearchIndexUtils.createSearchIndex(parameters);
403416
setLuceneIndex(index);
404417
}
405418

@@ -598,8 +611,7 @@ public Statement mapStatement(Statement statement) {
598611
}
599612

600613
protected Collection<SearchQueryInterpreter> getSearchQueryInterpreters() {
601-
return Arrays.<SearchQueryInterpreter> asList(
602-
new QuerySpecBuilder(incompleteQueryFails),
614+
return Arrays.<SearchQueryInterpreter> asList(new QuerySpecBuilder(incompleteQueryFails),
603615
new DistanceQuerySpecBuilder(luceneIndex), new GeoRelationQuerySpecBuilder(luceneIndex));
604616
}
605617
}

core/sail/fts/lucene-api/src/main/java/org/eclipse/rdf4j/sail/lucene/LuceneSailConnection.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public class LuceneSailConnection extends NotifyingSailConnectionWrapper {
9999

100100
@SuppressWarnings("unchecked")
101101
private static final Set<Class<? extends QueryModelNode>> PROJECTION_TYPES = Sets.newHashSet(
102-
Projection.class,
103-
MultiProjection.class);
102+
Projection.class, MultiProjection.class);
104103

105104
private final Logger logger = LoggerFactory.getLogger(this.getClass());
106105

@@ -184,10 +183,10 @@ public LuceneSailConnection(NotifyingSailConnection wrappedConnection, SearchInd
184183
}
185184

186185
@Override
187-
public synchronized void addStatement(Resource arg0, IRI arg1, Value arg2, Resource... arg3)
186+
public synchronized void addStatement(Resource subj, IRI pred, Value obj, Resource... contexts)
188187
throws SailException
189188
{
190-
super.addStatement(arg0, arg1, arg2, arg3);
189+
super.addStatement(subj, pred, obj, contexts);
191190
}
192191

193192
@Override
@@ -214,16 +213,16 @@ public void close()
214213
// //////////////////////////////// Methods related to indexing
215214

216215
@Override
217-
public synchronized void clear(Resource... arg0)
216+
public synchronized void clear(Resource... contexts)
218217
throws SailException
219218
{
220219
// remove the connection listener, this is safe as the changing methods
221220
// are synchronized
222221
// during the clear(), no other operation can be invoked
223222
getWrappedConnection().removeConnectionListener(connectionListener);
224223
try {
225-
super.clear(arg0);
226-
buffer.clear(arg0);
224+
super.clear(contexts);
225+
buffer.clear(contexts);
227226
}
228227
finally {
229228
getWrappedConnection().addConnectionListener(connectionListener);
@@ -252,38 +251,37 @@ public void commit()
252251

253252
logger.debug("Committing Lucene transaction with {} operations.", buffer.operations().size());
254253
try {
255-
try {
256-
// preprocess buffer
257-
buffer.optimize();
258-
259-
// run operations and remove them from buffer
260-
for (Iterator<Operation> i = buffer.operations().iterator(); i.hasNext();) {
261-
Operation op = i.next();
262-
if (op instanceof LuceneSailBuffer.AddRemoveOperation) {
263-
AddRemoveOperation addremove = (AddRemoveOperation)op;
264-
// add/remove in one call
265-
addRemoveStatements(addremove.getAdded(), addremove.getRemoved());
266-
}
267-
else if (op instanceof LuceneSailBuffer.ClearContextOperation) {
268-
// clear context
269-
clearContexts(((ClearContextOperation)op).getContexts());
270-
}
271-
else if (op instanceof LuceneSailBuffer.ClearOperation) {
272-
logger.debug("clearing index...");
273-
luceneIndex.clear();
274-
}
275-
else
276-
throw new RuntimeException(
277-
"Cannot interpret operation " + op + " of type " + op.getClass().getName());
278-
i.remove();
254+
// preprocess buffer
255+
buffer.optimize();
256+
257+
// run operations and remove them from buffer
258+
for (Iterator<Operation> i = buffer.operations().iterator(); i.hasNext();) {
259+
Operation op = i.next();
260+
if (op instanceof LuceneSailBuffer.AddRemoveOperation) {
261+
AddRemoveOperation addremove = (AddRemoveOperation)op;
262+
// add/remove in one call
263+
addRemoveStatements(addremove.getAdded(), addremove.getRemoved());
279264
}
265+
else if (op instanceof LuceneSailBuffer.ClearContextOperation) {
266+
// clear context
267+
clearContexts(((ClearContextOperation)op).getContexts());
268+
}
269+
else if (op instanceof LuceneSailBuffer.ClearOperation) {
270+
logger.debug("clearing index...");
271+
luceneIndex.clear();
272+
}
273+
else {
274+
throw new SailException(
275+
"Cannot interpret operation " + op + " of type " + op.getClass().getName());
276+
}
277+
i.remove();
280278
}
281-
catch (Exception e) {
282-
logger.error("Committing operations in lucenesail, encountered exception " + e
283-
+ ". Only some operations were stored, " + buffer.operations().size()
284-
+ " operations are discarded. Lucene Index is now corrupt.", e);
285-
throw new SailException(e);
286-
}
279+
}
280+
catch (Exception e) {
281+
logger.error("Committing operations in lucenesail, encountered exception " + e
282+
+ ". Only some operations were stored, " + buffer.operations().size()
283+
+ " operations are discarded. Lucene Index is now corrupt.", e);
284+
throw new SailException(e);
287285
}
288286
finally {
289287
buffer.reset();
@@ -610,10 +608,10 @@ private static int size(Iterable<?> iter, int defaultSize) {
610608
}
611609

612610
@Override
613-
public synchronized void removeStatements(Resource arg0, IRI arg1, Value arg2, Resource... arg3)
611+
public synchronized void removeStatements(Resource subj, IRI pred, Value obj, Resource... contexts)
614612
throws SailException
615613
{
616-
super.removeStatements(arg0, arg1, arg2, arg3);
614+
super.removeStatements(subj, pred, obj, contexts);
617615
}
618616

619617
@Override
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Eclipse RDF4J contributors, Aduna, and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*******************************************************************************/
8+
package org.eclipse.rdf4j.sail.lucene.util;
9+
10+
import java.util.Properties;
11+
import org.eclipse.rdf4j.sail.lucene.LuceneSail;
12+
import static org.eclipse.rdf4j.sail.lucene.LuceneSail.DEFAULT_INDEX_CLASS;
13+
import static org.eclipse.rdf4j.sail.lucene.LuceneSail.INDEX_CLASS_KEY;
14+
import org.eclipse.rdf4j.sail.lucene.SearchIndex;
15+
16+
/**
17+
* This is utility class with tool useful for manipulation on the {@link SearchIndex}.
18+
*
19+
* @author jacek grzebyta
20+
* @version 2.3
21+
*/
22+
public class SearchIndexUtils {
23+
24+
/**
25+
* The method creates instance of {@link SearchIndex}. The type of instantiated class depends on the value
26+
* of {@link LuceneSail#INDEX_CLASS_KEY} parameter. By default it is
27+
* <code>org.eclipse.rdf4j.sail.lucene.LuceneIndex</code>.
28+
*
29+
* @param parameters
30+
* @return
31+
* @throws Exception
32+
*/
33+
public static SearchIndex createSearchIndex(Properties parameters)
34+
throws Exception
35+
{
36+
String indexClassName = parameters.getProperty(INDEX_CLASS_KEY, DEFAULT_INDEX_CLASS);
37+
SearchIndex index = (SearchIndex)Class.forName(indexClassName).newInstance();
38+
index.initialize(parameters);
39+
return index;
40+
}
41+
}

core/sail/fts/lucene-api/src/main/resources/META-INF/services/org.eclipse.rdf4j.query.algebra.evaluation.function.TupleFunction

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)