Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/bcui/sensei into pullRequ…

…est#35
  • Loading branch information...
commit d551a74eb5342f2e7925330f5f44987e569f4ec6 2 parents 06fdc58 + 2dae030
alperez authored
Showing with 23,668 additions and 19,133 deletions.
  1. +9 −0 clients/java/src/main/java/com/senseidb/search/client/json/BQLException.java
  2. +3 −1 clients/java/src/main/java/com/senseidb/search/client/json/JsonDeserializer.java
  3. +11 −8 clients/java/src/main/java/com/senseidb/search/client/json/SenseiServiceProxy.java
  4. +4 −4 clients/java/src/main/java/com/senseidb/search/client/json/req/FacetInit.java
  5. +10 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/FacetType.java
  6. +27 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/MapReduce.java
  7. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/Range.java
  8. +16 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/RequestMetadata.java
  9. +2 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/Selection.java
  10. +36 −15 clients/java/src/main/java/com/senseidb/search/client/json/req/SenseiClientRequest.java
  11. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/Sort.java
  12. +23 −24 clients/java/src/main/java/com/senseidb/search/client/json/req/Term.java
  13. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/Terms.java
  14. +0 −6 clients/java/src/main/java/com/senseidb/search/client/json/req/filter/Filter.java
  15. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/filter/Ids.java
  16. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/BoolQuery.java
  17. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/CustomQuery.java
  18. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/DisMax.java
  19. +15 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/query/FieldAwareQuery.java
  20. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/FilteredQuery.java
  21. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/MatchAllQuery.java
  22. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/PathQuery.java
  23. +12 −1 clients/java/src/main/java/com/senseidb/search/client/json/req/query/Query.java
  24. +6 −2 clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryJsonHandler.java
  25. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryPrefix.java
  26. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryWildcard.java
  27. +1 −9 clients/java/src/main/java/com/senseidb/search/client/json/req/query/StringQuery.java
  28. +1 −35 clients/java/src/main/java/com/senseidb/search/client/json/req/query/TextQuery.java
  29. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanFirst.java
  30. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanNear.java
  31. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanNot.java
  32. +1 −1  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanOr.java
  33. +2 −21 clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanTerm.java
  34. +70 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/Model.java
  35. +18 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/Relevance.java
  36. +10 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceFacetType.java
  37. +78 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceValues.java
  38. +24 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceValuesHandler.java
  39. +18 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/SaveAs.java
  40. +14 −0 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/VariableType.java
  41. +19 −0 clients/java/src/main/java/com/senseidb/search/client/json/res/Error.java
  42. +3 −3 clients/java/src/main/java/com/senseidb/search/client/json/res/SenseiHit.java
  43. +26 −1 clients/java/src/main/java/com/senseidb/search/client/json/res/SenseiResult.java
  44. +11 −3 clients/java/src/test/java/com/senseidb/test/client/json/Examples.java
  45. +59 −4 clients/java/src/test/java/com/senseidb/test/client/json/JavaClientIntegrationTest.java
  46. +2 −1  clients/java/src/test/java/com/senseidb/test/client/json/JsonSerializationTest.java
  47. +44 −0 clients/java/src/test/java/com/senseidb/test/client/json/RelevanceExample.java
  48. +2 −1  clients/java/src/test/java/com/senseidb/test/client/json/TweetsTest.java
  49. +2 −2 sensei-core/pom.xml
  50. +59 −4 sensei-core/src/main/antlr3/com/senseidb/bql/parsers/BQL.g
  51. +24 −17 sensei-core/src/main/java/com/senseidb/cluster/client/SenseiNetworkClient.java
  52. +134 −134 sensei-core/src/main/java/com/senseidb/cluster/routing/ConsistentHashLoadBalancer.java
  53. +24 −24 sensei-core/src/main/java/com/senseidb/cluster/routing/ConsistentHashLoadBalancerFactory.java
  54. +93 −93 sensei-core/src/main/java/com/senseidb/cluster/routing/RingHashLoadBalancer.java
  55. +26 −26 sensei-core/src/main/java/com/senseidb/cluster/routing/RingHashLoadBalancerFactory.java
  56. +1 −2  sensei-core/src/main/java/com/senseidb/cluster/routing/RoutingInfo.java
  57. +10 −10 sensei-core/src/main/java/com/senseidb/cluster/routing/SenseiLoadBalancer.java
  58. +12 −12 sensei-core/src/main/java/com/senseidb/cluster/routing/SenseiLoadBalancerFactory.java
  59. +36 −0 sensei-core/src/main/java/com/senseidb/cluster/routing/SenseiPartitionedLoadBalancerFactory.java
  60. +80 −80 sensei-core/src/main/java/com/senseidb/cluster/routing/UniformPartitionedLoadBalancer.java
  61. +36 −36 sensei-core/src/main/java/com/senseidb/cluster/routing/UniformPartitionedRoutingFactory.java
  62. +1 −1  sensei-core/src/main/java/com/senseidb/conf/SchemaConverter.java
  63. +2 −0  sensei-core/src/main/java/com/senseidb/conf/SenseiConfParams.java
  64. +42 −9 sensei-core/src/main/java/com/senseidb/conf/SenseiFacetHandlerBuilder.java
  65. +57 −6 sensei-core/src/main/java/com/senseidb/conf/SenseiSchema.java
  66. +120 −78 sensei-core/src/main/java/com/senseidb/conf/SenseiServerBuilder.java
  67. +1 −1  sensei-core/src/main/java/com/senseidb/dataprovider/http/HttpStreamDataProvider.java
  68. +1 −1  sensei-core/src/main/java/com/senseidb/gateway/file/LinedFileDataProvider.java
  69. +23 −6 sensei-core/src/main/java/com/senseidb/indexing/DefaultStreamingIndexingManager.java
  70. +162 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/ActivityIntStorage.java
  71. +153 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/ActivityIntValues.java
  72. +10 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/ActivityValues.java
  73. +170 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/CompositeActivityManager.java
  74. +173 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/CompositeActivityStorage.java
  75. +329 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/CompositeActivityValues.java
  76. +62 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/Metadata.java
  77. +25 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/UpdateBatch.java
  78. +8 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/deletion/DeletionListener.java
  79. +53 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/deletion/HourglassAdapterDeletionAdapter.java
  80. +71 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/deletion/PurgeFilterWrapper.java
  81. +9 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/deletion/ZoieRetireListener.java
  82. +168 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/facet/ActivityRangeFacetHandler.java
  83. +47 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/facet/ActivityRangeFilterIterator.java
  84. +27 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/facet/ActivityRangeFilterSynchronizedIterator.java
  85. +179 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/facet/SynchronizedActivityRangeFacetHandler.java
  86. +138 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/time/AggregatesUpdateJob.java
  87. +40 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/time/Clock.java
  88. +100 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/time/IntContainer.java
  89. +338 −0 sensei-core/src/main/java/com/senseidb/indexing/activity/time/TimeAggregatedActivityValues.java
  90. +11 −0 sensei-core/src/main/java/com/senseidb/plugin/SenseiPluginRegistry.java
  91. +2 −2 sensei-core/src/main/java/com/senseidb/search/facet/UIDFacetHandler.java
  92. +4 −3 sensei-core/src/main/java/com/senseidb/search/facet/attribute/PredicateFacetFilter.java
  93. +104 −139 sensei-core/src/main/java/com/senseidb/search/node/AbstractConsistentHashBroker.java
  94. +3 −3 sensei-core/src/main/java/com/senseidb/search/node/AbstractSenseiBroker.java
  95. +5 −2 sensei-core/src/main/java/com/senseidb/search/node/AbstractSenseiScatterGatherHandler.java
  96. +15 −1 sensei-core/src/main/java/com/senseidb/search/node/ResultMerger.java
  97. +29 −32 sensei-core/src/main/java/com/senseidb/search/node/SenseiBroker.java
  98. +11 −0 sensei-core/src/main/java/com/senseidb/search/node/SenseiCore.java
  99. +9 −2 sensei-core/src/main/java/com/senseidb/search/node/SenseiHourglassFactory.java
  100. +3 −0  sensei-core/src/main/java/com/senseidb/search/node/SenseiScatterGatherHandler.java
  101. +31 −28 sensei-core/src/main/java/com/senseidb/search/node/SenseiServer.java
  102. +36 −99 sensei-core/src/main/java/com/senseidb/search/node/SenseiSysBroker.java
  103. +1 −1  sensei-core/src/main/java/com/senseidb/search/query/AbstractScoreAdjuster.java
  104. +13 −2 sensei-core/src/main/java/com/senseidb/search/query/QueryConstructor.java
  105. +94 −10 sensei-core/src/main/java/com/senseidb/search/query/ScoreAugmentQuery.java
  106. +3 −4 sensei-core/src/main/java/com/senseidb/search/query/filters/SenseiTermFilter.java
  107. +12 −0 sensei-core/src/main/java/com/senseidb/search/relevance/CustomRelevanceFunction.java
  108. +72 −0 sensei-core/src/main/java/com/senseidb/search/relevance/ModelStorage.java
  109. +141 −0 sensei-core/src/main/java/com/senseidb/search/relevance/RelevanceFunctionBuilder.java
  110. +0 −2,201 sensei-core/src/main/java/com/senseidb/search/relevance/RelevanceQuery.java
  111. +734 −0 sensei-core/src/main/java/com/senseidb/search/relevance/RuntimeRelevanceFunction.java
  112. +1,291 −0 sensei-core/src/main/java/com/senseidb/search/relevance/impl/CompilationHelper.java
  113. +2 −2 sensei-core/src/main/java/com/senseidb/search/relevance/{CustomScorer.java → impl/CustomMathModel.java}
  114. +74 −0 sensei-core/src/main/java/com/senseidb/search/relevance/impl/CustomScorer.java
  115. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacet.java
  116. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetDouble.java
  117. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetFloat.java
  118. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetInt.java
  119. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetLong.java
  120. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetShort.java
  121. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/MFacetString.java
  122. +186 −0 sensei-core/src/main/java/com/senseidb/search/relevance/impl/RelevanceJSONConstants.java
  123. +115 −0 sensei-core/src/main/java/com/senseidb/search/relevance/impl/RelevanceQuery.java
  124. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacet.java
  125. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetDouble.java
  126. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetFloat.java
  127. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetInt.java
  128. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetLong.java
  129. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetShort.java
  130. +1 −1  sensei-core/src/main/java/com/senseidb/search/relevance/{ → impl}/WeightedMFacetString.java
  131. +1 −0  sensei-core/src/main/java/com/senseidb/search/req/AbstractSenseiRequest.java
  132. +1 −0  sensei-core/src/main/java/com/senseidb/search/req/AbstractSenseiResult.java
  133. +13 −0 sensei-core/src/main/java/com/senseidb/search/req/ErrorType.java
  134. +59 −0 sensei-core/src/main/java/com/senseidb/search/req/SenseiError.java
  135. +38 −3 sensei-core/src/main/java/com/senseidb/search/req/SenseiRequest.java
  136. +11 −1 sensei-core/src/main/java/com/senseidb/search/req/SenseiResult.java
  137. +9 −1 sensei-core/src/main/java/com/senseidb/search/req/SenseiSystemInfo.java
  138. +5 −0 sensei-core/src/main/java/com/senseidb/search/req/mapred/CombinerStage.java
  139. +7 −1 sensei-core/src/main/java/com/senseidb/search/req/mapred/FieldAccessor.java
  140. +40 −4 sensei-core/src/main/java/com/senseidb/search/req/mapred/SenseiMapReduce.java
  141. +2 −1  sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/AvgMapReduce.java
  142. +2 −4 sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/DistinctCountMapReduce.java
  143. +2 −1  sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/HashSetDistinctCountMapReduce.java
  144. +6 −5 sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/MaxMapReduce.java
  145. +2 −1  sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/MinMapReduce.java
  146. +2 −1  sensei-core/src/main/java/com/senseidb/search/req/mapred/functions/SumMapReduce.java
  147. +7 −5 sensei-core/src/main/java/com/senseidb/search/req/mapred/impl/SenseiMapFunctionWrapper.java
  148. +3 −1 sensei-core/src/main/java/com/senseidb/search/req/mapred/impl/SenseiReduceFunctionWrapper.java
  149. +0 −107 sensei-core/src/main/java/com/senseidb/search/req/mapred/obsolete/MapReduceBroker.java
  150. +0 −17 sensei-core/src/main/java/com/senseidb/search/req/mapred/obsolete/MapReduceJob.java
  151. +0 −49 sensei-core/src/main/java/com/senseidb/search/req/mapred/obsolete/MapReduceRequest.java
  152. +0 −69 sensei-core/src/main/java/com/senseidb/search/req/mapred/obsolete/MapReduceSenseiService.java
  153. +0 −29 sensei-core/src/main/java/com/senseidb/search/req/mapred/obsolete/SenseiMapReduceResult.java
  154. +45 −82 sensei-core/src/main/java/com/senseidb/servlet/AbstractSenseiClientServlet.java
  155. +24 −1 sensei-core/src/main/java/com/senseidb/servlet/DefaultSenseiJSONServlet.java
  156. +2 −4 sensei-core/src/main/java/com/senseidb/servlet/SenseiHttpInvokerServiceServlet.java
  157. +8 −10 sensei-core/src/main/java/com/senseidb/servlet/ZookeeperConfigurableServlet.java
  158. +36 −13 sensei-core/src/main/java/com/senseidb/svc/impl/AbstractSenseiCoreService.java
  159. +7 −10 sensei-core/src/main/java/com/senseidb/svc/impl/ClusteredSenseiServiceImpl.java
  160. +1 −1  sensei-core/src/main/java/com/senseidb/util/RequestConverter2.java
  161. +288 −288 sensei-core/src/test/java/com/senseidb/cluster/routing/TestLoadBalancer.java
  162. +20 −0 sensei-core/src/test/java/com/senseidb/gateway/file/BitSetPurgeFilter.java
  163. +57 −0 sensei-core/src/test/java/com/senseidb/gateway/file/FileDataProviderWithMocks.java
  164. +43 −0 sensei-core/src/test/java/com/senseidb/gateway/file/LinedFileDataProviderMockBuilder.java
  165. +43 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/ActivityIntValuesIntTest.java
  166. +240 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/ActivityIntegrationTest.java
  167. +136 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/PersistentColumnManagerTest.java
  168. +24 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/Wait.java
  169. +75 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/time/ActivityIntValuesSynchronizedDecorator.java
  170. +46 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/time/IntContainerTest.java
  171. +60 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/time/TimeAggregatedActivityInitTest.java
  172. +86 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/time/TimeAggregatedActivityPerfTest.java
  173. +73 −0 sensei-core/src/test/java/com/senseidb/indexing/activity/time/TimeAggregatedActivityValuesTest.java
  174. +76 −72 sensei-core/src/test/java/com/senseidb/search/req/mapred/CountGroupByMapReduce.java
  175. +65 −0 sensei-core/src/test/java/com/senseidb/search/req/mapred/DistinctUIDCount.java
  176. +45 −0 sensei-core/src/test/java/com/senseidb/search/req/mapred/ListAllUIDs.java
  177. +0 −60 sensei-core/src/test/java/com/senseidb/search/req/mapred/MaxTestMapReduce.java
  178. +17 −18 sensei-core/src/test/java/com/senseidb/search/req/mapred/TestMapReduce.java
  179. +170 −0 sensei-core/src/test/java/com/senseidb/test/ErrorHandlingTest.java
  180. +6 −11 sensei-core/src/test/java/com/senseidb/test/SenseiStarter.java
  181. +3 −1 sensei-core/src/test/java/com/senseidb/test/SenseiTestSuite.java
  182. +1 −1  sensei-core/src/test/java/com/senseidb/test/TestSensei.java
  183. +32 −0 sensei-core/src/test/java/com/senseidb/test/bql/parsers/TestBQL.java
  184. +28 −0 sensei-core/src/test/java/com/senseidb/test/bql/parsers/TestErrorHandling.java
  185. +2 −2 sensei-core/src/test/json/sensei-request.json
  186. +15,000 −15,000 sensei-core/src/test/resources/data/test_data.json
  187. +14 −1 sensei-core/src/test/resources/test-conf/node1/schema.xml
  188. +3 −2 sensei-core/src/test/resources/test-conf/node1/sensei.properties
  189. +15 −1 sensei-core/src/test/resources/test-conf/node2/schema.xml
  190. +2 −2 sensei-core/src/test/resources/test-conf/node2/sensei.properties
  191. +6 −4 sensei-core/src/test/resources/test-conf/sensei-test.spring
  192. +6 −6 sensei-war/src/main/java/com/senseidb/servlet/SenseiNodeServlet.java
View
9 clients/java/src/main/java/com/senseidb/search/client/json/BQLException.java
@@ -0,0 +1,9 @@
+package com.senseidb.search.client.json;
+
+public class BQLException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public BQLException(String message) {
+ super(message);
+ }
+}
View
4 clients/java/src/main/java/com/senseidb/search/client/json/JsonDeserializer.java
@@ -65,7 +65,9 @@ else if (type == Boolean.class) {
value = jsonObject.optString(name);
} else if (type == Double.class) {
value = jsonObject.optDouble(name);
- } else if (type.isEnum()) {
+ } else if (type == JSONObject.class) {
+ value = jsonObject.optJSONObject(name);
+ }else if (type.isEnum()) {
value = jsonObject.optString(name);
if (value != null) {
value = Enum.valueOf((Class)type, value.toString());
View
19 clients/java/src/main/java/com/senseidb/search/client/json/SenseiServiceProxy.java
@@ -24,7 +24,7 @@
import com.senseidb.search.client.json.req.SenseiClientRequest;
import com.senseidb.search.client.json.res.SenseiResult;
public class SenseiServiceProxy {
- private static Logger LOG = LoggerFactory.getLogger(SenseiServiceProxy.class);
+ // private static Logger LOG = LoggerFactory.getLogger(SenseiServiceProxy.class);
private String host;
@@ -68,13 +68,16 @@ public SenseiResult sendSearchRequest( SenseiClientRequest request) {
throw new RuntimeException(ex);
}
}
- public SenseiResult sendBQL( String bql) {
+ public SenseiResult sendBQL( String bql) throws BQLException {
try {
StringBuilder buffer = new StringBuilder();
buffer.append("{'bql':").append(bql).append("}");
String requestStr = buffer.toString();
String output = sendPostRaw(getSearchUrl(), requestStr);
//System.out.println("Output from Server = " + output);
+ if (output.indexOf("\"error\"") < 5 && output.indexOf("\"error\"") >= 0) {
+ throw new BQLException(output);
+ }
return JsonDeserializer.deserialize(SenseiResult.class, jsonResponse(output));
} catch (Exception ex) {
throw new RuntimeException(ex);
@@ -173,13 +176,13 @@ public String sendPostRaw(String urlStr, String requestStr){
public String sendPostRaw(String urlStr, String requestStr,Map<String,String> headers){
HttpURLConnection conn = null;
try {
- if (LOG.isInfoEnabled()){
+ /*if (LOG.isInfoEnabled()){
LOG.info("Sending a post request to the server - " + urlStr);
}
if (LOG.isDebugEnabled()){
LOG.debug("The request is - " + requestStr);
- }
+ }*/
URL url = new URL(urlStr);
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
@@ -209,9 +212,9 @@ public String sendPostRaw(String urlStr, String requestStr,Map<String,String> he
os.close();
int responseCode = conn.getResponseCode();
- if (LOG.isInfoEnabled()){
+ /*if (LOG.isInfoEnabled()){
LOG.info("The http response code is " + responseCode);
- }
+ }*/
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Failed : HTTP error code : "
+ responseCode);
@@ -219,9 +222,9 @@ public String sendPostRaw(String urlStr, String requestStr,Map<String,String> he
byte[] bytes = drain(new GZIPInputStream(new BufferedInputStream( conn.getInputStream())));
String output = new String(bytes, "UTF-8");
- if (LOG.isDebugEnabled()){
+ /*if (LOG.isDebugEnabled()){
LOG.debug("The response from the server is - " + output);
- }
+ }*/
return output;
} catch (Exception ex) {
throw new RuntimeException (ex);
View
8 clients/java/src/main/java/com/senseidb/search/client/json/req/FacetInit.java
@@ -6,15 +6,15 @@
public class FacetInit {
String type; List<Object> values;
- public static FacetInit build(String type, Object... values) {
+ public static FacetInit build(FacetType type, Object... values) {
FacetInit facetInit = new FacetInit();
- facetInit.type = type;
+ facetInit.type = type.getValue();
facetInit.values = Arrays.asList(values);
return facetInit;
}
- public static FacetInit build(String type, List<Object> values) {
+ public static FacetInit build(FacetType type, List<Object> values) {
FacetInit facetInit = new FacetInit();
- facetInit.type = type;
+ facetInit.type = type.getValue();
facetInit.values = values;
return facetInit;
}
View
10 clients/java/src/main/java/com/senseidb/search/client/json/req/FacetType.java
@@ -0,0 +1,10 @@
+package com.senseidb.search.client.json.req;
+
+public enum FacetType {
+ type_int, type_long, type_double, type_float, type_short, type_string;
+
+
+ public String getValue() {
+ return this.name().substring("type_".length());
+ }
+}
View
27 clients/java/src/main/java/com/senseidb/search/client/json/req/MapReduce.java
@@ -0,0 +1,27 @@
+package com.senseidb.search.client.json.req;
+
+
+import java.util.Map;
+
+public class MapReduce {
+ private String function;
+ private Map<String, Object> parameters;
+ public String getFunction() {
+ return function;
+ }
+ public void setFunction(String function) {
+ this.function = function;
+ }
+ public Map<String, Object> getParameters() {
+ return parameters;
+ }
+ public void setParameters(Map<String, Object> parameters) {
+ this.parameters = parameters;
+ }
+ public MapReduce(String function, Map<String, Object> parameters) {
+ super();
+ this.function = function;
+ this.parameters = parameters;
+ }
+
+}
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/Range.java
@@ -50,7 +50,7 @@
*
*
*/
- public class Range extends Selection implements Query{
+ public class Range extends Selection {
private String from;
private String to;
View
16 clients/java/src/main/java/com/senseidb/search/client/json/req/RequestMetadata.java
@@ -0,0 +1,16 @@
+package com.senseidb.search.client.json.req;
+
+import java.util.List;
+
+import com.senseidb.search.client.json.JsonField;
+
+public class RequestMetadata {
+ @JsonField("select_list")
+ private List<String> shownOnlyFields;
+
+ public RequestMetadata(List<String> shownOnlyFields) {
+ super();
+ this.shownOnlyFields = shownOnlyFields;
+ }
+
+}
View
3  clients/java/src/main/java/com/senseidb/search/client/json/req/Selection.java
@@ -8,9 +8,10 @@
import com.senseidb.search.client.json.CustomJsonHandler;
import com.senseidb.search.client.json.req.filter.Filter;
+import com.senseidb.search.client.json.req.query.Query;
@CustomJsonHandler(SelectionJsonHandler.class)
-public abstract class Selection implements Filter {
+public abstract class Selection extends Query {
private String field;
public String getField() {
View
51 clients/java/src/main/java/com/senseidb/search/client/json/req/SenseiClientRequest.java
@@ -7,10 +7,12 @@
import java.util.Map;
import com.senseidb.search.client.json.CustomJsonHandler;
+import com.senseidb.search.client.json.JsonField;
import com.senseidb.search.client.json.req.filter.Filter;
import com.senseidb.search.client.json.req.filter.FilterJsonHandler;
import com.senseidb.search.client.json.req.query.Query;
import com.senseidb.search.client.json.req.query.QueryJsonHandler;
+import com.senseidb.search.client.json.req.relevance.Relevance;
/**
* The sensei request object, that is used to send the Sensei query to the
@@ -24,7 +26,7 @@
/*
* private Paging paging;
*/
- private Integer count;
+ private Integer size;
private Integer from;
/**
@@ -41,7 +43,7 @@
* initializing parameters that are needed by all runtime facet handlers
*/
private Map<String, Map<String, FacetInit>> facetInit = new HashMap<String, Map<String, FacetInit>>();
- private List<Sort> sorts = new ArrayList<Sort>();
+ private List<Object> sort = new ArrayList<Object>();
private Map<String, Facet> facets = new HashMap<String, Facet>();
/**
* Flag indicating whether stored fields are to be fetched
@@ -77,16 +79,17 @@
*/
private Map<String, Object> templateMapping;
- /**
- * @author vzhabiuk
- *
- */
+ private MapReduce mapReduce;
+
+
+ private RequestMetadata meta;
+
public static class Builder {
private SenseiClientRequest request = new SenseiClientRequest();
- public Builder paging(int count, int offset) {
- request.count = count;
+ public Builder paging(int size, int offset) {
+ request.size = size;
request.from = offset;
return this;
}
@@ -134,7 +137,10 @@ public Builder addFacetInit(String name, Map<String, FacetInit> facetInits) {
request.facetInit.put(name, facetInits);
return this;
}
-
+ public Builder showOnlyFields(String...fields ) {
+ request.meta = new RequestMetadata(Arrays.asList(fields));
+ return this;
+ }
/**
* @see com.senseidb.search.client.json.req.SenseiClientRequest#templateMapping
*/
@@ -151,7 +157,11 @@ public Builder addSort(Sort sort) {
if (sort == null) {
throw new IllegalArgumentException("The sort should be not null");
}
- request.sorts.add(sort);
+ if ("_score".equalsIgnoreCase(sort.getField())) {
+ request.sort.add("_score");
+ } else {
+ request.sort.add(sort);
+ }
return this;
}
@@ -183,9 +193,15 @@ public Builder filter(Filter filter) {
return this;
}
+ public Builder mapReduce(String function, Map<String, Object> parameters) {
+ request.mapReduce = new MapReduce(function, parameters);
+ return this;
+ }
+
public SenseiClientRequest build() {
return request;
}
+
}
public static Builder builder() {
@@ -193,7 +209,7 @@ public static Builder builder() {
}
public Paging getPaging() {
- return new Paging(count, from);
+ return new Paging(size, from);
}
public GroupBy getGroupBy() {
@@ -208,8 +224,8 @@ public GroupBy getGroupBy() {
return facetInit;
}
- public List<Sort> getSorts() {
- return sorts;
+ public List<Object> getSorts() {
+ return sort;
}
public Map<String, Facet> getFacets() {
@@ -237,7 +253,7 @@ public String getRouteParam() {
}
public Integer getCount() {
- return count;
+ return size;
}
public Integer getFrom() {
@@ -267,5 +283,10 @@ public void setFilter(Filter filter) {
public void setSelections(List<Selection> selections) {
this.selections = selections;
}
-
+ public void setMapReduce(MapReduce mapReduce){
+ this.mapReduce = mapReduce;
+ }
+ public MapReduce getMapReduce(){
+ return mapReduce;
+ }
}
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/Sort.java
@@ -35,7 +35,7 @@ public static Sort desc(String field) {
}
public static Sort byRelevance() {
Sort sort = new Sort();
- sort.field = "relevance";
+ sort.field = "_score";
return sort;
}
public static enum Order {
View
47 clients/java/src/main/java/com/senseidb/search/client/json/req/Term.java
@@ -3,30 +3,29 @@
import com.senseidb.search.client.json.req.query.Query;
/**
- * <p>Matches documents that have fields that contain a term (<strong>not analyzed</strong>). The term query maps to Sensei <code>TermQuery</code>. The following matches documents where the user field contains the term <code>kimchy</code>:</p>
-<pre class="prettyprint lang-js"><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"term"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"user"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"kimchy"</span><span class="pln"> </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span><span class="pln"> &nbsp; &nbsp;</span></pre>
+ * <p>
+ * Matches documents that have fields that contain a term (<strong>not
+ * analyzed</strong>). The term query maps to Sensei <code>TermQuery</code>. The
+ * following matches documents where the user field contains the term
+ * <code>kimchy</code>:
+ * </p>
+ *
+ */
+public class Term extends Selection {
+ private String value;
+ private double boost;
-<p>A boost can also be associated with the query:</p>
-<pre class="prettyprint lang-js"><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"term"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"user"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"value"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"kimchy"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"boost"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="lit">2.0</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span><span class="pln"> &nbsp; &nbsp;</span></pre>
+ public Term(String value) {
+ super();
+ this.value = value;
+ }
-<p>Or :</p>
-<pre class="prettyprint lang-js"><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"term"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"user"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"term"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"kimchy"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"boost"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="lit">2.0</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span><span class="pln"> &nbsp; &nbsp;</span></pre>
+ public Term(String value, double boost) {
+ super();
+ this.value = value;
+ this.boost = boost;
+ }
-
- *
- */
- public class Term extends Selection implements Query {
- private String value;
- private double boost;
- public Term(String value) {
- super();
- this.value = value;
- }
- public Term(String value, double boost) {
- super();
- this.value = value;
- this.boost = boost;
- }
- public Term(){
- }
- }
+ public Term() {
+ }
+}
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/Terms.java
@@ -20,7 +20,7 @@
*
*
*/
-public class Terms extends Selection implements Query {
+public class Terms extends Selection {
List<String> values;
List<String> excludes;
View
6 clients/java/src/main/java/com/senseidb/search/client/json/req/filter/Filter.java
@@ -14,12 +14,6 @@
* href="bool-filter.html">bool</a> filter. Can be placed within queries that
* accept a filter.
* </p>
- *
- * <pre class="prettyprint lang-js">
- * </pre>
- *
- *
- *
*/
public static class AndOr implements Filter {
List<Filter> filters = new ArrayList<Filter>();;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/filter/Ids.java
@@ -15,7 +15,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class Ids implements Filter, Query {
+public class Ids extends Query implements Filter {
List<String> values;
List<String> excludes;
private double boost;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/BoolQuery.java
@@ -17,7 +17,7 @@
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class BoolQuery implements Query {
+public class BoolQuery extends Query {
List<Query> must;
List<Query> must_not;
List<Query> should;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/CustomQuery.java
@@ -11,7 +11,7 @@
*
*/
@CustomJsonHandler(value = QueryJsonHandler.class)
-public class CustomQuery implements Query {
+public class CustomQuery extends Query {
@JsonField("class")
private String cls;
private Map<String, String> params = new HashMap<String, String>();
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/DisMax.java
@@ -38,7 +38,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class DisMax implements Query {
+public class DisMax extends Query {
@JsonField("tie_braker")
private double tieBraker;
private double boost;
View
15 clients/java/src/main/java/com/senseidb/search/client/json/req/query/FieldAwareQuery.java
@@ -0,0 +1,15 @@
+package com.senseidb.search.client.json.req.query;
+
+public class FieldAwareQuery extends Query {
+ protected String field;
+
+ public FieldAwareQuery setField(String field) {
+ this.field = field;
+ return this;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+}
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/FilteredQuery.java
@@ -20,7 +20,7 @@
*
*/
@CustomJsonHandler(value = QueryJsonHandler.class)
-public class FilteredQuery implements Query {
+public class FilteredQuery extends Query {
private Query query;
@CustomJsonHandler(value = FilterJsonHandler.class, flatten = false)
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/MatchAllQuery.java
@@ -17,7 +17,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class MatchAllQuery implements Query {
+public class MatchAllQuery extends Query {
double boost;
public MatchAllQuery(double boost) {
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/PathQuery.java
@@ -3,7 +3,7 @@
import com.senseidb.search.client.json.CustomJsonHandler;
@CustomJsonHandler(value = QueryJsonHandler.class)
-public class PathQuery extends FieldAware implements Query {
+public class PathQuery extends FieldAwareQuery {
private String value;
private double boost;
View
13 clients/java/src/main/java/com/senseidb/search/client/json/req/query/Query.java
@@ -1,7 +1,18 @@
package com.senseidb.search.client.json.req.query;
import com.senseidb.search.client.json.req.filter.Filter;
+import com.senseidb.search.client.json.req.relevance.Relevance;
-public interface Query extends Filter {
+public abstract class Query implements Filter {
+ private Relevance relevance;
+
+ public Query setRelevance(Relevance relevance) {
+ this.relevance = relevance;
+ return this;
+ }
+ public Relevance getRelevance() {
+ return relevance;
+ }
+
}
View
8 clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryJsonHandler.java
@@ -54,19 +54,23 @@ public JSONObject serialize(Query bean) throws JSONException {
+ " is not supported for serialization by the QueryJsonHandler");
}
JSONObject defaultSerialization = (JSONObject) JsonSerializer.serialize(bean, false);
- if (bean instanceof FieldAware) {
+ if (bean instanceof FieldAwareQuery) {
defaultSerialization.remove("field");
if (bean instanceof SpanTerm && ((SpanTerm) bean).getBoost() == null) {
SpanTerm spanTerm = (SpanTerm) bean;
defaultSerialization = new JSONObject().put(spanTerm.getField(), spanTerm.getValue());
} else {
- defaultSerialization = new JSONObject().put(((FieldAware) bean).getField(), defaultSerialization);
+ defaultSerialization = new JSONObject().put(((FieldAwareQuery) bean).getField(), defaultSerialization);
}
}
if (bean instanceof Selection) {
defaultSerialization.remove("field");
defaultSerialization = new JSONObject().put(((Selection) bean).getField(), defaultSerialization);
}
+ if (bean.getRelevance() != null) {
+ defaultSerialization.remove("relevance");
+ defaultSerialization.put("relevance", JsonSerializer.serialize(bean.getRelevance()));
+ }
return new JSONObject().put(typeNames.get(bean.getClass()), defaultSerialization);
}
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryPrefix.java
@@ -31,7 +31,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class QueryPrefix extends FieldAware implements Query {
+public class QueryPrefix extends FieldAwareQuery {
private String value;
private double boost;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/QueryWildcard.java
@@ -18,7 +18,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class QueryWildcard extends FieldAware implements Query {
+public class QueryWildcard extends FieldAwareQuery {
private String value;
private double boost;
View
10 clients/java/src/main/java/com/senseidb/search/client/json/req/query/StringQuery.java
@@ -122,10 +122,6 @@
* (the <code>name</code> is boosted by 5 using <code>^5</code> notation):
* </p>
*
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"query_string"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"fields"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">"content"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"name^5"</span><span class="pun">],</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this AND that OR thus"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"use_dis_max"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <p>
* When running the <code>query_string</code> query against multiple fields, the
* following additional parameters are allowed:
@@ -158,13 +154,9 @@
* included). For example:
* </p>
*
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"query_string"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"fields"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">"content"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"name.*^5"</span><span class="pun">],</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this AND that OR thus"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"use_dis_max"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>
- * </span><span class="pun">}</span>
- *
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class StringQuery implements Filter, Query {
+public class StringQuery extends Query {
@JsonField("default_field")
private String defaultField;
private String query;
View
36 clients/java/src/main/java/com/senseidb/search/client/json/req/query/TextQuery.java
@@ -48,29 +48,16 @@
* change in structure, <code>message</code> is the field name):
* </p>
*
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"operator"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"and"</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <h3>phrase</h3>
* <p>
* The <code>text_phrase</code> query analyzes the text and creates a
* <code>phrase</code> query out of the analyzed text. For example:
* </p>
- *
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text_phrase"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <p>
* Since <code>text_phrase</code> is only a <code>type</code> of a
* <code>text</code> query, it can also be used in the following manner:
* </p>
*
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"type"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"phrase"</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <p>
* A phrase query maintains order of the terms up to a configurable
* <code>slop</code> (which defaults to 0).
@@ -81,29 +68,15 @@
* definition, or the default search analyzer, for example:
* </p>
*
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text_phrase"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"analyzer"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"my_analyzer"</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <h3>text_phrase_prefix</h3>
* <p>
* The <code>text_phrase_prefix</code> is the same as <code>text_phrase</code>,
* expect it allows for prefix matches on the last term in the text. For
* example:
* </p>
- *
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text_phrase_prefix"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <p>
* Or:
* </p>
- *
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"type"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"phrase_prefix"</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <p>
* It accepts the same parameters as the phrase type. In addition, it also
* accepts a <code>max_expansions</code> parameter that can control to how many
@@ -111,11 +84,6 @@
* to an acceptable value to control the execution time of the query. For
* example:
* </p>
- *
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"text_phrase_prefix"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"message"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"query"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"this is a test"</span><span class="pun">,</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="str">"max_expansions"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span>
- * </pre>
- *
* <h2>Comparison to query_string / field</h2>
* <p>
* The text family of queries does not go through a “query parsing” process. It
@@ -126,11 +94,9 @@
* box does). Also, the <code>phrase_prefix</code> can provide a great “as you
* type” behavior to automatically load search results.
* </p>
- *
- *
*/
@CustomJsonHandler(value = QueryJsonHandler.class)
-public class TextQuery extends FieldAware implements Query {
+public class TextQuery extends FieldAwareQuery {
private String value;
private Operator operator;
private Type type;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanFirst.java
@@ -19,7 +19,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class SpanFirst implements Query {
+public class SpanFirst extends Query {
SpanTerm match;
int end;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanNear.java
@@ -25,7 +25,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class SpanNear implements Query {
+public class SpanNear extends Query {
List<SpanTerm> clauses;
private int slop;
@JsonField("in_order")
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanNot.java
@@ -21,7 +21,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class SpanNot implements Query {
+public class SpanNot extends Query {
SpanTerm include;
View
2  clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanOr.java
@@ -21,7 +21,7 @@
*
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class SpanOr implements Query {
+public class SpanOr extends Query {
List<SpanTerm> clauses;
private final Double boost;
View
23 clients/java/src/main/java/com/senseidb/search/client/json/req/query/span/SpanTerm.java
@@ -3,35 +3,16 @@
import java.util.List;
import com.senseidb.search.client.json.CustomJsonHandler;
-import com.senseidb.search.client.json.req.query.FieldAware;
-import com.senseidb.search.client.json.req.query.Query;
+import com.senseidb.search.client.json.req.query.FieldAwareQuery;
import com.senseidb.search.client.json.req.query.QueryJsonHandler;
/**
* <p>
* Matches spans containing a term. The span term query maps to Sensei
* <code>SpanTermQuery</code>. Here is an example:
- * </p>
- *
- * <pre class="prettyprint lang-js">
- * <span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="str">"span_term"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="str">"user"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"kimchy"</span><span class="pln"> </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span><span class="pln"> &nbsp; &nbsp;</span>
- * </pre>
- *
- * <p>
- * A boost can also be associated with the query:
- * </p>
- *
- *
- * <p>
- * Or :
- * </p>
- *
- *
- *
- *
*/
@CustomJsonHandler(QueryJsonHandler.class)
-public class SpanTerm extends FieldAware implements Query {
+public class SpanTerm extends FieldAwareQuery {
private String value;
private Double boost;
View
70 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/Model.java
@@ -0,0 +1,70 @@
+package com.senseidb.search.client.json.req.relevance;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.senseidb.search.client.json.JsonField;
+import com.senseidb.search.client.json.req.FacetType;
+
+public class Model {
+ private Map<String, List<String>> variables = new HashMap<String, List<String>>();;
+ private Map<String, List<String>> facets = new HashMap<String, List<String>>();
+ @JsonField("function_params")
+ private List<String> functionParams = new ArrayList<String>();
+ private String function;
+ @JsonField("save_as")
+ private SaveAs saveAs;
+ public static ModelBuilder builder() {
+ return new ModelBuilder();
+ }
+
+ public static class ModelBuilder {
+ private final Model model;
+ public ModelBuilder() {
+ this.model = new Model();
+ }
+ public ModelBuilder function(String function) {
+ this.model.function = function;
+ return this;
+ }
+ public ModelBuilder addFunctionParams(String... params) {
+ if (params != null) {
+ this.model.functionParams.addAll(Arrays.asList(params));
+ }
+ return this;
+ }
+ public ModelBuilder addFacets(RelevanceFacetType type, String... names) {
+ if (names != null) {
+ List<String> facets = this.model.facets.get(type.getValue());
+ if (facets == null) {
+ facets = new ArrayList<String>();
+ this.model.facets.put(type.getValue(), facets);
+ }
+ facets.addAll(Arrays.asList(names));
+ }
+ return this;
+ }
+ public ModelBuilder addVariables(VariableType type, String... variables) {
+ if (variables != null) {
+ List<String> variablesList = this.model.variables.get(type.getValue());
+ if (variablesList == null) {
+ variablesList = new ArrayList<String>();
+ this.model.variables.put(type.getValue(), variablesList);
+ }
+ variablesList.addAll(Arrays.asList(variables));
+ }
+ return this;
+ }
+ public ModelBuilder saveAs(String name, boolean overwrite) {
+ this.model.saveAs = new SaveAs(name, overwrite);
+ return this;
+ }
+ public Model build() {
+ return model;
+ }
+ }
+
+}
View
18 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/Relevance.java
@@ -0,0 +1,18 @@
+package com.senseidb.search.client.json.req.relevance;
+
+import com.senseidb.search.client.json.CustomJsonHandler;
+
+public class Relevance {
+ private Model model;
+ @CustomJsonHandler(value = RelevanceValuesHandler.class)
+ private RelevanceValues values;
+ private Relevance() {
+ // TODO Auto-generated constructor stub
+ }
+ public static Relevance valueOf(Model model, RelevanceValues values) {
+ Relevance relevance = new Relevance();
+ relevance.model = model;
+ relevance.values = values;
+ return relevance;
+ }
+}
View
10 .../java/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceFacetType.java
@@ -0,0 +1,10 @@
+package com.senseidb.search.client.json.req.relevance;
+
+public enum RelevanceFacetType {
+ type_int, type_long, type_double, type_float, type_short, type_string,
+ type_mint, type_mlong, type_mdouble, type_mfloat, type_mshort, type_mstring,
+ type_wmint, type_wmlong, type_wmdouble, type_wmfloat, type_wmshort, type_wmstring;
+ public String getValue() {
+ return this.name().substring("type_".length());
+ }
+}
View
78 ...nts/java/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceValues.java
@@ -0,0 +1,78 @@
+package com.senseidb.search.client.json.req.relevance;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RelevanceValues {
+ protected Map<String, Object> values = new HashMap<String, Object>();
+
+ public static RelevanceValuesBuilder builder() {
+ return new RelevanceValuesBuilder();
+ }
+
+ public Map<String, Object> getValues() {
+ return values;
+ }
+private RelevanceValues() {
+ // TODO Auto-generated constructor stub
+}
+ public static class RelevanceValuesBuilder {
+ private RelevanceValues relevanceValues;
+
+ public RelevanceValuesBuilder() {
+ relevanceValues = new RelevanceValues();
+ }
+
+ public RelevanceValuesBuilder addListValue(String variableName, Object... values) {
+ for (Object value : values) {
+ checkType(value);
+ }
+ relevanceValues.values.put(variableName, Arrays.asList(values));
+ return this;
+ }
+
+ public RelevanceValuesBuilder addAtomicValue(String variableName, Object value) {
+ checkType(value);
+ relevanceValues.values.put(variableName, value);
+ return this;
+ }
+
+ private void checkType(Object value) {
+ if (!(value instanceof String) && !(value instanceof Number)) {
+ throw new IllegalStateException("The value should be either String or Number");
+ }
+ }
+ public RelevanceValuesBuilder addMapValue(String variableName, List keys, List values) {
+ for (int i = 0; i < keys.size(); i++) {
+ checkType(keys.get(i));
+ checkType(values.get(i));
+ }
+ Map<String, Object> ret = new HashMap<String, Object>(2);
+ ret.put("key", keys);
+ ret.put("value", values);
+ relevanceValues.values.put(variableName, ret);
+ return this;
+ }
+ public RelevanceValuesBuilder addMapValue(String variableName, Map<Object, Object> valuesMap) {
+ List<Object> keys = new ArrayList<Object>(valuesMap.size());
+ List<Object> values = new ArrayList<Object>(valuesMap.size());
+ for (Map.Entry<Object, Object> entry : valuesMap.entrySet()) {
+ checkType(entry.getKey());
+ checkType(entry.getValue());
+ keys.add(entry.getKey());
+ values.add(entry.getValue());
+ }
+ Map<String, Object> ret = new HashMap<String, Object>(2);
+ ret.put("key", keys);
+ ret.put("value", values);
+ relevanceValues.values.put(variableName, ret);
+ return this;
+ }
+ public RelevanceValues build() {
+ return relevanceValues;
+ }
+ }
+}
View
24 ...a/src/main/java/com/senseidb/search/client/json/req/relevance/RelevanceValuesHandler.java
@@ -0,0 +1,24 @@
+package com.senseidb.search.client.json.req.relevance;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.senseidb.search.client.json.JsonHandler;
+import com.senseidb.search.client.json.JsonSerializer;
+
+public class RelevanceValuesHandler implements JsonHandler<RelevanceValues>{
+
+ @Override
+ public JSONObject serialize(RelevanceValues bean) throws JSONException {
+ if (bean == null) {
+ return null;
+ }
+ return (JSONObject) JsonSerializer.serialize(bean.values);
+ }
+
+ @Override
+ public RelevanceValues deserialize(JSONObject json) throws JSONException {
+ throw new UnsupportedOperationException();
+ }
+
+}
View
18 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/SaveAs.java
@@ -0,0 +1,18 @@
+package com.senseidb.search.client.json.req.relevance;
+
+public class SaveAs {
+ private String name;
+ private boolean overwrite;
+ public SaveAs(String name, boolean overwrite) {
+ super();
+ this.name = name;
+ this.overwrite = overwrite;
+ }
+ public String getName() {
+ return name;
+ }
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+}
View
14 clients/java/src/main/java/com/senseidb/search/client/json/req/relevance/VariableType.java
@@ -0,0 +1,14 @@
+package com.senseidb.search.client.json.req.relevance;
+
+public enum VariableType {
+ set_int, set_float, set_string, set_double, set_long,
+ map_int_int,map_int_double,map_int_float,map_int_long,map_int_bool,map_int_string,
+ map_string_int,map_string_double,map_string_float,map_string_long,map_string_bool,map_string_string,
+ type_int, type_double, type_float, type_long, type_bool, type_string;
+ public String getValue() {
+ if (this.name().startsWith("type_")) {
+ return this.name().substring("type_".length());
+ }
+ return this.name();
+ }
+}
View
19 clients/java/src/main/java/com/senseidb/search/client/json/res/Error.java
@@ -0,0 +1,19 @@
+package com.senseidb.search.client.json.res;
+
+public class Error {
+ private String message;
+ private String errorType;
+ public String getMessage() {
+ return message;
+ }
+ public void setMessage(String message) {
+ this.message = message;
+ }
+ public String getErrorType() {
+ return errorType;
+ }
+ public void setErrorType(String errorType) {
+ this.errorType = errorType;
+ }
+
+}
View
6 clients/java/src/main/java/com/senseidb/search/client/json/res/SenseiHit.java
@@ -14,7 +14,7 @@
@JsonField("_docid")
private Integer docid;
@JsonField("_score")
- private Integer score;
+ private Double score;
@JsonField("_srcdata")
private String srcdata;
@JsonField("_grouphitscount")
@@ -45,7 +45,7 @@ public Integer getDocid() {
return docid;
}
- public Integer getScore() {
+ public Double getScore() {
return score;
}
@@ -69,7 +69,7 @@ public void setDocid(Integer docid) {
this.docid = docid;
}
- public void setScore(Integer score) {
+ public void setScore(Double score) {
this.score = score;
}
View
27 clients/java/src/main/java/com/senseidb/search/client/json/res/SenseiResult.java
@@ -4,6 +4,8 @@
import java.util.List;
import java.util.Map;
+import org.json.JSONObject;
+
import com.senseidb.search.client.json.JsonField;
public class SenseiResult {
@@ -17,10 +19,15 @@
private String parsedQuery;
private Long time;
private Map<String, List<FacetResult>> facets;
+
+ private JSONObject mapReduceResult;
+ private Integer errorCode;
+ private List<Error> errors = new ArrayList<Error>();
+
@Override
public String toString() {
return "SenseiResult [tid=" + tid + ", totaldocs=" + totaldocs + ", numhits=" + numhits + ", numgroups="
- + numgroups + ", \nhits=" + hits + ",\n parsedQuery=" + parsedQuery + ", time=" + time + ", \nfacets="
+ + numgroups + ", \nhits=" + hits + "\nmapReduceResult=" + mapReduceResult + ",\n parsedQuery=" + parsedQuery + ", time=" + time + ", \nfacets="
+ facets + "]";
}
public Long getTid() {
@@ -72,5 +79,23 @@ public void setFacets(Map<String, List<FacetResult>> facets) {
this.facets = facets;
}
+ public JSONObject getMapReduceResult() {
+ return mapReduceResult;
+ }
+ public void setMapReduceResult(JSONObject mapReduceResult) {
+ this.mapReduceResult = mapReduceResult;
+ }
+ public Integer getErrorCode() {
+ return errorCode;
+ }
+ public void setErrorCode(Integer errorCode) {
+ this.errorCode = errorCode;
+ }
+ public List<Error> getErrors() {
+ return errors;
+ }
+ public void setErrors(List<Error> errors) {
+ this.errors = errors;
+ }
}
View
14 clients/java/src/test/java/com/senseidb/test/client/json/Examples.java
@@ -2,7 +2,9 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.json.JSONObject;
@@ -10,6 +12,7 @@
import com.senseidb.search.client.json.SenseiServiceProxy;
import com.senseidb.search.client.json.req.Facet;
import com.senseidb.search.client.json.req.FacetInit;
+import com.senseidb.search.client.json.req.FacetType;
import com.senseidb.search.client.json.req.Operator;
import com.senseidb.search.client.json.req.Selection;
import com.senseidb.search.client.json.req.SenseiClientRequest;
@@ -49,9 +52,7 @@ public static void main(String[] args) throws Exception {
.addSelection(Selection.path("field", "value", true, 1))
.addSelection(Selection.range("color", "*", "*"))
.addFacet("facet1", Facet.builder().max(2).minHit(1).orderByVal().build())
- .addFacetInit("name", "parameter", FacetInit.build("string", "val1", "val2"))
- .addSort(Sort.desc("color"))
- .addSort(Sort.asc("year"))
+ .addFacetInit("name", "parameter", FacetInit.build(FacetType.type_double, "val1", "val2"))
.addTermVector("Term1")
.explain(true)
.partitions(Arrays.asList(1,2)) ;
@@ -99,6 +100,13 @@ public static void main(String[] args) throws Exception {
return builder;
}
+
+ public static SenseiClientRequest.Builder mapReduce(SenseiClientRequest.Builder builder) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("column", "price");
+ builder.mapReduce("com.senseidb.search.req.mapred.functions.MinMapReduce", params).build();
+ return builder;
+ }
}
View
63 clients/java/src/test/java/com/senseidb/test/client/json/JavaClientIntegrationTest.java
@@ -1,6 +1,7 @@
package com.senseidb.test.client.json;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
@@ -14,10 +15,16 @@
import com.senseidb.search.client.json.req.Operator;
import com.senseidb.search.client.json.req.Selection;
import com.senseidb.search.client.json.req.SenseiClientRequest;
+import com.senseidb.search.client.json.req.Sort;
import com.senseidb.search.client.json.req.filter.Filter;
import com.senseidb.search.client.json.req.filter.Filters;
import com.senseidb.search.client.json.req.query.Queries;
import com.senseidb.search.client.json.req.query.Query;
+import com.senseidb.search.client.json.req.relevance.Model;
+import com.senseidb.search.client.json.req.relevance.Relevance;
+import com.senseidb.search.client.json.req.relevance.RelevanceFacetType;
+import com.senseidb.search.client.json.req.relevance.RelevanceValues;
+import com.senseidb.search.client.json.req.relevance.VariableType;
import com.senseidb.search.client.json.res.SenseiResult;
@Ignore
public class JavaClientIntegrationTest extends Assert {
@@ -107,7 +114,7 @@ public void testTermQuery() throws Exception
@Test
public void testSimpleBQL() throws Exception{
- String bql = "select where color in ('red')";
+ String bql = "select * where color in ('red')";
SenseiResult res = senseiServiceProxy.sendBQL(bql);
assertEquals("numhits is wrong", 2160, res.getNumhits().intValue());
}
@@ -361,6 +368,17 @@ public void testTermFilter() throws Exception
}
@Test
+ public void testSingleField() throws Exception
+ {
+ SenseiClientRequest request = SenseiClientRequest.builder().showOnlyFields("color")
+
+ .build();
+ System.out.println(JsonSerializer.serialize(request));
+ SenseiResult res = senseiServiceProxy.sendSearchRequest( request);
+ assertEquals( 1, res.getHits().get(0).getFieldValues().size());
+
+ }
+ @Test
public void testTermsFilter() throws Exception
{
SenseiClientRequest request = SenseiClientRequest.builder().filter(
@@ -404,9 +422,46 @@ public void testGetStoreQuery() throws Exception
assertEquals(Integer.valueOf(5), ret.get(5L).get("id"));
assertEquals("automatic,hybrid,leather,reliable", ret.get(5L).get("tags"));
}
-
-
-
+ @Test
+ public void testRelevance() throws Exception
+ {
+ Model model = Model.builder().addFacets(RelevanceFacetType.type_int, "year","mileage").
+ addFacets(RelevanceFacetType.type_long, "groupid").addFacets(RelevanceFacetType.type_string, "color","category").
+ addFunctionParams("_INNER_SCORE", "thisYear", "year","goodYear","mileageWeight","mileage","color", "yearcolor", "colorweight", "category", "categorycolor").
+ addVariables(VariableType.set_int, "goodYear").addVariables(VariableType.type_int, "thisYear").
+ addVariables(VariableType.map_int_float, "mileageWeight").addVariables(VariableType.map_int_string, "yearcolor")
+ .addVariables(VariableType.map_string_float, "colorweight").addVariables(VariableType.map_string_string, "categorycolor").saveAs("model", true).
+ function(" if(categorycolor.containsKey(category) && categorycolor.get(category).equals(color)) return 10000f; if(colorweight.containsKey(color) ) return 200f + colorweight.getFloat(color); if(yearcolor.containsKey(year) && yearcolor.get(year).equals(color)) return 200f; if(mileageWeight.containsKey(mileage)) return 10000+mileageWeight.get(mileage); if(goodYear.contains(year)) return (float)Math.exp(2d); if(year==thisYear) return 87f ; return _INNER_SCORE;").build();
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ map.put("red", 335.5);
+ RelevanceValues.RelevanceValuesBuilder valuesBuilder = new RelevanceValues.RelevanceValuesBuilder().addAtomicValue("thisYear", 2001)
+ .addListValue("goodYear", 1996,1997).
+ addMapValue("mileageWeight", Arrays.asList(11400,11000), Arrays.asList(777.9, 10.2))
+ .addMapValue("colorweight", map);
+ map.clear();
+ map.put(1998, "red");
+ valuesBuilder.addMapValue("yearcolor", map);
+ valuesBuilder.addMapValue("categorycolor", Arrays.asList("compact"), Arrays.asList("white"));
+ SenseiClientRequest request = SenseiClientRequest.builder().addSort(Sort.byRelevance()).query(Queries.stringQuery("").setRelevance(Relevance.valueOf(model, valuesBuilder.build()))).build();
+ SenseiResult senseiResult = senseiServiceProxy.sendSearchRequest(request);
+ assertEquals(10777, senseiResult.getHits().get(0).getScore().intValue());
+ assertEquals(0, senseiResult.getErrorCode().intValue());
+ }
+ @Test
+ public void testError() throws Exception{
+ String bql = "select1 * where color in ('red')";
+ SenseiResult res = senseiServiceProxy.sendBQL(bql);
+ assertEquals( 150, res.getErrorCode().intValue());
+ assertEquals( 1, res.getErrors().size());
+ assertEquals( "[line:1, col:0] No viable alternative (token=select1)", res.getErrors().get(0).getMessage());
+ assertEquals( "BQLParsingError", res.getErrors().get(0).getErrorType());
+ }
+ @Test
+ public void testMapReduce() throws Exception{
+ SenseiResult res = senseiServiceProxy.sendSearchRequest(Examples.mapReduce(SenseiClientRequest.builder()).build());
+ assertEquals("{\"min\":2100,\"uid\":4757}", res.getMapReduceResult().toString());
+
+ }
/* Need to fix the bug in bobo and kamikazi, for details see the following two test cases:*/
// public void testAndFilter1() throws Exception
View
3  clients/java/src/test/java/com/senseidb/test/client/json/JsonSerializationTest.java
@@ -8,6 +8,7 @@
import com.senseidb.search.client.json.JsonDeserializer;
import com.senseidb.search.client.json.JsonSerializer;
import com.senseidb.search.client.json.req.FacetInit;
+import com.senseidb.search.client.json.req.FacetType;
import com.senseidb.search.client.json.req.SenseiClientRequest;
import com.senseidb.search.client.json.res.SenseiResult;
@@ -37,7 +38,7 @@ public void test2Serialization() throws Exception {
//@Test
public void test3DeserializeFacetInit() throws Exception {
SenseiClientRequest senseiRequest = SenseiClientRequest.builder()
- .addFacetInit("name", "parameter", FacetInit.build("string", "val1", "val2")).build();
+ .addFacetInit("name", "parameter", FacetInit.build(FacetType.type_float, "val1", "val2")).build();
String strRepresentation = JsonSerializer.serialize(senseiRequest).toString();
SenseiClientRequest senseiRequest2 = JsonDeserializer.deserialize(SenseiClientRequest.class, new JSONObject(strRepresentation));
String strRepresentation2 = JsonSerializer.serialize(senseiRequest2).toString();
View
44 clients/java/src/test/java/com/senseidb/test/client/json/RelevanceExample.java
@@ -0,0 +1,44 @@
+package com.senseidb.test.client.json;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.json.JSONObject;
+
+import com.senseidb.search.client.json.JsonSerializer;
+import com.senseidb.search.client.json.SenseiServiceProxy;
+import com.senseidb.search.client.json.req.SenseiClientRequest;
+import com.senseidb.search.client.json.req.Sort;
+import com.senseidb.search.client.json.req.query.Queries;
+import com.senseidb.search.client.json.req.relevance.Model;
+import com.senseidb.search.client.json.req.relevance.Relevance;
+import com.senseidb.search.client.json.req.relevance.RelevanceFacetType;
+import com.senseidb.search.client.json.req.relevance.RelevanceValues;
+import com.senseidb.search.client.json.req.relevance.VariableType;
+
+public class RelevanceExample {
+public static void main(String[] args) throws Exception {
+ SenseiServiceProxy senseiServiceProxy = new SenseiServiceProxy("localhost", 8080);
+ Model model = Model.builder().addFacets(RelevanceFacetType.type_int, "year","mileage").
+ addFacets(RelevanceFacetType.type_long, "groupid").addFacets(RelevanceFacetType.type_string, "color","category").
+ addFunctionParams("_INNER_SCORE", "thisYear", "year","goodYear","mileageWeight","mileage","color", "yearcolor", "colorweight", "category", "categorycolor").
+ addVariables(VariableType.set_int, "goodYear").addVariables(VariableType.type_int, "thisYear").
+ addVariables(VariableType.map_int_float, "mileageWeight").addVariables(VariableType.map_int_string, "yearcolor")
+ .addVariables(VariableType.map_string_float, "colorweight").addVariables(VariableType.map_string_string, "categorycolor").
+ function(" if(categorycolor.containsKey(category) && categorycolor.get(category).equals(color)) return 10000f; if(colorweight.containsKey(color) ) return 200f + colorweight.getFloat(color); if(yearcolor.containsKey(year) && yearcolor.get(year).equals(color)) return 200f; if(mileageWeight.containsKey(mileage)) return 10000+mileageWeight.get(mileage); if(goodYear.contains(year)) return (float)Math.exp(2d); if(year==thisYear) return 87f ; return _INNER_SCORE;").build();
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ map.put("red", 335.5);
+ RelevanceValues.RelevanceValuesBuilder valuesBuilder = new RelevanceValues.RelevanceValuesBuilder().addAtomicValue("thisYear", 2001)
+ .addListValue("goodYear", 1996,1997).
+ addMapValue("mileageWeight", Arrays.asList(11400,11000), Arrays.asList(777.9, 10.2))
+ .addMapValue("colorweight", map);
+ map.clear();
+ map.put(1998, "red");
+ valuesBuilder.addMapValue("yearcolor", map);
+ valuesBuilder.addMapValue("categorycolor", Arrays.asList("compact"), Arrays.asList("white"));
+ SenseiClientRequest request = SenseiClientRequest.builder().addSort(Sort.byRelevance()).query(Queries.stringQuery("").setRelevance(Relevance.valueOf(model, valuesBuilder.build()))).showOnlyFields("color").build();
+ System.out.println(((JSONObject)JsonSerializer.serialize(request)).toString(1));
+ System.out.println(senseiServiceProxy.sendSearchRequest(request));
+}
+}
View
3  clients/java/src/test/java/com/senseidb/test/client/json/TweetsTest.java
@@ -2,6 +2,7 @@
import com.senseidb.search.client.json.SenseiServiceProxy;
import com.senseidb.search.client.json.req.FacetInit;
+import com.senseidb.search.client.json.req.FacetType;
import com.senseidb.search.client.json.req.Selection;
import com.senseidb.search.client.json.req.SenseiClientRequest;
@@ -9,7 +10,7 @@
public static void main(String[] args) throws Exception {
SenseiClientRequest request = SenseiClientRequest.builder().addSelection(Selection.terms("timeRange", "000120000")).
- addFacetInit("timeRange", "time", FacetInit.build("long", System.currentTimeMillis())).build();
+ addFacetInit("timeRange", "time", FacetInit.build(FacetType.type_long, System.currentTimeMillis())).build();
SenseiServiceProxy senseiServiceProxy = new SenseiServiceProxy("localhost", 8080);
System.out.println(senseiServiceProxy.sendSearchRequest(request));
}
View
4 sensei-core/pom.xml
@@ -242,7 +242,7 @@
<dependency>
<groupId>com.browseengine.bobo</groupId>
<artifactId>bobo-browse</artifactId>
- <version>3.0.6-SNAPSHOT</version>
+ <version>3.0.7-SNAPSHOT</version>
</dependency>
<dependency>
@@ -260,7 +260,7 @@
<dependency>
<groupId>com.linkedin</groupId>
<artifactId>norbert_2.8.1</artifactId>
- <version>0.6.12</version>
+ <version>0.6.16-SNAPSHOT</version>
</dependency>
<dependency>
View
63 sensei-core/src/main/antlr3/com/senseidb/bql/parsers/BQL.g
@@ -519,6 +519,7 @@ LIKE : ('L'|'l')('I'|'i')('K'|'k')('E'|'e') ;
LIMIT : ('L'|'l')('I'|'i')('M'|'m')('I'|'i')('T'|'t') ;
LONG : ('L'|'l')('O'|'o')('N'|'n')('G'|'g') ;
MATCH : ('M'|'m')('A'|'a')('T'|'t')('C'|'c')('H'|'h') ;
+MODEL : ('M'|'m')('O'|'o')('D'|'d')('E'|'e')('L'|'l') ;
NOT : ('N'|'n')('O'|'o')('T'|'t') ;
NOW : ('N'|'n')('O'|'o')('W'|'w') ;
NULL : ('N'|'n')('U'|'u')('L'|'l')('L'|'l') ;
@@ -527,12 +528,14 @@ ORDER : ('O'|'o')('R'|'r')('D'|'d')('E'|'e')('R'|'r') ;
PARAM : ('P'|'p')('A'|'a')('R'|'r')('A'|'a')('M'|'m') ;
QUERY : ('Q'|'q')('U'|'u')('E'|'e')('R'|'r')('Y'|'y') ;
ROUTE : ('R'|'r')('O'|'o')('U'|'u')('T'|'t')('E'|'e') ;
+RELEVANCE : ('R'|'r')('E'|'e')('L'|'l')('E'|'e')('V'|'v')('A'|'a')('N'|'n')('C'|'c')('E'|'e') ;
SELECT : ('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t') ;
SINCE : ('S'|'s')('I'|'i')('N'|'n')('C'|'c')('E'|'e') ;
STORED : ('S'|'s')('T'|'t')('O'|'o')('R'|'r')('E'|'e')('D'|'d') ;
STRING : ('S'|'s')('T'|'t')('R'|'r')('I'|'i')('N'|'n')('G'|'g') ;
TOP : ('T'|'t')('O'|'o')('P'|'p') ;
TRUE : ('T'|'t')('R'|'r')('U'|'u')('E'|'e') ;
+USING : ('U'|'u')('S'|'s')('I'|'i')('N'|'n')('G'|'g') ;
VALUE : ('V'|'v')('A'|'a')('L'|'l')('U'|'u')('E'|'e') ;
WHERE : ('W'|'w')('H'|'h')('E'|'e')('R'|'r')('E'|'e') ;
WITH : ('W'|'w')('I'|'i')('T'|'t')('H'|'h') ;
@@ -579,6 +582,7 @@ select_stmt returns [Object json]
boolean seenBrowseBy = false;
boolean seenFetchStored = false;
boolean seenRouteBy = false;
+ boolean seenRelevanceModel = false;
}
: SELECT ('*' | cols=column_name_list)
(FROM (IDENT | STRING_LITERAL))?
@@ -638,6 +642,16 @@ select_stmt returns [Object json]
seenRouteBy = true;
}
}
+ | rel_model = relevance_model_clause
+ {
+ if (seenRelevanceModel) {
+ throw new FailedPredicateException(input, "select_stmt", "USING RELEVANCE MODEL clause can only appear once.");
+ }
+ else {
+ seenRelevanceModel = true;
+ }
+ }
+
)*
{
JSONObject jsonObj = new JSONObject();
@@ -665,7 +679,12 @@ select_stmt returns [Object json]
jsonObj.put("meta", metaData);
if (order_by != null) {
- jsonObj.put("sort", $order_by.json);
+ if ($order_by.isRelevance) {
+ jsonObj.put("sort", "relevance");
+ }
+ else {
+ jsonObj.put("sort", $order_by.json);
+ }
}
if (limit != null) {
jsonObj.put("from", $limit.offset);
@@ -706,13 +725,26 @@ select_stmt returns [Object json]
jsonObj.put("filter", f);
}
}
+
if (given != null) {
jsonObj.put("facetInit", $given.json);
}
+
+ if (rel_model != null) {
+ JSONObject queryPred = jsonObj.optJSONObject("query");
+ if (queryPred == null) {
+ queryPred = new JSONObject().put("query_string",
+ new JSONObject().put("query", "")
+ .put("relevance", $rel_model.json));
+ jsonObj.put("query", queryPred);
+ }
+ }
+
}
catch (JSONException err) {
throw new FailedPredicateException(input, "select_stmt", "JSONException: " + err.getMessage());
}
+
$json = jsonObj;
}
// -> ^(SELECT column_name_list IDENT where?)
@@ -762,10 +794,16 @@ where returns [Object json]
}
;
-order_by_clause returns [Object json]
- : ORDER BY sort_specs
+order_by_clause returns [boolean isRelevance, Object json]
+ : ORDER BY (RELEVANCE | sort_specs)
{
- $json = $sort_specs.json;
+ if ($RELEVANCE != null) {
+ $isRelevance = true;
+ }
+ else {
+ $isRelevance = false;
+ $json = $sort_specs.json;
+ }
}
;
@@ -1693,6 +1731,23 @@ given_clause returns [JSONObject json]
}
;
+relevance_model_clause returns [JSONObject json]
+@init {
+ $json = new JSONObject();
+}
+ : USING RELEVANCE MODEL IDENT prop_list
+ {
+ try {
+ $json.put("predefined_model", $IDENT.text);
+ $json.put("values", $prop_list.json);
+ }
+ catch (JSONException err) {
+ throw new FailedPredicateException(input, "relevance_model_clause",
+ "JSONException: " + err.getMessage());
+ }
+ }
+ ;
+
facet_param_list returns [JSONObject json]
@init {
$json = new JSONObject();
View
41 sensei-core/src/main/java/com/senseidb/cluster/client/SenseiNetworkClient.java
@@ -17,56 +17,58 @@
import com.linkedin.norbert.network.NoNodesAvailableException;
import com.linkedin.norbert.network.ResponseIterator;
import com.linkedin.norbert.network.Serializer;
+import com.senseidb.cluster.routing.SenseiPartitionedLoadBalancerFactory;
/**
* @author nnarkhed
*
*/
-public class SenseiNetworkClient implements PartitionedNetworkClient<Integer>
+public class SenseiNetworkClient implements PartitionedNetworkClient<String>
{
- private final PartitionedNetworkClient<Integer> _networkClient;
+ private final PartitionedNetworkClient<String> _networkClient;
- public SenseiNetworkClient(NetworkClientConfig netConfig, PartitionedLoadBalancerFactory<Integer> routerFactory)
+ public SenseiNetworkClient(NetworkClientConfig netConfig, PartitionedLoadBalancerFactory<String> routerFactory)
{
if(routerFactory != null)
{
- _networkClient = new NettyPartitionedNetworkClient<Integer>(netConfig, routerFactory);
+ _networkClient = new NettyPartitionedNetworkClient<String>(netConfig, routerFactory);
}
else