From 180a88f611ad6976d4e42e00db6eba12d03fa7a5 Mon Sep 17 00:00:00 2001 From: Eduardo Alonso Date: Thu, 1 Sep 2016 13:08:45 +0200 Subject: [PATCH] Sincronized with 3.0.8 branch (#185) * Updated to cassandra-3.0.8 * Fixed release date in changelog * [RELEASE] 3.0.8.0 * [RELEASE] Prepare for next development iteration * Added testsAT for checking alias in map names. * Refactor columns (#173) * Add scale-based column implementation * Port column package to Scala * Refactor and improve test coverage. * Replace mappers supported Cassandra types by Java types. * Refactor document creation. * Refactor * Added jenkins testAT execution. * Fixed deb and rpm generation in pom. * Fixed Date format with timezone in scala tests. * Fixed deb dependecies in pom. * Chenegd local_jmx to false in jenkins containers parameters. * Added LOCAL_JMX to env docker stratup * Fixed order in jenkins params * Fixed Changelog. * Feature/composite spatial strategy (#176) * Add geospatial shapes post filtering (ensures accuracy with any tree levels) * Use composite strategy in geo_point. * Fix license header. * Fix spelling. * Upgrade query builder JSON serializer to Jackson 2.8.0 * Fix style. * Fix mapping of timestamps and dates by their underlying numeric value (#177) * Fix doc. * Fix changelog. * Set default number of indexing threads to number of processors available to the JVM * Fix JMX test setup * Restore AT default fetch size. * Set release date. * [RELEASE] 3.0.8.1 * [RELEASE] Prepare for next development iteration * Fix changelog * Transformations associativity (#183) * Allow associativity in search-time geospatial transformations * Improve doc * Improve doc * Improve doc * Fix compatibility matrix * Split geospatial transformations doc * Improve doc * Improve doc * Improve doc * Improve doc * Improve doc headers * Improve doc * Fix doc * Improve doc * Improve doc * Revert "Improve doc" This reverts commit e107ddb6bdbe63b185083551a96b158394ce714f. * Improve doc * Fix changelog * Fix geo shape mapper unit test for invalid shape. * Fix doc * Add methods for iteratively building geospatial transformations * Fix paged index-sorted queries matching more than 65535 rows (#184) Fix paged index-sorted queries matching more than 65535 rows * Fix doc * Fix partition directed queries using dummy column syntax in skinny tables * [RELEASE] 3.0.8.2 * [RELEASE] Prepare for next development iteration * Fixed versions --- .jenkins.yml | 14 + CHANGELOG.md | 16 + README.rst | 108 +- builder/pom.xml | 11 +- .../cassandra/lucene/builder/Builder.java | 273 +- .../cassandra/lucene/builder/JSONBuilder.java | 19 +- .../lucene/builder/common/GeoShape.java | 325 +++ .../builder/common/GeoTransformation.java | 73 +- .../lucene/builder/index/schema/Schema.java | 2 +- .../index/schema/analysis/Analyzer.java | 4 +- .../schema/analysis/ClasspathAnalyzer.java | 4 +- .../schema/analysis/SnowballAnalyzer.java | 4 +- .../schema/mapping/BigDecimalMapper.java | 3 +- .../schema/mapping/BigIntegerMapper.java | 2 +- .../schema/mapping/BitemporalMapper.java | 4 +- .../index/schema/mapping/DateMapper.java | 2 +- .../index/schema/mapping/DateRangeMapper.java | 2 +- .../index/schema/mapping/DoubleMapper.java | 2 +- .../index/schema/mapping/FloatMapper.java | 2 +- .../index/schema/mapping/GeoPointMapper.java | 14 +- .../index/schema/mapping/GeoShapeMapper.java | 13 +- .../index/schema/mapping/IntegerMapper.java | 2 +- .../index/schema/mapping/LongMapper.java | 2 +- .../builder/index/schema/mapping/Mapper.java | 6 +- .../schema/mapping/SingleColumnMapper.java | 2 +- .../index/schema/mapping/StringMapper.java | 2 +- .../index/schema/mapping/TextMapper.java | 2 +- .../lucene/builder/search/Search.java | 2 +- .../search/condition/AllCondition.java | 2 +- .../search/condition/BitemporalCondition.java | 4 +- .../search/condition/BooleanCondition.java | 2 +- .../builder/search/condition/Condition.java | 6 +- .../search/condition/ContainsCondition.java | 4 +- .../search/condition/DateRangeCondition.java | 4 +- .../search/condition/FuzzyCondition.java | 4 +- .../search/condition/GeoBBoxCondition.java | 4 +- .../condition/GeoDistanceCondition.java | 4 +- .../search/condition/GeoShapeCondition.java | 33 +- .../search/condition/LuceneCondition.java | 4 +- .../search/condition/MatchCondition.java | 4 +- .../search/condition/NoneCondition.java | 2 +- .../search/condition/PhraseCondition.java | 4 +- .../search/condition/PrefixCondition.java | 4 +- .../search/condition/RangeCondition.java | 4 +- .../search/condition/RegexpCondition.java | 4 +- .../search/condition/WildcardCondition.java | 4 +- .../search/sort/GeoDistanceSortField.java | 4 +- .../builder/search/sort/SimpleSortField.java | 4 +- .../lucene/builder/search/sort/Sort.java | 4 +- .../lucene/builder/search/sort/SortField.java | 6 +- .../cassandra/lucene/builder/BuilderTest.java | 179 +- doc/documentation.rst | 2579 +++++++++-------- docker/docker-entrypoint.sh | 36 + plugin/pom.xml | 39 +- .../com/stratio/cassandra/lucene/Index.java | 12 +- .../cassandra/lucene/IndexOptions.java | 10 +- .../cassandra/lucene/IndexPagingState.java | 15 +- .../cassandra/lucene/IndexService.java | 53 +- .../cassandra/lucene/IndexServiceSkinny.java | 26 +- .../cassandra/lucene/IndexServiceWide.java | 23 +- .../cassandra/lucene/column/Column.java | 239 -- .../cassandra/lucene/column/ColumnAdder.java | 79 - .../lucene/column/ColumnBuilder.java | 102 - .../cassandra/lucene/column/Columns.java | 215 -- .../lucene/column/ColumnsMapper.java | 209 -- .../cassandra/lucene/common/GeoShape.java | 388 +++ .../lucene/common/GeoTransformation.java | 121 +- .../lucene/index/DocumentIterator.java | 2 +- .../lucene/index/TokenLengthAnalyzer.java | 3 +- .../cassandra/lucene/key/KeyMapper.java | 26 +- .../cassandra/lucene/key/KeyQuery.java | 4 +- .../cassandra/lucene/key/PartitionMapper.java | 19 +- .../cassandra/lucene/key/TokenMapper.java | 44 +- .../cassandra/lucene/schema/Schema.java | 78 +- .../lucene/schema/SchemaAnalyzer.java | 2 +- .../schema/mapping/BigDecimalMapper.java | 14 +- .../schema/mapping/BigIntegerMapper.java | 11 +- .../schema/mapping/BitemporalMapper.java | 42 +- .../lucene/schema/mapping/BlobMapper.java | 5 +- .../lucene/schema/mapping/BooleanMapper.java | 6 +- .../lucene/schema/mapping/DateMapper.java | 17 +- .../schema/mapping/DateRangeMapper.java | 35 +- .../lucene/schema/mapping/DoubleMapper.java | 19 +- .../lucene/schema/mapping/FloatMapper.java | 18 +- .../lucene/schema/mapping/GeoPointMapper.java | 86 +- .../lucene/schema/mapping/GeoShapeMapper.java | 66 +- .../lucene/schema/mapping/InetMapper.java | 5 +- .../lucene/schema/mapping/IntegerMapper.java | 22 +- .../lucene/schema/mapping/KeywordMapper.java | 4 +- .../lucene/schema/mapping/LongMapper.java | 23 +- .../lucene/schema/mapping/Mapper.java | 208 +- .../schema/mapping/SingleColumnMapper.java | 68 +- .../lucene/schema/mapping/StringMapper.java | 21 +- .../lucene/schema/mapping/TextMapper.java | 23 +- .../lucene/schema/mapping/UUIDMapper.java | 5 +- .../builder/DateRangeMapperBuilder.java | 1 - .../lucene/search/SearchBuilders.java | 16 +- .../search/condition/GeoBBoxCondition.java | 9 +- .../condition/GeoDistanceCondition.java | 2 +- .../search/condition/GeoShapeCondition.java | 49 +- .../search/condition/LuceneCondition.java | 2 +- .../condition/SingleColumnCondition.java | 4 +- .../condition/SingleMapperCondition.java | 4 +- .../builder/GeoShapeConditionBuilder.java | 35 +- .../search/sort/GeoDistanceSortField.java | 17 +- .../lucene/search/sort/SimpleSortField.java | 2 +- .../cassandra/lucene/util/DateParser.java | 7 +- .../lucene/util/GeospatialUtils.java | 13 +- .../cassandra/lucene/util/JsonSerializer.java | 4 +- .../cassandra/lucene/column/Column.scala | 116 + .../cassandra/lucene/column/Columns.scala | 97 + .../lucene/column/ColumnsMapper.scala | 255 ++ .../cassandra/lucene/column/ColumnTest.java | 115 - .../cassandra/lucene/column/ColumnsTest.java | 150 - .../cassandra/lucene/common/GeoShapeTest.java | 91 + .../GeoTransformationBBoxTest.java | 4 +- .../GeoTransformationBufferTest.java | 6 +- .../GeoTransformationCentroidTest.java | 5 +- .../GeoTransformationConvexHullTest.java | 5 +- .../lucene/schema/SchemaBuilderTest.java | 106 +- .../cassandra/lucene/schema/SchemaTest.java | 32 +- .../schema/mapping/BitemporalMapperTest.java | 48 +- .../schema/mapping/DateRangeMapperTest.java | 26 +- .../schema/mapping/DoubleMapperTest.java | 3 - .../schema/mapping/FloatMapperTest.java | 2 - .../schema/mapping/GeoPointMapperTest.java | 43 +- .../schema/mapping/GeoShapeMapperTest.java | 111 +- .../schema/mapping/IntegerMapperTest.java | 12 +- .../lucene/schema/mapping/LongMapperTest.java | 13 +- .../lucene/schema/mapping/MapperTest.java | 182 +- .../schema/mapping/StringMapperTest.java | 16 +- .../lucene/schema/mapping/TextMapperTest.java | 2 +- .../condition/GeoBBoxConditionTest.java | 7 +- .../condition/GeoDistanceConditionTest.java | 25 +- .../condition/GeoShapeConditionTest.java | 177 +- .../GeoTransformationDifferenceTest.java | 91 - .../GeoTransformationIntersectionTest.java | 91 - .../condition/GeoTransformationUnionTest.java | 91 - .../search/condition/MatchConditionTest.java | 4 +- .../cassandra/lucene/util/DateParserTest.java | 2 - .../cassandra/lucene/BaseScalaTest.scala | 26 + .../cassandra/lucene/column/ColumnTest.scala | 120 + .../lucene/column/ColumnsMapperTest.scala | 258 ++ .../cassandra/lucene/column/ColumnsTest.scala | 139 + pom.xml | 2 +- .../GeoShapeSearchOverGeoPointsAT.java | 10 +- .../GeoShapeSearchOverGeoShapesAT.java | 530 ++-- .../GeoShapeSearchSpatialOperationsAT.java | 677 +++-- .../lucene/testsAT/issues/Issue165AT.java | 147 +- .../lucene/testsAT/issues/Issue177AT.java | 60 + .../testsAT/search/AbstractSearchAT.java | 1 + .../lucene/testsAT/search/DataHelper.java | 15 +- .../lucene/testsAT/search/FuzzySearchAT.java | 21 + .../lucene/testsAT/search/MatchSearchAT.java | 20 + .../lucene/testsAT/search/PhraseSearchAT.java | 20 + .../lucene/testsAT/search/PrefixSearchAT.java | 20 + .../lucene/testsAT/search/RangeSearchAT.java | 20 + .../lucene/testsAT/search/RegexpSearchAT.java | 20 + .../lucene/testsAT/search/SortedSearchAT.java | 39 +- .../lucene/testsAT/suite/IssuesSuite.java | 3 +- .../lucene/testsAT/suite/VariaSuite.java | 1 + .../lucene/testsAT/udt/TupleIndexingAT.java | 3 +- .../lucene/testsAT/util/CassandraConfig.java | 27 +- .../testsAT/util/CassandraConnection.java | 1 + .../lucene/testsAT/util/CassandraUtils.java | 9 + .../varia/BoundStatementWithSortedKQuery.java | 9 +- .../varia/SearchMatchingManyRowsAT.java | 85 + 167 files changed, 5582 insertions(+), 5025 deletions(-) create mode 100644 .jenkins.yml create mode 100644 builder/src/main/java/com/stratio/cassandra/lucene/builder/common/GeoShape.java create mode 100755 docker/docker-entrypoint.sh delete mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/column/Column.java delete mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/column/ColumnAdder.java delete mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/column/ColumnBuilder.java delete mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/column/Columns.java delete mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/column/ColumnsMapper.java create mode 100644 plugin/src/main/java/com/stratio/cassandra/lucene/common/GeoShape.java create mode 100644 plugin/src/main/scala/com/stratio/cassandra/lucene/column/Column.scala create mode 100644 plugin/src/main/scala/com/stratio/cassandra/lucene/column/Columns.scala create mode 100644 plugin/src/main/scala/com/stratio/cassandra/lucene/column/ColumnsMapper.scala delete mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/column/ColumnTest.java delete mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/column/ColumnsTest.java create mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/common/GeoShapeTest.java rename plugin/src/test/java/com/stratio/cassandra/lucene/{search/condition => common}/GeoTransformationBBoxTest.java (96%) rename plugin/src/test/java/com/stratio/cassandra/lucene/{search/condition => common}/GeoTransformationBufferTest.java (96%) rename plugin/src/test/java/com/stratio/cassandra/lucene/{search/condition => common}/GeoTransformationCentroidTest.java (95%) rename plugin/src/test/java/com/stratio/cassandra/lucene/{search/condition => common}/GeoTransformationConvexHullTest.java (95%) delete mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/search/condition/GeoTransformationDifferenceTest.java delete mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/search/condition/GeoTransformationIntersectionTest.java delete mode 100644 plugin/src/test/java/com/stratio/cassandra/lucene/search/condition/GeoTransformationUnionTest.java create mode 100644 plugin/src/test/scala/com/stratio/cassandra/lucene/BaseScalaTest.scala create mode 100644 plugin/src/test/scala/com/stratio/cassandra/lucene/column/ColumnTest.scala create mode 100644 plugin/src/test/scala/com/stratio/cassandra/lucene/column/ColumnsMapperTest.scala create mode 100644 plugin/src/test/scala/com/stratio/cassandra/lucene/column/ColumnsTest.scala create mode 100644 testsAT/src/test/java/com/stratio/cassandra/lucene/testsAT/issues/Issue177AT.java create mode 100644 testsAT/src/test/java/com/stratio/cassandra/lucene/testsAT/varia/SearchMatchingManyRowsAT.java 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 90c7f28c1..f6806248d 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) @@ -236,33 +243,43 @@ and create them again with running newer version. If you have huge amount of data in your cluster this could be an expensive task. We have tested it and here you have a compatibility matrix that states between which versions it is not needed to delete the index: -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| From\\ To | 3.0.3.0 | 3.0.3.1 | 3.0.4.0 | 3.0.4.1 | 3.0.5.0 | 3.0.5.1 | 3.0.5.2 | 3.0.6.0 | 3.0.6.1 | 3.0.6.2 | 3.0.7.0 | 3.0.7.1 | -+===========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+ -| 2.x | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.3.0 | -- | YES | YES | NO | NO | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.3.1 | -- | -- | YES | NO | NO | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.4.0 | -- | -- | -- | NO | NO | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.4.1 | -- | -- | -- | -- | YES | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.5.0 | -- | -- | -- | -- | -- | NO | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.5.1 | -- | -- | -- | -- | -- | -- | NO | NO | NO | NO | NO | NO | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.5.2 | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | YES | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.6.0 | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.6.1 | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.7.0 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ -| 3.0.7.1 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | -+-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| From\\ To | 3.0.3.0 | 3.0.3.1 | 3.0.4.0 | 3.0.4.1 | 3.0.5.0 | 3.0.5.1 | 3.0.5.2 | 3.0.6.0 | 3.0.6.1 | 3.0.6.2 | 3.0.7.0 | 3.0.7.1 | 3.0.7.2 | 3.0.8.0 | 3.0.8.1 | 3.0.8.2 | ++===========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+=========+ +| 2.x | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.3.0 | -- | YES | YES | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.3.1 | -- | -- | YES | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.4.0 | -- | -- | -- | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.4.1 | -- | -- | -- | -- | YES | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.5.0 | -- | -- | -- | -- | -- | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.5.1 | -- | -- | -- | -- | -- | -- | NO | NO | NO | NO | NO | NO | NO | NO | NO | NO | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.5.2 | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | YES | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.6.0 | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.6.1 | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.6.2 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.7.0 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.7.1 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.7.2 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.8.0 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | \(1\) | \(1\) | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| 3.0.8.1 | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | YES | ++-----------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ + +**(1):** Compatible only if you are not using geospatial mappers. Alternative syntaxes ==================== @@ -352,15 +369,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: @@ -370,16 +387,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. @@ -396,7 +413,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: @@ -404,8 +421,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” @@ -414,8 +431,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": @@ -423,9 +440,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: @@ -433,10 +452,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: @@ -444,11 +465,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: @@ -456,12 +479,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 @@ -470,16 +497,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 @@ -499,15 +531,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: @@ -519,7 +553,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 @@ -531,24 +565,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 : "" (,