Java Code Examples for org.apache.solr.client.solrj.response.QueryResponse#getJsonFacetingResponse()
The following examples show how to use
org.apache.solr.client.solrj.response.QueryResponse#getJsonFacetingResponse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectJsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testMultiStatFacet() throws Exception { final String jsonBody = String.join("\n","{", " 'query': '*:*',", " 'facet': {", " 'sum_price': 'sum(price)',", " 'avg_price': 'avg(price)'", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasStatFacetWithValue(topLevelFacetData,"sum_price", 5251.270030975342); assertHasStatFacetWithValue(topLevelFacetData,"avg_price", 328.20437693595886); }
Example 2
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testRangeFacetSimple() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-range-facet-simple[] RangeFacetMap rangeFacet = new RangeFacetMap("price", 0.0, 100.0, 20.0); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFacet("prices", rangeFacet); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-range-facet-simple[] assertEquals(0, queryResponse.getStatus()); assertEquals(32, queryResponse.getResults().getNumFound()); assertEquals(10, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetingData,"prices", new FacetBucket(0.0f,5), new FacetBucket(20.0f, 0), new FacetBucket(40.0f, 0), new FacetBucket(60.0f, 1), new FacetBucket(80.0f, 1)); }
Example 3
Source File: JsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithArbitraryDomainFromQueryString() throws Exception { final TermsFacetMap categoriesFacet = new TermsFacetMap("cat") .setLimit(3) .withDomain(new DomainMap() .withQuery("*:*")); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("cat:electronics") .withFacet("top_cats", categoriesFacet); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_ELECTRONICS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData,"top_cats", new FacetBucket("electronics",NUM_ELECTRONICS), new FacetBucket("currency", NUM_CURRENCY), new FacetBucket("memory", NUM_MEMORY)); }
Example 4
Source File: DirectJsonQueryRequestFacetingEmbeddedTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithMultipleLocalParamsQueryClausesInArbitraryDomain() throws Exception { final String jsonBody = String.join("\n", "{", " 'query': 'cat:electronics',", " 'facet': {", " 'cats_matching_solr': {", " 'type': 'terms',", " 'field': 'cat',", " 'domain': {", " 'query': ['{!lucene df=\"cat\" v=\"search\"}', '{!lucene df=\"name\" v=\"Solr\"}']", " }", " }", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_ELECTRONICS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData, "cats_matching_solr", new FacetBucket("search", 1), new FacetBucket("software", 1)); }
Example 5
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetFilteredDomain() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-facet-filtered-domain[] final TermsFacetMap categoryFacet = new TermsFacetMap("cat") .setLimit(3) .withDomain(new DomainMap().withFilter("popularity:[5 TO 10]")); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFacet("categories", categoryFacet); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-facet-filtered-domain[] assertEquals(0, queryResponse.getStatus()); assertEquals(32, queryResponse.getResults().getNumFound()); assertEquals(10, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetingData, "categories", new FacetBucket("electronics", 9), new FacetBucket("graphics card", 2), new FacetBucket("hard drive", 2)); }
Example 6
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWidenedUsingQueryDomain() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-facet-query-domain[] final TermsFacetMap inStockFacet = new TermsFacetMap("inStock").setLimit(2); final TermsFacetMap popularCategoriesFacet = new TermsFacetMap("cat") .withDomain(new DomainMap().withQuery("popularity:[8 TO 10]")) .setLimit(3); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("apple") .withFacet("popular_categories", popularCategoriesFacet); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-facet-query-domain[] assertEquals(0, queryResponse.getStatus()); assertEquals(1, queryResponse.getResults().getNumFound()); assertEquals(1, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetingData, "popular_categories", new FacetBucket("electronics", 1), new FacetBucket("music", 1), new FacetBucket("search", 1)); }
Example 7
Source File: JsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithDomainWidenedUsingExcludeTagsToIgnoreFilters() throws Exception { final TermsFacetMap inStockFacet = new TermsFacetMap("cat") .setLimit(2); final TermsFacetMap allProductsFacet = new TermsFacetMap("cat") .setLimit(2).withDomain(new DomainMap().withTagsToExclude("on_shelf")); final Map<String, Object> taggedFilterMap = new HashMap<>(); taggedFilterMap.put("#on_shelf", "inStock:true"); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFilter(taggedFilterMap) .withFacet("in_stock_only", inStockFacet) .withFacet("all", allProductsFacet); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_IN_STOCK, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData,"in_stock_only", new FacetBucket("electronics",8), new FacetBucket("currency", 4)); assertHasFacetWithBucketValues(topLevelFacetData ,"all", new FacetBucket("electronics",12), new FacetBucket("currency", 4)); }
Example 8
Source File: JsonQueryRequestHeatmapFacetingTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testHeatmapFacet() throws Exception { final List<List<Integer>> expectedHeatmapGrid = Arrays.asList( Arrays.asList(0, 0, 2, 1, 0, 0), Arrays.asList(0, 0, 1, 1, 0, 0), Arrays.asList(0, 1, 1, 1, 0, 0), Arrays.asList(0, 0, 1, 1, 0, 0), Arrays.asList(0, 0, 1, 1, 0, 0), null, null ); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .setLimit(0) .withFacet("heatmapFacet", new HeatmapFacetMap(FIELD) .setHeatmapFormat(HeatmapFacetMap.HeatmapFormat.INTS2D) .setRegionQuery("[\"50 20\" TO \"180 90\"]") .setGridLevel(4) ); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); final NestableJsonFacet topLevelFacet = response.getJsonFacetingResponse(); final HeatmapJsonFacet heatmap = topLevelFacet.getHeatmapFacetByName("heatmapFacet"); final List<List<Integer>> actualHeatmapGrid = heatmap.getCountGrid(); assertEquals(expectedHeatmapGrid, actualHeatmapGrid); }
Example 9
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testSimpleJsonTermsFacet() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-simple-terms-facet[] final TermsFacetMap categoryFacet = new TermsFacetMap("cat").setLimit(3); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFacet("categories", categoryFacet); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-simple-terms-facet[] assertEquals(0, queryResponse.getStatus()); assertEquals(32, queryResponse.getResults().getNumFound()); assertEquals(10, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetingData,"categories", new FacetBucket("electronics",12), new FacetBucket("currency", 4), new FacetBucket("memory", 3)); }
Example 10
Source File: JsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithArbitraryDomainFromLocalParamsQuery() throws Exception { final TermsFacetMap searchCategoriesFacet = new TermsFacetMap("cat") .withDomain(new DomainMap() .withQuery("{!lucene df=\"cat\" v=\"search\"}")); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("cat:electronics") .withFacet("largest_search_cats", searchCategoriesFacet); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_ELECTRONICS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData,"largest_search_cats", new FacetBucket("search",2), new FacetBucket("software", 2)); }
Example 11
Source File: JsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithDomainFilteredBySimpleQueryString() throws Exception { final TermsFacetMap popularCategoriesFacet = new TermsFacetMap("cat") .setLimit(3) .withDomain(new DomainMap() .withFilter("popularity:[5 TO 10]")); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFacet("top_popular_cats", popularCategoriesFacet); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData,"top_popular_cats", new FacetBucket("electronics",9), new FacetBucket("graphics card", 2), new FacetBucket("hard drive", 2)); }
Example 12
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testStatFacetSimple() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-metrics-facet-simple[] final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withFilter("price:[1.0 TO *]") .withFilter("popularity:[0 TO 10]") .withStatFacet("min_manu_id_s", "min(manu_id_s)") .withStatFacet("avg_value", "avg(div(popularity,price))"); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-metrics-facet-simple[] assertEquals(0, queryResponse.getStatus()); assertEquals(13, queryResponse.getResults().getNumFound()); assertEquals(10, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertEquals(0.036, (double) topLevelFacetingData.getStatValue("avg_value"), 0.1); Object val = topLevelFacetingData.getStatValue("min_manu_id_s"); assertTrue(val instanceof String); assertEquals("apple", val.toString()); }
Example 13
Source File: DirectJsonQueryRequestFacetingEmbeddedTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testSingleStatFacet() throws Exception { final String jsonBody = String.join("\n", "{", " 'query': '*:*',", " 'facet': {", " 'sum_price': 'sum(price)'", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasStatFacetWithValue(topLevelFacetData, "sum_price", 5251.270030975342); }
Example 14
Source File: DirectJsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetWithMultipleLocalParamsQueryClausesInArbitraryDomain() throws Exception { final String jsonBody = String.join("\n","{", " 'query': 'cat:electronics',", " 'facet': {", " 'cats_matching_solr': {", " 'type': 'terms',", " 'field': 'cat',", " 'domain': {", " 'query': ['{!lucene df=\"cat\" v=\"search\"}', '{!lucene df=\"name\" v=\"Solr\"}']", " }", " }", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_ELECTRONICS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData,"cats_matching_solr", new FacetBucket("search",1), new FacetBucket("software", 1)); }
Example 15
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testFacetWidenedExcludeTagsDomain() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-facet-excludetags-domain[] final TermsFacetMap inStockFacet = new TermsFacetMap("inStock").setLimit(2); final TermsFacetMap allManufacturersFacet = new TermsFacetMap("manu_id_s") .setLimit(2) .withDomain(new DomainMap().withTagsToExclude("MANU")); final JsonQueryRequest request = new JsonQueryRequest() .setQuery("cat:electronics") .withFilter("{!tag=MANU}manu_id_s:apple") .withFacet("stock", inStockFacet) .withFacet("manufacturers", allManufacturersFacet); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-facet-excludetags-domain[] assertEquals(0, queryResponse.getStatus()); assertEquals(1, queryResponse.getResults().getNumFound()); assertEquals(1, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetingData, "stock", new FacetBucket(true, 1)); assertHasFacetWithBucketValues(topLevelFacetingData, "manufacturers", new FacetBucket("corsair", 3), new FacetBucket("belkin", 2)); }
Example 16
Source File: DirectJsonQueryRequestFacetingEmbeddedTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testFacetWithDomainWidenedUsingExcludeTagsToIgnoreFilters() throws Exception { final String jsonBody = String.join("\n", "{", " 'query': '*:*',", " 'filter': {'#on_shelf': 'inStock:true'},", " 'facet': {", " 'in_stock_only': {", " 'type': 'terms',", " 'field': 'cat',", " 'limit': 2", " }", " 'all': {", " 'type': 'terms',", " 'field': 'cat',", " 'limit': 2,", " 'domain': {", " 'excludeTags': 'on_shelf'", " }", " }", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_IN_STOCK, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasFacetWithBucketValues(topLevelFacetData, "in_stock_only", new FacetBucket("electronics", 8), new FacetBucket("currency", 4)); assertHasFacetWithBucketValues(topLevelFacetData, "all", new FacetBucket("electronics", 12), new FacetBucket("currency", 4)); }
Example 17
Source File: JsonRequestApiTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testStatFacet1() throws Exception { SolrClient solrClient = cluster.getSolrClient(); //tag::solrj-json-metrics-facet-1[] final JsonQueryRequest request = new JsonQueryRequest() .setQuery("memory") .withFilter("inStock:true") .withStatFacet("avg_price", "avg(price)") .withStatFacet("min_manufacturedate_dt", "min(manufacturedate_dt)") .withStatFacet("num_suppliers", "unique(manu_exact)") .withStatFacet("median_weight", "percentile(weight,50)"); QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME); //end::solrj-json-metrics-facet-1[] assertEquals(0, queryResponse.getStatus()); assertEquals(4, queryResponse.getResults().getNumFound()); assertEquals(4, queryResponse.getResults().size()); final NestableJsonFacet topLevelFacetingData = queryResponse.getJsonFacetingResponse(); assertEquals(146.66, (double) topLevelFacetingData.getStatValue("avg_price"), 0.5); assertEquals(3L, topLevelFacetingData.getStatValue("num_suppliers")); assertEquals(352.0, (double) topLevelFacetingData.getStatValue("median_weight"), 0.5); Object val = topLevelFacetingData.getStatValue("min_manufacturedate_dt"); assertTrue(val instanceof Date); assertEquals("2006-02-13T15:26:37Z", ((Date)val).toInstant().toString()); }
Example 18
Source File: DirectJsonQueryRequestFacetingEmbeddedTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSingleRangeFacet() throws Exception { final String jsonBody = String.join("\n", "{", " 'query': '*:*',", " 'facet': {", " 'prices': {", " 'type': 'range',", " 'field': 'price',", " 'start': 0,", " 'end': 100,", " 'gap': 20", " }", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertEquals(NUM_TECHPRODUCTS_DOCS, topLevelFacetData.getCount()); assertHasFacetWithBucketValues(topLevelFacetData, "prices", new FacetBucket(0.0f, 5), new FacetBucket(20.0f, 0), new FacetBucket(40.0f, 0), new FacetBucket(60.0f, 1), new FacetBucket(80.0f, 1)); }
Example 19
Source File: DirectJsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSingleRangeFacet() throws Exception { final String jsonBody = String.join("\n","{", " 'query': '*:*',", " 'facet': {", " 'prices': {", " 'type': 'range',", " 'field': 'price',", " 'start': 0,", " 'end': 100,", " 'gap': 20", " }", " }", "}"); final DirectJsonQueryRequest request = new DirectJsonQueryRequest(jsonBody); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertEquals(NUM_TECHPRODUCTS_DOCS, topLevelFacetData.getCount()); assertHasFacetWithBucketValues(topLevelFacetData,"prices", new FacetBucket(0.0f, 5), new FacetBucket(20.0f, 0), new FacetBucket(40.0f, 0), new FacetBucket(60.0f, 1), new FacetBucket(80.0f, 1)); }
Example 20
Source File: JsonQueryRequestFacetingIntegrationTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testMultiStatFacet() throws Exception { final JsonQueryRequest request = new JsonQueryRequest() .setQuery("*:*") .withStatFacet("sum_price", "sum(price)") .withStatFacet("avg_price", "avg(price)"); QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION_NAME); assertExpectedDocumentsFoundAndReturned(response, NUM_TECHPRODUCTS_DOCS, 10); final NestableJsonFacet topLevelFacetData = response.getJsonFacetingResponse(); assertHasStatFacetWithValue(topLevelFacetData,"sum_price", 5251.270030975342); assertHasStatFacetWithValue(topLevelFacetData,"avg_price", 328.20437693595886); }