Repository: jena Updated Branches: refs/heads/master 5bf38bbdc -> 15d839b4e
JENA-1336: chooseTextIndex to look in ExecutionContext.getContext Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4a1d9655 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4a1d9655 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4a1d9655 Branch: refs/heads/master Commit: 4a1d965573a2dc532b572401c6234f26bb2a0935 Parents: 4f35323 Author: Andy Seaborne <[email protected]> Authored: Fri May 12 17:24:07 2017 +0100 Committer: Andy Seaborne <[email protected]> Committed: Fri May 12 17:37:23 2017 +0100 ---------------------------------------------------------------------- .../jena/query/spatial/SpatialIndexContext.java | 4 ++-- .../assembler/SpatialIndexLuceneAssembler.java | 1 + .../query/spatial/pfunction/SpatialMatch.java | 6 ++++-- .../pfunction/SpatialOperationPFBase.java | 7 +++---- .../jena/query/spatial/SpatialSearchUtil.java | 4 ++-- .../jena/query/text/DatasetGraphText.java | 2 -- .../org/apache/jena/query/text/TextQueryPF.java | 20 +++++++++++++++++--- 7 files changed, 29 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java ---------------------------------------------------------------------- diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java index fe55656..c5d392c 100644 --- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java +++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialIndexContext.java @@ -42,7 +42,8 @@ public class SpatialIndexContext { this.spatialPredicatePairValues = new HashMap<>(); } - public void index(Node g, Node s, Node p, Node o) { + @SuppressWarnings("deprecation") + public void index(Node g, Node s, Node p, Node o) { if (!o.isLiteral()) { return; @@ -95,7 +96,6 @@ public class SpatialIndexContext { pairValues.add(toAdd); } else if (defn.isWKTPredicate(p) && SpatialValueUtil.isWKTLiteral(o.getLiteral())) { - @SuppressWarnings("deprecation") Shape shape = SpatialQuery.ctx.readShape(o.getLiteralLexicalForm()); indexer.add(x, shape); } http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java ---------------------------------------------------------------------- diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java index 643b54e..31c8365 100644 --- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java +++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/assembler/SpatialIndexLuceneAssembler.java @@ -50,6 +50,7 @@ public class SpatialIndexLuceneAssembler extends AssemblerBase . */ + @SuppressWarnings("resource") @Override public SpatialIndex open(Assembler a, Resource root, Mode mode) { http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java ---------------------------------------------------------------------- diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java index 3c0c660..31d0a90 100644 --- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java +++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialMatch.java @@ -30,7 +30,8 @@ public class SpatialMatch { private final int limit; private final SpatialOperation operation; - public SpatialMatch(Double latitude, Double longitude, Double radius, + @SuppressWarnings("deprecation") + public SpatialMatch(Double latitude, Double longitude, Double radius, String units, int limit, SpatialOperation operation) { double degrees = DistanceUnitsUtils.dist2Degrees(radius, units); @@ -40,7 +41,8 @@ public class SpatialMatch { this.operation = operation; } - public SpatialMatch(Double latitude1, Double longitude1, Double latitude2, + @SuppressWarnings("deprecation") + public SpatialMatch(Double latitude1, Double longitude1, Double latitude2, Double longitude2, int limit, SpatialOperation operation) { this.shape = SpatialQuery.ctx.makeRectangle(longitude1, longitude2, latitude1, latitude2); this.limit = limit; http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java ---------------------------------------------------------------------- diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java index 0a1df9c..ec36a1c 100644 --- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java +++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java @@ -53,14 +53,13 @@ public abstract class SpatialOperationPFBase extends PropertyFunctionBase { } @Override - public void build(PropFuncArg argSubject, Node predicate, - PropFuncArg argObject, ExecutionContext execCxt) { + public void build(PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { super.build(argSubject, predicate, argObject, execCxt); DatasetGraph dsg = execCxt.getDataset(); - server = chooseTextIndex(dsg); + server = chooseTextIndex(execCxt,dsg); } - protected SpatialIndex chooseTextIndex(DatasetGraph dsg) { + protected SpatialIndex chooseTextIndex(ExecutionContext execCxt, DatasetGraph dsg) { Object obj = dsg.getContext().get(SpatialQuery.spatialIndex); if (obj != null) { http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java ---------------------------------------------------------------------- diff --git a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java index 380ac70..cff5ea6 100644 --- a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java +++ b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java @@ -55,8 +55,8 @@ public class SpatialSearchUtil { try { Directory directory = FSDirectory.open(indexDir.toPath()) ; IndexWriterConfig wConfig = new IndexWriterConfig(analyzer) ; - IndexWriter indexWriter = new IndexWriter(directory, wConfig) ; - indexWriter.close() ; // force creation of the index files + // force creation of the index files + try ( IndexWriter indexWriter = new IndexWriter(directory, wConfig) ){} } catch (IOException ex) { IO.exception(ex) ; } http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java ---------------------------------------------------------------------- diff --git a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java index 2e6ed4d..4ac491f 100644 --- a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java +++ b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java @@ -40,12 +40,10 @@ public class DatasetGraphText extends DatasetGraphMonitor implements Transaction // JENA-1302. private final Object txnExitLock = new Object(); - // If we are going to implement Transactional, then we are going to have to do as DatasetGraphWithLock and // TDB's DatasetGraphTransaction do and track transaction state in a ThreadLocal private final ThreadLocal<ReadWrite> readWriteMode = new ThreadLocal<>(); - public DatasetGraphText(DatasetGraph dsg, TextIndex index, TextDocProducer producer) { this(dsg, index, producer, false); http://git-wip-us.apache.org/repos/asf/jena/blob/4a1d9655/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java ---------------------------------------------------------------------- diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java index 78b3746..68026e3 100644 --- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java +++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java @@ -70,7 +70,7 @@ public class TextQueryPF extends PropertyFunctionBase { public void build(PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { super.build(argSubject, predicate, argObject, execCxt) ; DatasetGraph dsg = execCxt.getDataset() ; - textIndex = chooseTextIndex(dsg) ; + textIndex = chooseTextIndex(execCxt, dsg) ; if (argSubject.isList()) { int size = argSubject.getArgListSize(); @@ -90,9 +90,23 @@ public class TextQueryPF extends PropertyFunctionBase { } } - private static TextIndex chooseTextIndex(DatasetGraph dsg) { + /** + * Find the text index from: + * <ul> + * <li>The execution context. + * <li>The dataset. + * </ul> + * + * If the text index is set in the dataset context, it will have been merged + * into the execution context. This is the normal route because + * {@link TextDatasetFactory} sets the text index in the dataset context. + * Asking the dataset directly is only needed for the case of no context set, + * just in case of a unusually, progammatically constructed + * {@code DatasetGraphText} is being used (a bug, or old code, probably). + */ + private static TextIndex chooseTextIndex(ExecutionContext execCxt, DatasetGraph dsg) { - Object obj = dsg.getContext().get(TextQuery.textIndex) ; + Object obj = execCxt.getContext().get(TextQuery.textIndex) ; if (obj != null) { try {
