Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Add support for s2 indexing #18

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
public class GeoSparqlConfig {
public enum PrefixTree {
GEOHASH(SimpleValueFactory.getInstance().createLiteral("geohash")),
QUAD(SimpleValueFactory.getInstance().createLiteral("quad"));
QUAD(SimpleValueFactory.getInstance().createLiteral("quad")),
S2(SimpleValueFactory.getInstance().createLiteral("s2"));

private Literal literal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
import org.apache.lucene.spatial.prefix.tree.S2PrefixTree;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.apache.lucene.spatial.serialized.SerializedDVStrategy;
Expand Down Expand Up @@ -100,6 +101,8 @@ public void initSettings() {
grid = new QuadPrefixTree(ctx, precision);
} else if (prefixTree == GeoSparqlConfig.PrefixTree.GEOHASH) {
grid = new GeohashPrefixTree(ctx, precision);
} else if (prefixTree == GeoSparqlConfig.PrefixTree.S2) {
grid = new S2PrefixTree(ctx, precision);
} else {
throw new PluginException("Unexpected prefix tree type: " + prefixTree);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public static void validateParams(GeoSparqlConfig.PrefixTree prefixTree, int pre
if (precision <= 0 || precision > QuadPrefixTree.MAX_LEVELS_POSSIBLE) {
throw new PluginException(constructExceptionMessage(prefixTree));
}
case S2:
if (precision <= 0) {
throw new PluginException(constructExceptionMessage(prefixTree));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public void testCanSaveAndRead2() {
test(false, GeoSparqlConfig.PrefixTree.GEOHASH, 7, GeoSparqlConfig.PrefixTree.QUAD, 12, false);
}

@Test
public void testCanSaveAndRead3() {
test(false, GeoSparqlConfig.PrefixTree.S2, 7, GeoSparqlConfig.PrefixTree.S2, 12, false);
}

private void test(boolean enabled, GeoSparqlConfig.PrefixTree prefixTree, int precision,
GeoSparqlConfig.PrefixTree currentPrefixTree, int currentPrecision, boolean ignoreErrors) {
GeoSparqlConfig config1 = new GeoSparqlConfig();
Expand Down