diff --git a/.jenkins.yml b/.jenkins.yml new file mode 100644 index 000000000..2d58f9715 --- /dev/null +++ b/.jenkins.yml @@ -0,0 +1,14 @@ +ATSERVICES: + - CASSANDRA: + image: stratio/cassandra-lucene-index:%%VERSION + sleep: 30 + volumes: + - jts:1.14.0 + env: + - LOCAL_JMX=no + +ATPARAMETERS: > + -Dit.host=%%CASSANDRA + -DJACOCO_SERVER=%%CASSANDRA + -Dit-embedded=false + diff --git a/CHANGELOG.md b/CHANGELOG.md index 604a4d296..47ea6e965 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 3.0.7.3 (Upcoming) + +Merged from 3.0.8.2: +* Allow associativity in search-time geospatial transformations +* Simplify naming of builder static methods for creating geospatial transformations +* Fix paged index-sorted queries matching more than 65535 rows +* Fix partition directed queries using dummy column syntax in skinny tables +Merged from 3.0.8.1: +* Upgrade query builder JSON serializer to Jackson 2.8.0 +* Add geospatial post filtering (ensures accuracy with any tree levels) +* Set default number of indexing threads to number of processors available to the JVM +* Fix mapping of timestamps and dates by their underlying numeric value (#177) + +Merged from 2.2.7.1: +* Fix mapper referenced by alias in sortFields + ## 3.0.7.2 (July 05, 2016) * Modernize search syntax keeping backward compatibility diff --git a/README.rst b/README.rst index d839b19fe..491edb33a 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,7 @@ Stratio’s Cassandra Lucene Index and its integration with Lucene search techno - Full text search (language-aware analysis, wildcard, fuzzy, regexp) - Boolean search (and, or, not) -- Sorting by relevance, column value, and distance) +- Sorting by relevance, column value, and distance - Geospatial indexing (points, lines, polygons and their multiparts) - Geospatial transformations (bounding box, buffer, centroid, convex hull, union, difference, intersection) - Geospatial operations (intersects, contains, is within) @@ -145,15 +145,15 @@ We will create the following table to store tweets: .. code-block:: sql CREATE KEYSPACE demo - WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor': 1}; + WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}; USE demo; CREATE TABLE tweets ( - id INT PRIMARY KEY, - user TEXT, - body TEXT, - time TIMESTAMP, - latitude FLOAT, - longitude FLOAT + id INT PRIMARY KEY, + user TEXT, + body TEXT, + time TIMESTAMP, + latitude FLOAT, + longitude FLOAT ); Now you can create a custom Lucene index on it with the following statement: @@ -163,16 +163,16 @@ Now you can create a custom Lucene index on it with the following statement: CREATE CUSTOM INDEX tweets_index ON tweets () USING 'com.stratio.cassandra.lucene.Index' WITH OPTIONS = { - 'refresh_seconds' : '1', - 'schema' : '{ - fields : { - id : {type : "integer"}, - user : {type : "string"}, - body : {type : "text", analyzer : "english"}, - time : {type : "date", pattern : "yyyy/MM/dd"}, - place : {type : "geo_point", latitude: "latitude", longitude: "longitude"} - } - }' + 'refresh_seconds': '1', + 'schema': '{ + fields: { + id: {type: "integer"}, + user: {type: "string"}, + body: {type: "text", analyzer: "english"}, + time: {type: "date", pattern: "yyyy/MM/dd"}, + place: {type: "geo_point", latitude: "latitude", longitude: "longitude"} + } + }' }; This will index all the columns in the table with the specified types, and it will be refreshed once per second. @@ -189,7 +189,7 @@ Now, to search for tweets within a certain date range: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"} + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"} }'); The same search can be performed forcing an explicit refresh of the involved index shards: @@ -197,8 +197,8 @@ The same search can be performed forcing an explicit refresh of the involved ind .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - refresh : true + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + refresh: true }') limit 100; Now, to search the top 100 more relevant tweets where *body* field contains the phrase “big data gives organizations” @@ -207,8 +207,8 @@ within the aforementioned date range: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} }') LIMIT 100; To refine the search to get only the tweets written by users whose names start with "a": @@ -216,9 +216,11 @@ To refine the search to get only the tweets written by users whose names start w .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} }') LIMIT 100; To get the 100 more recent filtered results you can use the *sort* option: @@ -226,10 +228,12 @@ To get the 100 more recent filtered results you can use the *sort* option: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : {field: "time", reverse: true} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: {field: "time", reverse: true} }') limit 100; The previous search can be restricted to tweets created close to a geographical position: @@ -237,11 +241,13 @@ The previous search can be restricted to tweets created close to a geographical .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : {field: "time", reverse: true} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: {field: "time", reverse: true} }') limit 100; It is also possible to sort the results by distance to a geographical position: @@ -249,12 +255,16 @@ It is also possible to sort the results by distance to a geographical position: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : [ {field: "time", reverse: true}, - {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328}] + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: [ + {field: "time", reverse: true}, + {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} + ] }') limit 100; Last but not least, you can route any search to a certain token range or partition, in such a way that only a @@ -263,12 +273,16 @@ subset of the cluster nodes will be hit, saving precious resources: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : [ {field: "time", reverse: true}, - {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328}] + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: [ + {field: "time", reverse: true}, + {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} + ] }') AND TOKEN(id) >= TOKEN(0) AND TOKEN(id) < TOKEN(10000000) limit 100; This last is the basis for `Hadoop, Spark and other MapReduce frameworks support `__. diff --git a/builder/pom.xml b/builder/pom.xml index 17ed0adea..36ff6f512 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -36,9 +36,14 @@ - org.codehaus.jackson - jackson-mapper-asl - 1.9.2 + com.fasterxml.jackson.core + jackson-core + 2.8.0 + + + com.fasterxml.jackson.core + jackson-databind + 2.8.0 junit diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/Builder.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/Builder.java index 9a3f45053..7de6e842d 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/Builder.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/Builder.java @@ -15,6 +15,7 @@ */ package com.stratio.cassandra.lucene.builder; +import com.stratio.cassandra.lucene.builder.common.GeoShape; import com.stratio.cassandra.lucene.builder.common.GeoTransformation; import com.stratio.cassandra.lucene.builder.index.Index; import com.stratio.cassandra.lucene.builder.index.schema.Schema; @@ -26,6 +27,10 @@ import com.stratio.cassandra.lucene.builder.search.sort.GeoDistanceSortField; import com.stratio.cassandra.lucene.builder.search.sort.SimpleSortField; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * Utility class for creating Lucene index statements. * @@ -456,111 +461,299 @@ public static GeoDistanceCondition geoDistance(String field, } /** - * Returns a new {@link GeoShapeCondition} with the specified field reference point. + * Returns a new {@link GeoShapeCondition} with the specified shape. * * @param field the name of the field - * @param shape the shape in WKT format + * @param shape the shape * @return a new geos hape condition */ - public static GeoShapeCondition geoShape(String field, String shape) { + public static GeoShapeCondition geoShape(String field, GeoShape shape) { return new GeoShapeCondition(field, shape); } /** - * Returns a new {@link GeoTransformation.BBox}. + * Returns a new {@link GeoShapeCondition} with the specified shape. + * + * @param field the name of the field + * @param shape the shape in WKT format + * @return a new geos hape condition + */ + public static GeoShapeCondition geoShape(String field, String shape) { + return geoShape(field, wkt(shape)); + } + + /** + * Returns a new {@link DateRangeCondition} with the specified field reference point. + * + * @param field the name of the field to be matched + * @return a new date range condition + */ + public static DateRangeCondition dateRange(String field) { + return new DateRangeCondition(field); + } + + /** + * Returns a new {@link SimpleSortField} for the specified field. + * + * @param field the name of the field to be sorted + * @return a new simple sort field + */ + public static SimpleSortField field(String field) { + return new SimpleSortField(field); + } + + /** + * Returns a new {@link GeoDistanceSortField} for the specified field. + * + * @param field the name of the geo point field mapper to be used for sorting + * @param latitude the latitude in degrees of the point to min distance sort by + * @param longitude the longitude in degrees of the point to min distance sort by + * @return a new geo distance sort field + */ + public static GeoDistanceSortField geoDistance(String field, double latitude, double longitude) { + return new GeoDistanceSortField(field, latitude, longitude); + } + + /** + * Returns a new {@link GeoTransformation.BBox} transformation to be applied to {@link GeoShapeMapper}s. * * @return a new bbox transformation */ - public static GeoTransformation.BBox bboxGeoTransformation() { + public static GeoTransformation.BBox bbox() { return new GeoTransformation.BBox(); } /** - * Returns a new {@link GeoTransformation.Buffer}. + * Returns a new {@link GeoTransformation.Buffer} transformation to be applied to {@link GeoShapeMapper}s. * * @return a new buffer transformation */ - public static GeoTransformation.Buffer bufferGeoTransformation() { + public static GeoTransformation.Buffer buffer() { return new GeoTransformation.Buffer(); } /** - * Returns a new {@link GeoTransformation.Centroid}. + * Returns a new {@link GeoTransformation.Centroid} transformation to be applied to {@link GeoShapeMapper}s. * * @return a new centroid transformation */ - public static GeoTransformation.Centroid centroidGeoTransformation() { + public static GeoTransformation.Centroid centroid() { return new GeoTransformation.Centroid(); } /** - * Returns a new {@link GeoTransformation.Centroid}. + * Returns a new {@link GeoTransformation.Centroid} transformation to be applied to {@link GeoShapeMapper}s. * * @return a new convex hull transformation */ - public static GeoTransformation.ConvexHull convexHullGeoTransformation() { + public static GeoTransformation.ConvexHull convexHull() { return new GeoTransformation.ConvexHull(); } /** - * Returns a new {@link GeoTransformation.Difference}. + * Returns a new {@link GeoShape.WKT}. + * + * @param value the WKT string value + * @return a new bbox transformation + */ + public static GeoShape.WKT wkt(String value) { + return new GeoShape.WKT(value); + } + + /** + * Returns a new {@link GeoShape.BBox}, representing the bounding box around the specified {@link GeoShape}. + * + * @param shape the base shape + * @return a new bbox transformation + */ + public static GeoShape.BBox bbox(GeoShape shape) { + return new GeoShape.BBox(shape); + } + + /** + * Returns a new {@link GeoShape.BBox}, representing the bounding box around the specified WKT shape. + * + * @param shape the base shape in WKT format + * @return a new bbox transformation + */ + public static GeoShape.BBox bbox(String shape) { + return bbox(wkt(shape)); + } + + /** + * Returns a new {@link GeoShape.Buffer}, representing a buffer around the specified {@link GeoShape}. + * + * @param shape the base shape + * @return a new buffer transformation + */ + public static GeoShape.Buffer buffer(GeoShape shape) { + return new GeoShape.Buffer(shape); + } + + /** + * Returns a new {@link GeoShape.Buffer}, representing a buffer around the specified WKT shape. + * + * @param shape the base shape in WKT format + * @return a new buffer transformation + */ + public static GeoShape.Buffer buffer(String shape) { + return buffer(wkt(shape)); + } + + /** + * Returns a new {@link GeoShape.Centroid}, representing the centroid of the specified {@link GeoShape}. + * + * @param shape the base shape + * @return a new centroid transformation + */ + public static GeoShape.Centroid centroid(GeoShape shape) { + return new GeoShape.Centroid(shape); + } + + /** + * Returns a new {@link GeoShape.Centroid}, representing the centroid of the specified WKT shape. + * + * @param shape the base shape in WKT format + * @return a new centroid transformation + */ + public static GeoShape.Centroid centroid(String shape) { + return centroid(wkt(shape)); + } + + /** + * Returns a new {@link GeoShape.ConvexHull}, representing the convex hull of the specified {@link GeoShape}. + * + * @param shape the base shape + * @return a new convex hull transformation + */ + public static GeoShape.ConvexHull convexHull(GeoShape shape) { + return new GeoShape.ConvexHull(shape); + } + + /** + * Returns a new {@link GeoShape.ConvexHull}, representing the convex hull of the specified WKT shape. + * + * @param shape the base shape in WKT format + * @return a new convex hull transformation + */ + public static GeoShape.ConvexHull convexHull(String shape) { + return convexHull(wkt(shape)); + } + + /** + * Returns a new empty {@link GeoShape.Difference}. + * + * @return a new difference transformation + */ + public static GeoShape.Difference difference() { + return new GeoShape.Difference(); + } + + /** + * Returns a new {@link GeoShape.Difference}, representing the difference of the specified {@link GeoShape}s. + * + * @param shapes the shapes to be subtracted + * @return a new difference transformation + */ + public static GeoShape.Difference difference(GeoShape... shapes) { + return new GeoShape.Difference(shapes); + } + + /** + * Returns a new {@link GeoShape.Difference}, representing the difference of the specified {@link GeoShape}s. + * + * @param shapes the shapes to be subtracted + * @return a new difference transformation + */ + public static GeoShape.Difference difference(List shapes) { + return new GeoShape.Difference(shapes); + } + + /** + * Returns a new {@link GeoShape.Difference}, representing the difference of the specified WKT shapes. * - * @param shape the shape to be subtracted + * @param shapes the shapes to be subtracted in WKT format * @return a new difference transformation */ - public static GeoTransformation.Difference differenceGeoTransformation(String shape) { - return new GeoTransformation.Difference(shape); + public static GeoShape.Difference difference(String... shapes) { + return difference(Stream.of(shapes).map(Builder::wkt).collect(Collectors.toList())); } /** - * Returns a new {@link GeoTransformation.Intersection}. + * Returns a new empty {@link GeoShape.Intersection}. * - * @param shape the shape to be intersected * @return a new intersection transformation */ - public static GeoTransformation.Intersection intersectionGeoTransformation(String shape) { - return new GeoTransformation.Intersection(shape); + public static GeoShape.Intersection intersection() { + return new GeoShape.Intersection(); } /** - * Returns a new {@link GeoTransformation.Union}. + * Returns a new {@link GeoShape.Intersection}, representing the intersection of the specified {@link GeoShape}s. + * + * @param shapes the shapes to be intersected + * @return a new intersection transformation + */ + public static GeoShape.Intersection intersection(GeoShape... shapes) { + return new GeoShape.Intersection(shapes); + } + + /** + * Returns a new {@link GeoShape.Intersection}, representing the intersection of the specified {@link GeoShape}s. + * + * @param shapes the shapes to be intersected + * @return a new intersection transformation + */ + public static GeoShape.Intersection intersection(List shapes) { + return new GeoShape.Intersection(shapes); + } + + /** + * Returns a new {@link GeoShape.Intersection}, representing the intersection of the specified WKT shapes. + * + * @param shapes the shapes to be intersected + * @return a new intersection transformation + */ + public static GeoShape.Intersection intersection(String... shapes) { + return intersection(Stream.of(shapes).map(Builder::wkt).collect(Collectors.toList())); + } + + /** + * Returns a new empty {@link GeoShape.Union}. * - * @param shape the shape to be added * @return a new union transformation */ - public static GeoTransformation.Union unionGeoTransformation(String shape) { - return new GeoTransformation.Union(shape); + public static GeoShape.Union union() { + return new GeoShape.Union(); } /** - * Returns a new {@link DateRangeCondition} with the specified field reference point. + * Returns a new {@link GeoShape.Union}, representing the union of the specified {@link GeoShape}s. * - * @param field the name of the field to be matched - * @return a new date range condition + * @param shapes the shapes to be added + * @return a new union transformation */ - public static DateRangeCondition dateRange(String field) { - return new DateRangeCondition(field); + public static GeoShape.Union union(GeoShape... shapes) { + return new GeoShape.Union(shapes); } /** - * Returns a new {@link SimpleSortField} for the specified field. + * Returns a new {@link GeoShape.Union}, representing the union of the specified {@link GeoShape}s. * - * @param field the name of the field to be sorted - * @return a new simple sort field + * @param shapes the shapes to be added + * @return a new union transformation */ - public static SimpleSortField field(String field) { - return new SimpleSortField(field); + public static GeoShape.Union union(List shapes) { + return new GeoShape.Union(shapes); } /** - * Returns a new {@link GeoDistanceSortField} for the specified field. + * Returns a new {@link GeoShape.Union}, representing the union of the specified WKT shapes. * - * @param field the name of the geo point field mapper to be used for sorting - * @param latitude the latitude in degrees of the point to min distance sort by - * @param longitude the longitude in degrees of the point to min distance sort by - * @return a new geo distance sort field + * @param shapes the shapes to be subtracted in WKT format + * @return a new difference transformation */ - public static GeoDistanceSortField geoDistanceField(String field, double latitude, double longitude) { - return new GeoDistanceSortField(field, latitude, longitude); + public static GeoShape.Union union(String... shapes) { + return union(Stream.of(shapes).map(Builder::wkt).collect(Collectors.toList())); } } diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/JSONBuilder.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/JSONBuilder.java index f779d2c6b..c03ad1283 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/JSONBuilder.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/JSONBuilder.java @@ -15,12 +15,11 @@ */ package com.stratio.cassandra.lucene.builder; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.map.annotate.JsonSerialize; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.*; import java.io.IOException; import java.util.ArrayList; @@ -40,10 +39,10 @@ public abstract class JSONBuilder { static { mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - mapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, false); - mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true); - mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); - mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); + mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } /** {@inheritDoc} */ diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoShape.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoShape.java new file mode 100644 index 000000000..38acbb67c --- /dev/null +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoShape.java @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2014 Stratio (http://stratio.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.stratio.cassandra.lucene.builder.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.stratio.cassandra.lucene.builder.JSONBuilder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Andres de la Pena {@literal } + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonSubTypes({@JsonSubTypes.Type(value = GeoShape.WKT.class, name = "wkt"), + @JsonSubTypes.Type(value = GeoShape.BBox.class, name = "bbox"), + @JsonSubTypes.Type(value = GeoShape.Buffer.class, name = "buffer"), + @JsonSubTypes.Type(value = GeoShape.Centroid.class, name = "centroid"), + @JsonSubTypes.Type(value = GeoShape.ConvexHull.class, name = "convex_hull"), + @JsonSubTypes.Type(value = GeoShape.Difference.class, name = "difference"), + @JsonSubTypes.Type(value = GeoShape.Intersection.class, name = "intersection"), + @JsonSubTypes.Type(value = GeoShape.Union.class, name = "union")}) +public abstract class GeoShape extends JSONBuilder { + + /** + * {@link GeoShape} in WKT format. + */ + public static class WKT extends GeoShape { + + /** The WKT representation of the shape. **/ + @JsonProperty("value") + final String value; + + /** + * Constructor taking the WKT representation of the shape. + * + * @param value the WKT value + */ + public WKT(String value) { + this.value = value; + } + + } + + /** + * {@link GeoShape} that gets the bounding box of a geographical shape. The bounding box of shape is + * the minimal rectangle containing the shape. + */ + public static class BBox extends GeoShape { + + /** The base shape. **/ + @JsonProperty("shape") + final GeoShape shape; + + /** + * Constructor taking the shape. + * + * @param shape a shape + */ + public BBox(GeoShape shape) { + this.shape = shape; + } + + } + + /** + * {@link GeoShape} for getting the buffer around a geographical shape. + */ + public static class Buffer extends GeoShape { + + /** The shape to be buffered. **/ + @JsonProperty("shape") + final GeoShape shape; + + /** The max allowed distance. */ + @JsonProperty("max_distance") + String maxDistance; + + /** The min allowed distance. */ + @JsonProperty("min_distance") + String minDistance; + + /** + * Constructor taking the shape. + * + * @param shape a shape + */ + public Buffer(GeoShape shape) { + this.shape = shape; + } + + /** + * Sets the max allowed distance. + * + * @param maxDistance the max distance + * @return this with the specified max distance + */ + public Buffer maxDistance(String maxDistance) { + this.maxDistance = maxDistance; + return this; + } + + /** + * Sets the min allowed distance. + * + * @param minDistance the min distance + * @return this with the specified min distance + */ + public Buffer minDistance(String minDistance) { + this.minDistance = minDistance; + return this; + } + } + + /** + * {@link GeoShape} that gets the center point of a geographical shape. + */ + public static class Centroid extends GeoShape { + + /** The shape. **/ + @JsonProperty("shape") + final GeoShape shape; + + /** + * Constructor taking the shape. + * + * @param shape a shape + */ + public Centroid(GeoShape shape) { + this.shape = shape; + } + + } + + /** + * {@link GeoShape} that gets the convex hull of a geographical shape. + */ + public static class ConvexHull extends GeoShape { + + /** The shape. **/ + @JsonProperty("shape") + final GeoShape shape; + + /** + * Constructor taking the shape. + * + * @param shape a shape + */ + public ConvexHull(GeoShape shape) { + this.shape = shape; + } + + } + + /** + * {@link GeoShape} that gets the difference of two geographical shapes. + */ + public static class Difference extends GeoShape { + + /** The shapes to be subtracted. */ + @JsonProperty("shapes") + public final List shapes; + + /** + * Constructor receiving the shapes to be subtracted. + * + * @param shapes the shapes to be subtracted + */ + public Difference(GeoShape... shapes) { + this(new ArrayList<>(Arrays.asList(shapes))); + } + + /** + * Constructor receiving the shapes to be subtracted. + * + * @param shapes the shapes to be subtracted + */ + public Difference(List shapes) { + this.shapes = shapes; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be subtracted. + * + * @param shape the shape to be added + * @return this with the specified shape + */ + public Difference add(GeoShape shape) { + shapes.add(shape); + return this; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be subtracted. + * + * @param shape the shape to be added in WKT format + * @return this with the specified shape + */ + public Difference add(String shape) { + shapes.add(new WKT(shape)); + return this; + } + + } + + /** + * {@link GeoShape} that gets the intersection of two geographical shapes. + */ + public static class Intersection extends GeoShape { + + /** The shapes to be intersected. */ + @JsonProperty("shapes") + public final List shapes; + + /** + * Constructor receiving the shapes to be intersected. + * + * @param shapes the shapes to be intersected + */ + public Intersection(GeoShape... shapes) { + this(new ArrayList<>(Arrays.asList(shapes))); + } + + /** + * Constructor receiving the shapes to be intersected. + * + * @param shapes the shapes to be intersected + */ + public Intersection(List shapes) { + this.shapes = shapes; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be intersected. + * + * @param shape the shape to be added + * @return this with the specified shape + */ + public Intersection add(GeoShape shape) { + shapes.add(shape); + return this; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be intersected. + * + * @param shape the shape to be added in WKT format + * @return this with the specified shape + */ + public Intersection add(String shape) { + shapes.add(new WKT(shape)); + return this; + } + + } + + /** + * {@link GeoShape} that gets the union of two geographical shapes. + */ + public static class Union extends GeoShape { + + /** The shapes to be added. */ + @JsonProperty("shapes") + public final List shapes; + + /** + * Constructor receiving the shapes to be added. + * + * @param shapes the shapes to be added + */ + public Union(GeoShape... shapes) { + this(new ArrayList<>(Arrays.asList(shapes))); + } + + /** + * Constructor receiving the shapes to be added. + * + * @param shapes the shapes to be added + */ + public Union(List shapes) { + this.shapes = shapes; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be added. + * + * @param shape the shape to be added + * @return this with the specified shape + */ + public Union add(GeoShape shape) { + shapes.add(shape); + return this; + } + + /** + * Adds the specified {@link GeoShape} to the shapes to be added. + * + * @param shape the shape to be added in WKT format + * @return this with the specified shape + */ + public Union add(String shape) { + shapes.add(new WKT(shape)); + return this; + } + + } + +} + diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoTransformation.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoTransformation.java index 2d5669e41..33c55ca26 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoTransformation.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoTransformation.java @@ -15,10 +15,10 @@ */ package com.stratio.cassandra.lucene.builder.common; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.stratio.cassandra.lucene.builder.JSONBuilder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.annotate.JsonSubTypes; -import org.codehaus.jackson.annotate.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Andres de la Pena {@literal } @@ -27,10 +27,7 @@ @JsonSubTypes({@JsonSubTypes.Type(value = GeoTransformation.BBox.class, name = "bbox"), @JsonSubTypes.Type(value = GeoTransformation.Buffer.class, name = "buffer"), @JsonSubTypes.Type(value = GeoTransformation.Centroid.class, name = "centroid"), - @JsonSubTypes.Type(value = GeoTransformation.ConvexHull.class, name = "convex_hull"), - @JsonSubTypes.Type(value = GeoTransformation.Difference.class, name = "difference"), - @JsonSubTypes.Type(value = GeoTransformation.Intersection.class, name = "intersection"), - @JsonSubTypes.Type(value = GeoTransformation.Union.class, name = "union")}) + @JsonSubTypes.Type(value = GeoTransformation.ConvexHull.class, name = "convex_hull")}) public abstract class GeoTransformation extends JSONBuilder { /** @@ -42,7 +39,7 @@ public static class BBox extends GeoTransformation { } /** - * {@link GeoTransformation} for getting the bounding shape of a JTS geographical shape. + * {@link GeoTransformation} for getting the buffer around a JTS geographical shape. */ public static class Buffer extends GeoTransformation { @@ -91,65 +88,5 @@ public static class ConvexHull extends GeoTransformation { } - /** - * {@link GeoTransformation} that gets the difference of two JTS geographical shapes. - */ - public static class Difference extends GeoTransformation { - - /** The other shape. */ - @JsonProperty("shape") - public final String shape; - - /** - * Constructor receiving the geometry to be subtracted. - * - * @param shape the geometry to be subtracted in WKT format - */ - public Difference(String shape) { - this.shape = shape; - } - - } - - /** - * {@link GeoTransformation} that gets the intersection of two JTS geographical shapes. - */ - public static class Intersection extends GeoTransformation { - - /** The other shape. */ - @JsonProperty("shape") - public final String shape; - - /** - * Constructor receiving the geometry to be intersected. - * - * @param shape the geometry to be intersected in WKT format - */ - public Intersection(String shape) { - this.shape = shape; - } - - } - - /** - * {@link GeoTransformation} that gets the union of two JTS geographical shapes. - */ - public static class Union extends GeoTransformation { - - /** The other shape. */ - @JsonProperty("shape") - public final String shape; - - /** - * Constructor receiving the geometry to be added. - * - * @param shape the geometry to be added in WKT format - */ - public Union(String shape) { - this.shape = shape; - } - - } - } diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/Schema.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/Schema.java index c596877a1..41afc7f51 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/Schema.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/Schema.java @@ -18,7 +18,7 @@ import com.stratio.cassandra.lucene.builder.JSONBuilder; import com.stratio.cassandra.lucene.builder.index.schema.analysis.Analyzer; import com.stratio.cassandra.lucene.builder.index.schema.mapping.Mapper; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.LinkedHashMap; import java.util.Map; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/Analyzer.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/Analyzer.java index d50cbfd2b..196c6ed1a 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/Analyzer.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/Analyzer.java @@ -15,9 +15,9 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.analysis; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.stratio.cassandra.lucene.builder.JSONBuilder; -import org.codehaus.jackson.annotate.JsonSubTypes; -import org.codehaus.jackson.annotate.JsonTypeInfo; /** * A Lucene {@code Analyzer}. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/ClasspathAnalyzer.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/ClasspathAnalyzer.java index 9678115d5..b145624dc 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/ClasspathAnalyzer.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/ClasspathAnalyzer.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.analysis; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * {@link Analyzer} using a Lucene's {@code Analyzer}s in classpath. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/SnowballAnalyzer.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/SnowballAnalyzer.java index 92e5646fc..db9bf3a78 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/SnowballAnalyzer.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/analysis/SnowballAnalyzer.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.analysis; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * {@link Analyzer} for tartarus.org snowball {@code Analyzer}. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigDecimalMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigDecimalMapper.java index 72db43abb..3773defff 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigDecimalMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigDecimalMapper.java @@ -15,7 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; + +import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigIntegerMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigIntegerMapper.java index e48e11218..6b2012cec 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigIntegerMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BigIntegerMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigInteger; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BitemporalMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BitemporalMapper.java index 8f732dcb5..acf1492d2 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BitemporalMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/BitemporalMapper.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map bitemporal DateRanges. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateMapper.java index e4cd200f3..5a2d026bd 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * {@link SingleColumnMapper} to build a new {@code DateMapper}. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateRangeMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateRangeMapper.java index 37e1b5621..ac04d3654 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateRangeMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DateRangeMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map 1-dimensional date ranges. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DoubleMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DoubleMapper.java index e90d24ddd..5e276a077 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DoubleMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/DoubleMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map a double field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/FloatMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/FloatMapper.java index 40b0beab7..2343862f1 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/FloatMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/FloatMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map a float field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoPointMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoPointMapper.java index 7d22e5b9a..8830bd458 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoPointMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoPointMapper.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map geographical points. @@ -33,7 +33,7 @@ public class GeoPointMapper extends Mapper { @JsonProperty("longitude") final String longitude; - /** The maximum number of levels in the tree. */ + /** The maximum number of levels in the geohash search tree. */ @JsonProperty("max_levels") Integer maxLevels; @@ -50,10 +50,12 @@ public GeoPointMapper(@JsonProperty("latitude") String latitude, @JsonProperty(" } /** - * Sets the maximum number of levels in the tree. + * Sets the maximum number of levels in the geohash search tree. False positives will be discarded using stored doc + * values, so a low value doesn't mean precision lost. High values will produce few false positives to be + * post-filtered, at the expense of creating more terms in the search index. * - * @param maxLevels the maximum number of levels - * @return this with hte specified max number of levels + * @param maxLevels the maximum number of levels in the geohash search tree + * @return this with the specified max number of levels */ public GeoPointMapper maxLevels(Integer maxLevels) { this.maxLevels = maxLevels; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoShapeMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoShapeMapper.java index 6b8754aec..358fd77c4 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoShapeMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/GeoShapeMapper.java @@ -16,7 +16,7 @@ package com.stratio.cassandra.lucene.builder.index.schema.mapping; import com.stratio.cassandra.lucene.builder.common.GeoTransformation; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Arrays; import java.util.List; @@ -32,7 +32,7 @@ public class GeoShapeMapper extends Mapper { @JsonProperty("column") String column; - /** The maximum number of levels in the tree. */ + /** The maximum number of levels in the geohash search tree. */ @JsonProperty("max_levels") Integer maxLevels; @@ -52,10 +52,13 @@ public final GeoShapeMapper column(String column) { } /** - * Sets the maximum number of levels in the tree. + * Sets the maximum number of levels in the geohash search tree. False positives will be discarded using stored doc + * values, so a low value doesn't mean precision lost. High values will produce few false positives to + * be post-filtered, at the expense of creating many terms in the search index. This can be specially costly in + * large polygons, which can produce thousands of terms in case of using large geohash values. * - * @param maxLevels the maximum number of levels in the tree - * @return this with hte specified max number of levels + * @param maxLevels the maximum number of levels in the geohash search tree + * @return this with the specified max number of levels */ public GeoShapeMapper maxLevels(Integer maxLevels) { this.maxLevels = maxLevels; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/IntegerMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/IntegerMapper.java index a9d99edad..305960d2c 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/IntegerMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/IntegerMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map an integer field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/LongMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/LongMapper.java index 3a90b4b02..2bf091474 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/LongMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/LongMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map a long field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/Mapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/Mapper.java index fe25fb2a4..b3d3bac95 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/Mapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/Mapper.java @@ -15,10 +15,10 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.stratio.cassandra.lucene.builder.JSONBuilder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.annotate.JsonSubTypes; -import org.codehaus.jackson.annotate.JsonTypeInfo; /** * Class for mapping between Cassandra's columns and Lucene documents. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/SingleColumnMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/SingleColumnMapper.java index a85956b99..b201b71c5 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/SingleColumnMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/SingleColumnMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Class for mapping between Cassandra's columns and Lucene documents. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/StringMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/StringMapper.java index f5b1d5f4f..ff6a8214b 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/StringMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/StringMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map a string, not tokenized field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/TextMapper.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/TextMapper.java index 65f1716f5..852bed233 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/TextMapper.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/index/schema/mapping/TextMapper.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.index.schema.mapping; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Mapper} to map a string, tokenized field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/Search.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/Search.java index 8d791682a..0f18e4a3c 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/Search.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/Search.java @@ -19,7 +19,7 @@ import com.stratio.cassandra.lucene.builder.search.condition.Condition; import com.stratio.cassandra.lucene.builder.search.sort.Sort; import com.stratio.cassandra.lucene.builder.search.sort.SortField; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/AllCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/AllCondition.java index 9ce8183a8..4113eae67 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/AllCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/AllCondition.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; +import com.fasterxml.jackson.annotation.JsonCreator; /** * A {@link Condition} implementation that matches all documents. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BitemporalCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BitemporalCondition.java index 4230cbe6d..b10503dee 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BitemporalCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BitemporalCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches bi-temporal (four) fields within two ranges of values. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BooleanCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BooleanCondition.java index 702bec761..29e89a13b 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BooleanCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/BooleanCondition.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/Condition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/Condition.java index c1eb84698..38224576c 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/Condition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/Condition.java @@ -15,10 +15,10 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.stratio.cassandra.lucene.builder.JSONBuilder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.annotate.JsonSubTypes; -import org.codehaus.jackson.annotate.JsonTypeInfo; /** * The abstract base class for queries. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/ContainsCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/ContainsCondition.java index c28628658..35da9c6bd 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/ContainsCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/ContainsCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches documents containing a value for a field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/DateRangeCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/DateRangeCondition.java index ede314557..f68355579 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/DateRangeCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/DateRangeCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches a field within an range of values. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/FuzzyCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/FuzzyCondition.java index dd672c4e8..da66ebd7a 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/FuzzyCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/FuzzyCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} that implements the fuzzy search query. The similarity measurement is based on the diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoBBoxCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoBBoxCondition.java index 2b0a2cee7..f3f5e5ed2 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoBBoxCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoBBoxCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} that matches documents containing a shape contained in a certain bounding box. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoDistanceCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoDistanceCondition.java index ef1403051..5ff68a7c4 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoDistanceCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoDistanceCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} that matches documents containing a point contained between two certain circles. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoShapeCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoShapeCondition.java index b5559b945..c6ffdf55d 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoShapeCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/GeoShapeCondition.java @@ -15,9 +15,10 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; +import com.stratio.cassandra.lucene.builder.common.GeoShape; import com.stratio.cassandra.lucene.builder.common.GeoTransformation; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Arrays; import java.util.List; @@ -33,26 +34,22 @@ public class GeoShapeCondition extends Condition { @JsonProperty("field") final String field; - /** The shape in WKT format. */ + /** The shape. */ @JsonProperty("shape") - final String shape; + final GeoShape shape; /** The spatial operation to be applied. */ @JsonProperty("operation") String operation; - /** The sequence of transformations to be applied to the shape before searching. */ - @JsonProperty("transformations") - List transformations; - /** * Constructor receiving the name of the field and the shape. * * @param field the name of the field - * @param shape the shape in WKT format + * @param shape the shape */ @JsonCreator - public GeoShapeCondition(@JsonProperty("field") String field, @JsonProperty("shape") String shape) { + public GeoShapeCondition(@JsonProperty("field") String field, @JsonProperty("shape") GeoShape shape) { this.field = field; this.shape = shape; } @@ -67,20 +64,4 @@ public GeoShapeCondition operation(String operation) { this.operation = operation; return this; } - - /** - * Sets the transformations to be applied to the shape before using it for indexing it. Possible values are {@code - * intersects}, {@code is_within} and {@code contains}. Defaults to {@code is_within}. - * - * @param transformations the sequence of transformations - * @return this with the transformations set - */ - public GeoShapeCondition transform(GeoTransformation... transformations) { - if (this.transformations == null) { - this.transformations = Arrays.asList(transformations); - } else { - this.transformations.addAll(Arrays.asList(transformations)); - } - return this; - } } \ No newline at end of file diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/LuceneCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/LuceneCondition.java index 4388223d4..b65ded4c3 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/LuceneCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/LuceneCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches documents satisfying a Lucene Query Syntax. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/MatchCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/MatchCondition.java index 761bc23b3..53f1fc8a0 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/MatchCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/MatchCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches documents containing a value for a field. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/NoneCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/NoneCondition.java index b9743e0eb..3487f7e4b 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/NoneCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/NoneCondition.java @@ -15,7 +15,7 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; +import com.fasterxml.jackson.annotation.JsonCreator; /** * A {@link Condition} implementation that matches none documents. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PhraseCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PhraseCondition.java index e187f0b8d..109ba8fa7 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PhraseCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PhraseCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches documents containing a particular sequence of terms. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PrefixCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PrefixCondition.java index 4d31a810a..91f3e1581 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PrefixCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/PrefixCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches documents containing terms with a specified prefix. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RangeCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RangeCondition.java index 90472d074..74c49a829 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RangeCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RangeCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A {@link Condition} implementation that matches a field within an range of values. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RegexpCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RegexpCondition.java index f450d72d3..2d86ca1b2 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RegexpCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/RegexpCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Implements the wildcard search query. Supported wildcards are {@code *}, which matches any character sequence diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/WildcardCondition.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/WildcardCondition.java index 96bea539f..a4d155aed 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/WildcardCondition.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/condition/WildcardCondition.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.condition; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Implements the wildcard search query. Supported wildcards are {@code *}, which matches any character sequence diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/GeoDistanceSortField.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/GeoDistanceSortField.java index 57f560e23..478ed127c 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/GeoDistanceSortField.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/GeoDistanceSortField.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.sort; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A geo spatial distance search sort. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SimpleSortField.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SimpleSortField.java index ff92f546c..21e066bf7 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SimpleSortField.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SimpleSortField.java @@ -15,8 +15,8 @@ */ package com.stratio.cassandra.lucene.builder.search.sort; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A simple relevance sorting for a field of a search. diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/Sort.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/Sort.java index 700084949..3c133528f 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/Sort.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/Sort.java @@ -16,8 +16,8 @@ package com.stratio.cassandra.lucene.builder.search.sort; import com.stratio.cassandra.lucene.builder.Builder; -import org.codehaus.jackson.annotate.JsonCreator; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Arrays; import java.util.List; diff --git a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SortField.java b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SortField.java index 8f0a6fbf6..089dbc282 100644 --- a/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SortField.java +++ b/builder/src/main/java/com/stratio/cassandra/lucene/builder/search/sort/SortField.java @@ -15,10 +15,10 @@ */ package com.stratio.cassandra.lucene.builder.search.sort; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.stratio.cassandra.lucene.builder.JSONBuilder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.annotate.JsonSubTypes; -import org.codehaus.jackson.annotate.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A sorting for a field of a search. diff --git a/builder/src/test/java/com/stratio/cassandra/lucene/builder/BuilderTest.java b/builder/src/test/java/com/stratio/cassandra/lucene/builder/BuilderTest.java index 0f027b9c9..f063f3606 100644 --- a/builder/src/test/java/com/stratio/cassandra/lucene/builder/BuilderTest.java +++ b/builder/src/test/java/com/stratio/cassandra/lucene/builder/BuilderTest.java @@ -15,9 +15,12 @@ */ package com.stratio.cassandra.lucene.builder; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.stratio.cassandra.lucene.builder.common.GeoShape; import org.junit.Test; +import java.util.Arrays; + import static com.stratio.cassandra.lucene.builder.Builder.*; import static org.junit.Assert.assertEquals; @@ -57,23 +60,14 @@ public void testIndexFull() { .build(); String expected = "CREATE CUSTOM INDEX idx ON keyspace.table(lucene) " + "USING 'com.stratio.cassandra.lucene.Index' " + - "WITH OPTIONS = {" + - "'refresh_seconds':'10.0'," + - "'directory_path':'path'," + - "'ram_buffer_mb':'64'," + - "'max_merge_mb':'16'," + - "'max_cached_mb':'32'," + - "'indexing_threads':'4'," + - "'indexing_queues_size':'100'," + - "'excluded_data_centers':'DC1,DC2'," + - "'schema':'{" + - "\"analyzers\":{" + + "WITH OPTIONS = {'refresh_seconds':'10.0','directory_path':'path','ram_buffer_mb':'64'," + + "'max_merge_mb':'16','max_cached_mb':'32','indexing_threads':'4'," + + "'indexing_queues_size':'100','excluded_data_centers':'DC1,DC2','schema':'{" + + "\"default_analyzer\":\"my_analyzer\",\"analyzers\":{" + "\"my_analyzer\":{\"type\":\"classpath\",\"class\":\"my_class\"}," + "\"snow\":{\"type\":\"snowball\",\"language\":\"tartar\",\"stopwords\":\"a,b,c\"}}," + - "\"default_analyzer\":\"my_analyzer\"," + "\"fields\":{" + - "\"uuid\":{\"type\":\"uuid\",\"validated\":true}," + - "\"string\":{\"type\":\"string\"}}}'}"; + "\"uuid\":{\"type\":\"uuid\",\"validated\":true},\"string\":{\"type\":\"string\"}}}'}"; assertEquals("index serialization is wrong", expected, actual); } @@ -249,21 +243,16 @@ public void testGeoShapeMapperDefaults() { public void testGeoShapeMapperFull() { String actual = geoShapeMapper().column("shape") .maxLevels(7) - .transform(centroidGeoTransformation(), - convexHullGeoTransformation(), - differenceGeoTransformation("my_difference_shape"), - intersectionGeoTransformation("my_intersection_shape"), - unionGeoTransformation("my_union_shape"), - bufferGeoTransformation().maxDistance("10km").minDistance("5km")) + .transform(centroid(), + convexHull(), + bbox(), + buffer().maxDistance("10km").minDistance("5km")) .build(); - String expected = "{\"type\":\"geo_shape\",\"column\":\"shape\",\"transformations\":[" + - "{\"type\":\"centroid\"}," + + String expected = "{\"type\":\"geo_shape\",\"column\":\"shape\",\"max_levels\":7,\"transformations\":" + + "[{\"type\":\"centroid\"}," + "{\"type\":\"convex_hull\"}," + - "{\"type\":\"difference\",\"shape\":\"my_difference_shape\"}," + - "{\"type\":\"intersection\",\"shape\":\"my_intersection_shape\"}," + - "{\"type\":\"union\",\"shape\":\"my_union_shape\"}," + - "{\"type\":\"buffer\",\"max_distance\":\"10km\",\"min_distance\":\"5km\"}]," + - "\"max_levels\":7}"; + "{\"type\":\"bbox\"}," + + "{\"type\":\"buffer\",\"max_distance\":\"10km\",\"min_distance\":\"5km\"}]}"; assertEquals("geo shape mapper serialization is wrong", expected, actual); } @@ -486,14 +475,8 @@ public void testFuzzyConditionFull() { .transpositions(true) .boost(2) .build(); - String expected = "{\"type\":\"fuzzy\"," + - "\"field\":\"field\"," + - "\"value\":\"value\"," + - "\"boost\":2.0," + - "\"transpositions\":true," + - "\"max_edits\":1," + - "\"prefix_length\":3," + - "\"max_expansions\":2}"; + String expected = "{\"type\":\"fuzzy\",\"field\":\"field\",\"value\":\"value\",\"boost\":2.0," + + "\"max_edits\":1,\"prefix_length\":3,\"max_expansions\":2,\"transpositions\":true}"; assertEquals("fuzzy condition serialization is wrong", expected, actual); } @@ -675,33 +658,96 @@ public void testGeoDistanceConditionFull() { assertEquals("geo distance condition serialization is wrong", expected, actual); } + @Test + public void testGeoShapeBuffer() { + String expected = "{\"type\":\"buffer\",\"shape\":{\"type\":\"wkt\",\"value\":\"1\"}," + + "\"max_distance\":\"1\",\"min_distance\":\"2\"}"; + assertEquals("Shape buffer is wrong", expected, buffer(wkt("1")).maxDistance("1").minDistance("2").build()); + assertEquals("Shape buffer is wrong", expected, buffer("1").maxDistance("1").minDistance("2").build()); + } + + @Test + public void testGeoShapeBBox() { + String expected = "{\"type\":\"bbox\",\"shape\":{\"type\":\"wkt\",\"value\":\"1\"}}"; + assertEquals("Shape bbox is wrong", expected, bbox(wkt("1")).build()); + assertEquals("Shape bbox is wrong", expected, bbox("1").build()); + } + + @Test + public void testGeoShapeCentroid() { + String expected = "{\"type\":\"centroid\",\"shape\":{\"type\":\"wkt\",\"value\":\"1\"}}"; + assertEquals("Shape centroid is wrong", expected, centroid(wkt("1")).build()); + assertEquals("Shape centroid is wrong", expected, centroid("1").build()); + } + + @Test + public void testGeoShapeConvexHull() { + String expected = "{\"type\":\"convex_hull\",\"shape\":{\"type\":\"wkt\",\"value\":\"1\"}}"; + assertEquals("Shape convex hull is wrong", expected, convexHull(wkt("1")).build()); + assertEquals("Shape convex hull is wrong", expected, convexHull("1").build()); + } + + @Test + public void testGeoShapeIntersection() { + String expected = "{\"type\":\"intersection\",\"shapes\":[" + + "{\"type\":\"wkt\",\"value\":\"1\"}," + + "{\"type\":\"wkt\",\"value\":\"2\"}" + + "]}"; + assertEquals("Shape intersection is wrong", expected, intersection(wkt("1"),wkt("2")).build()); + assertEquals("Shape intersection is wrong", expected, intersection("1","2").build()); + assertEquals("Shape intersection is wrong", expected, intersection(Arrays.asList(wkt("1"),wkt("2"))).build()); + assertEquals("Shape intersection is wrong", expected, intersection().add("1").add(wkt("2")).build()); + } + + @Test + public void testGeoShapeUnion() { + String expected = "{\"type\":\"union\",\"shapes\":[" + + "{\"type\":\"wkt\",\"value\":\"1\"}," + + "{\"type\":\"wkt\",\"value\":\"2\"}" + + "]}"; + assertEquals("Shape union is wrong", expected, union(wkt("1"),wkt("2")).build()); + assertEquals("Shape union is wrong", expected, union("1","2").build()); + assertEquals("Shape union is wrong", expected, union(Arrays.asList(wkt("1"),wkt("2"))).build()); + assertEquals("Shape union is wrong", expected, union().add("1").add(wkt("2")).build()); + } + + @Test + public void testGeoShapeDifference() { + String expected = "{\"type\":\"difference\",\"shapes\":[" + + "{\"type\":\"wkt\",\"value\":\"1\"}," + + "{\"type\":\"wkt\",\"value\":\"2\"}" + + "]}"; + assertEquals("Shape difference is wrong", expected, difference(wkt("1"),wkt("2")).build()); + assertEquals("Shape difference is wrong", expected, difference("1","2").build()); + assertEquals("Shape difference is wrong", expected, difference(Arrays.asList(wkt("1"),wkt("2"))).build()); + assertEquals("Shape difference is wrong", expected, difference().add("1").add(wkt("2")).build()); + } + @Test public void testGeoShapeConditionDefaults() { - String actual = geoShape("field", "shape").build(); - String expected = "{\"type\":\"geo_shape\",\"field\":\"field\",\"shape\":\"shape\"}"; + String actual = geoShape("field", wkt("POINT(0 0)")).build(); + String expected = "{\"type\":\"geo_shape\",\"field\":\"field\"," + + "\"shape\":{\"type\":\"wkt\",\"value\":\"POINT(0 0)\"}}"; assertEquals("geo shape condition serialization is wrong", expected, actual); } @Test public void testGeoShapeConditionFull() { - String actual = geoShape("f", "s").operation("intersects") - .transform(centroidGeoTransformation(), - bboxGeoTransformation(), - convexHullGeoTransformation(), - differenceGeoTransformation("my_difference_shape"), - intersectionGeoTransformation("my_intersection_shape"), - unionGeoTransformation("my_union_shape"), - bufferGeoTransformation().maxDistance("10km").minDistance("5km")) - .build(); - String expected = "{\"type\":\"geo_shape\",\"field\":\"f\",\"shape\":\"s\"," + - "\"operation\":\"intersects\",\"transformations\":[" + - "{\"type\":\"centroid\"}," + - "{\"type\":\"bbox\"}," + - "{\"type\":\"convex_hull\"}," + - "{\"type\":\"difference\",\"shape\":\"my_difference_shape\"}," + - "{\"type\":\"intersection\",\"shape\":\"my_intersection_shape\"}," + - "{\"type\":\"union\",\"shape\":\"my_union_shape\"}," + - "{\"type\":\"buffer\",\"max_distance\":\"10km\",\"min_distance\":\"5km\"}]}"; + GeoShape shape = union(difference(intersection(centroid(convexHull(bbox(buffer(wkt("POINT(0 0)")) + .maxDistance("10km") + .minDistance("1km"))))))); + String actual = geoShape("f", shape).operation("intersects").build(); + String expected = "{\"type\":\"geo_shape\",\"field\":\"f\",\"shape\":" + + "{\"type\":\"union\",\"shapes\":[" + + "{\"type\":\"difference\",\"shapes\":[" + + "{\"type\":\"intersection\",\"shapes\":[" + + "{\"type\":\"centroid\",\"shape\":" + + "{\"type\":\"convex_hull\",\"shape\":" + + "{\"type\":\"bbox\",\"shape\":" + + "{\"type\":\"buffer\",\"shape\":" + + "{\"type\":\"wkt\",\"value\":\"POINT(0 0)\"}," + + "\"max_distance\":\"10km\",\"min_distance\":\"1km\"}}}}]}]}]}," + + "\"operation\":\"intersects\"}"; assertEquals("geo shape condition serialization is wrong", expected, actual); } @@ -721,14 +767,14 @@ public void testSimpleSortFieldFull() { @Test public void testGeoDistanceSortFieldDefaults() { - String actual = geoDistanceField("field1", 1.2, 3.4).build(); + String actual = Builder.geoDistance("field1", 1.2, 3.4).build(); String expected = "{\"type\":\"geo_distance\",\"field\":\"field1\",\"latitude\":1.2,\"longitude\":3.4}"; assertEquals("sort field condition serialization is wrong", expected, actual); } @Test public void testGeoDistanceSortFieldFull() { - String actual = geoDistanceField("field1", 1.2, -3.4).reverse(true).build(); + String actual = Builder.geoDistance("field1", 1.2, -3.4).reverse(true).build(); String expected = "{\"type\":\"geo_distance\"," + "\"field\":\"field1\"," + "\"latitude\":1.2," + @@ -748,7 +794,7 @@ public void testSortDefaults() { public void testSortFull() { String actual = search().sort(field("field1"), field("field2"), - geoDistanceField("field1", 1.0, -3.2).reverse(true)).build(); + Builder.geoDistance("field1", 1.0, -3.2).reverse(true)).build(); String expected = "{\"sort\":[{" + "\"type\":\"simple\",\"field\":\"field1\"}," + "{\"type\":\"simple\",\"field\":\"field2\"}," + @@ -826,16 +872,11 @@ public void testIndexExample() { .mapper("message", textMapper().analyzer("danish")) .mapper("date", dateMapper().pattern("yyyyMMdd")) .build(); - String expected = "CREATE CUSTOM INDEX my_index ON messages() " + - "USING 'com.stratio.cassandra.lucene.Index' WITH OPTIONS = {" + - "'refresh_seconds':'10'," + - "'schema':'{" + - "\"analyzers\":{" + - "\"danish\":{\"type\":\"snowball\",\"language\":\"danish\"}}," + - "\"default_analyzer\":\"english\"," + - "\"fields\":{" + - "\"id\":{\"type\":\"uuid\"}," + - "\"user\":{\"type\":\"string\",\"case_sensitive\":false}," + + String expected = "CREATE CUSTOM INDEX my_index ON messages() USING 'com.stratio.cassandra.lucene.Index' " + + "WITH OPTIONS = {'refresh_seconds':'10','schema':'{\"default_analyzer\":\"english\"," + + "\"analyzers\":{\"danish\":{\"type\":\"snowball\",\"language\":\"danish\"}},\"fields\":" + + "{\"id\":{\"type\":\"uuid\"},\"user\":" + + "{\"type\":\"string\",\"case_sensitive\":false}," + "\"message\":{\"type\":\"text\",\"analyzer\":\"danish\"}," + "\"date\":{\"type\":\"date\",\"pattern\":\"yyyyMMdd\"}}}'}"; assertEquals("index serialization is wrong", expected, actual); diff --git a/doc/documentation.rst b/doc/documentation.rst index 4b945723f..b38fa513c 100644 --- a/doc/documentation.rst +++ b/doc/documentation.rst @@ -1,6 +1,6 @@ -++++++++++++++++++++++++++++++++ +================================ Stratio's Cassandra Lucene Index -++++++++++++++++++++++++++++++++ +================================ - `Overview <#overview>`__ - `Features <#features>`__ @@ -21,7 +21,7 @@ Stratio's Cassandra Lucene Index - `Blob mapper <#blob-mapper>`__ - `Boolean mapper <#boolean-mapper>`__ - `Date mapper <#date-mapper>`__ - - `Date range mapper <#daterange-mapper>`__ + - `Date range mapper <#date-range-mapper>`__ - `Double mapper <#double-mapper>`__ - `Float mapper <#float-mapper>`__ - `Geo point mapper <#geo-point-mapper>`__ @@ -52,14 +52,20 @@ Stratio's Cassandra Lucene Index - `Wildcard search <#wildcard-search>`__ - `Geographical elements <#geographical-elements>`__ - `Distance <#distance>`__ - - `Transformations <#tranformations>`__ - - `Bounding box <#bounding-box>`__ - - `Buffer <#buffer>`__ - - `Centroid <#centroid>`__ - - `Convex hull <#convex-hull>`__ - - `Difference <#difference>`__ - - `Intersection <#intersection>`__ - - `Union <#intersection>`__ + - `Transformations <#transformations>`__ + - `Bounding box transformation <#bounding-box-transformation>`__ + - `Buffer transformation <#buffer-transformation>`__ + - `Centroid transformation <#centroid-transformation>`__ + - `Convex hull transformation <#convex-hull-transformation>`__ + - `Shapes <#shapes>`__ + - `WKT shape <#wkt-shape>`__ + - `Bounding box shape <#bounding-box-shape>`__ + - `Buffer shape <#buffer-shape>`__ + - `Centroid shape <#centroid-shape>`__ + - `Convex hull shape <#convex-hull-shape>`__ + - `Difference shape <#difference-shape>`__ + - `Intersection shape <#intersection-shape>`__ + - `Union shape <#intersection-shape>`__ - `Complex data types <#complex-data-types>`__ - `Tuples <#tuples>`__ - `User Defined Types <#user-defined-types>`__ @@ -83,8 +89,9 @@ Stratio's Cassandra Lucene Index - `Try doc values <#try-doc-values>`__ - `Force segments merge <#force-segments-merge>`__ +-------- Overview -******** +-------- Stratio’s Cassandra Lucene Index, derived from `Stratio Cassandra `__, is a plugin for `Apache Cassandra `__ that extends its index functionality to provide near @@ -98,7 +105,7 @@ Cassandra indexes are one of the core modules on which `Stratio’s BigData plat :alt: architecture :align: center - Index `relevance searches `__ allow you to retrieve the +Index `relevance searches `__ allow you to retrieve the *n* more relevant results satisfying a search. The coordinator node sends the search to each node in the cluster, each node returns its *n* best results and then the coordinator combines these partial results and gives you the *n* best of them, avoiding full scan. You can also base the sorting in a combination of fields. @@ -115,9 +122,9 @@ Adding Lucene filters in the jobs input can dramatically reduce the amount of da :alt: spark_architecture :align: center - This project is not intended to replace Apache Cassandra denormalized tables, inverted indexes, and/or secondary - indexes. It is just a tool to perform some kind of queries which are really hard to be addressed using Apache Cassandra - out of the box features, filling the gap between real-time and analytics. +This project is not intended to replace Apache Cassandra denormalized tables, inverted indexes, and/or secondary +indexes. It is just a tool to perform some kind of queries which are really hard to be addressed using Apache Cassandra +out of the box features, filling the gap between real-time and analytics. .. image:: /doc/resources/oltp_olap.png :width: 100% @@ -133,7 +140,7 @@ Stratio’s Cassandra Lucene Index and its integration with Lucene search techno - Full text search (language-aware analysis, wildcard, fuzzy, regexp) - Boolean search (and, or, not) -- Sorting by relevance, column value, and distance) +- Sorting by relevance, column value, and distance - Geospatial indexing (points, lines, polygons and their multiparts) - Geospatial transformations (bounding box, buffer, centroid, convex hull, union, difference, intersection) - Geospatial operations (intersects, contains, is within) @@ -356,15 +363,15 @@ We will create the following table to store tweets: .. code-block:: sql CREATE KEYSPACE demo - WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor': 1}; + WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}; USE demo; CREATE TABLE tweets ( - id INT PRIMARY KEY, - user TEXT, - body TEXT, - time TIMESTAMP, - latitude FLOAT, - longitude FLOAT + id INT PRIMARY KEY, + user TEXT, + body TEXT, + time TIMESTAMP, + latitude FLOAT, + longitude FLOAT ); Now you can create a custom Lucene index on it with the following statement: @@ -374,16 +381,16 @@ Now you can create a custom Lucene index on it with the following statement: CREATE CUSTOM INDEX tweets_index ON tweets () USING 'com.stratio.cassandra.lucene.Index' WITH OPTIONS = { - 'refresh_seconds' : '1', - 'schema' : '{ - fields : { - id : {type : "integer"}, - user : {type : "string"}, - body : {type : "text", analyzer : "english"}, - time : {type : "date", pattern : "yyyy/MM/dd"}, - place : {type : "geo_point", latitude:"latitude", longitude:"longitude"} - } - }' + 'refresh_seconds': '1', + 'schema': '{ + fields: { + id: {type: "integer"}, + user: {type: "string"}, + body: {type: "text", analyzer: "english"}, + time: {type: "date", pattern: "yyyy/MM/dd"}, + place: {type: "geo_point", latitude: "latitude", longitude: "longitude"} + } + }' }; This will index all the columns in the table with the specified types, and it will be refreshed once per second. @@ -400,7 +407,7 @@ Now, to search for tweets within a certain date range: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"} + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"} }'); The same search can be performed forcing an explicit refresh of the involved index shards: @@ -408,8 +415,8 @@ The same search can be performed forcing an explicit refresh of the involved ind .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - refresh : true + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + refresh: true }') limit 100; Now, to search the top 100 more relevant tweets where *body* field contains the phrase “big data gives organizations” @@ -418,8 +425,8 @@ within the aforementioned date range: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} + filter: {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} }') LIMIT 100; To refine the search to get only the tweets written by users whose names start with "a": @@ -427,9 +434,11 @@ To refine the search to get only the tweets written by users whose names start w .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1} }') LIMIT 100; To get the 100 more recent filtered results you can use the *sort* option: @@ -437,10 +446,12 @@ To get the 100 more recent filtered results you can use the *sort* option: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : {field: "time", reverse: true} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: {field: "time", reverse: true} }') limit 100; The previous search can be restricted to tweets created close to a geographical position: @@ -448,11 +459,13 @@ The previous search can be restricted to tweets created close to a geographical .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : {field: "time", reverse: true} + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: {field: "time", reverse: true} }') limit 100; It is also possible to sort the results by distance to a geographical position: @@ -460,12 +473,16 @@ It is also possible to sort the results by distance to a geographical position: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter: [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : [ {field: "time", reverse: true}, - {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} ] + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: [ + {field: "time", reverse: true}, + {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} + ] }') limit 100; Last but not least, you can route any search to a certain token range or partition, in such a way that only a @@ -474,16 +491,21 @@ subset of the cluster nodes will be hit, saving precious resources: .. code-block:: sql SELECT * FROM tweets WHERE expr(tweets_index, '{ - filter : [ {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, - {type: "prefix", field: "user", value: "a"}, - {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "10km"} ], - query : {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, - sort : [ {field: "time", reverse: true}, - {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} ] + filter: [ + {type: "range", field: "time", lower: "2014/04/25", upper: "2014/05/01"}, + {type: "prefix", field: "user", value: "a"}, + {type: "geo_distance", field: "place", latitude: 40.3930, longitude: -3.7328, max_distance: "1km"} + ], + query: {type: "phrase", field: "body", value: "big data gives organizations", slop: 1}, + sort: [ + {field: "time", reverse: true}, + {field: "place", type: "geo_distance", latitude: 40.3930, longitude: -3.7328} + ] }') AND TOKEN(id) >= TOKEN(0) AND TOKEN(id) < TOKEN(10000000) limit 100; +-------- Indexing -******** +-------- Lucene indexes are an extension of the Cassandra secondary indexes. As such, they are created through CQL `CREATE CUSTOM INDEX statement `__, specifying the full @@ -503,15 +525,17 @@ where is a JSON object: .. code-block:: sql - := { ('refresh_seconds' : '',)? - ('ram_buffer_mb' : '',)? - ('max_merge_mb' : '',)? - ('max_cached_mb' : '',)? - ('indexing_threads' : '',)? - ('indexing_queues_size' : '',)? - ('directory_path' : '',)? - ('excluded_data_centers' : '',)? - 'schema' : ''}; + := { + ('refresh_seconds': '',)? + ('ram_buffer_mb': '',)? + ('max_merge_mb': '',)? + ('max_cached_mb': '',)? + ('indexing_threads': '',)? + ('indexing_queues_size': '',)? + ('directory_path': '',)? + ('excluded_data_centers': '',)? + 'schema': '' + }; All options take a value enclosed in single quotes: @@ -523,7 +547,7 @@ All options take a value enclosed in single quotes: - **max\_merge\_mb**: defaults to '5'. - **max\_cached\_mb**: defaults to '30'. - **indexing\_threads**: number of asynchronous indexing threads. ’0’ - means synchronous indexing. Defaults to ’0’. + means synchronous indexing. Defaults to number of processors available to the JVM. - **indexing\_queues\_size**: max number of queued documents per asynchronous indexing thread. Defaults to ’50’. - **directory\_path**: The path of the directory where the Lucene index @@ -535,24 +559,24 @@ All options take a value enclosed in single quotes: .. code-block:: sql - := { - (analyzers : { (, )* } ,)? - (default_analyzer : "",)? - fields : { (, )* } + := { + (analyzers: { (, )* } ,)? + (default_analyzer: "",)? + fields: { (, )* } } Where default\_analyzer defaults to ‘org.apache.lucene.analysis.standard.StandardAnalyzer’. .. code-block:: sql - := : { - type : "" (,