Fixed BLUR-256
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/b94ae0b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/b94ae0b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/b94ae0b6 Branch: refs/heads/blur-console-v2 Commit: b94ae0b6242d1e86379aa20b5edafe1774a72ce4 Parents: 348af34 Author: Aaron McCurry <[email protected]> Authored: Wed Nov 6 10:59:28 2013 -0500 Committer: Aaron McCurry <[email protected]> Committed: Wed Nov 6 11:00:08 2013 -0500 ---------------------------------------------------------------------- .../blur/thrift/util/SimpleFacetingExample.java | 61 ++++++++++++++++++++ docs/using-blur.base.html | 31 ++++++++++ docs/using-blur.html | 31 ++++++++++ 3 files changed, 123 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b94ae0b6/blur-thrift/src/main/java/org/apache/blur/thrift/util/SimpleFacetingExample.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/util/SimpleFacetingExample.java b/blur-thrift/src/main/java/org/apache/blur/thrift/util/SimpleFacetingExample.java new file mode 100644 index 0000000..c036f22 --- /dev/null +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/util/SimpleFacetingExample.java @@ -0,0 +1,61 @@ +package org.apache.blur.thrift.util; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.io.IOException; +import java.util.List; + +import org.apache.blur.thirdparty.thrift_0_9_0.TException; +import org.apache.blur.thrift.BlurClient; +import org.apache.blur.thrift.generated.Blur.Iface; +import org.apache.blur.thrift.generated.BlurException; +import org.apache.blur.thrift.generated.BlurQuery; +import org.apache.blur.thrift.generated.BlurResult; +import org.apache.blur.thrift.generated.BlurResults; +import org.apache.blur.thrift.generated.Facet; +import org.apache.blur.thrift.generated.Query; + +public class SimpleFacetingExample { + + public static void main(String[] args) throws BlurException, TException, IOException { + String connectionStr = args[0]; + String tableName = args[1]; + String queryStr = args[2]; + + Iface client = BlurClient.getClient(connectionStr); + + final BlurQuery blurQuery = new BlurQuery(); + Query query = new Query(); + blurQuery.setQuery(query); + query.setQuery(queryStr); + + blurQuery.addToFacets(new Facet("fam1.col1:value1 OR fam1.col1:value2", 10000)); + blurQuery.addToFacets(new Facet("fam1.col1:value100 AND fam1.col1:value200", Long.MAX_VALUE)); + + BlurResults results = client.query(tableName, blurQuery); + System.out.println("Total Results: " + results.totalResults); + + List<Long> facetCounts = results.getFacetCounts(); + List<Facet> facets = blurQuery.getFacets(); + for (int i = 0; i < facets.size(); i++) { + System.out.println("Facet [" + facets.get(i) + "] got [" + facetCounts.get(i) + "]"); + } + for (BlurResult result : results.getResults()) { + System.out.println(result); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b94ae0b6/docs/using-blur.base.html ---------------------------------------------------------------------- diff --git a/docs/using-blur.base.html b/docs/using-blur.base.html index 5c32bbe..4f31c81 100644 --- a/docs/using-blur.base.html +++ b/docs/using-blur.base.html @@ -63,6 +63,7 @@ </li> <li><a href="#simple_query_example">Query Example</a></li> <li><a href="#simple_query_example_data">Query Example with Data</a></li> + <li><a href="#simple_faceting_example">Faceting Example</a></li> <li><a href="#simple_fetch_data">Fetch Data</a></li> <li><a href="#simple_mutate_example">Mutate Example</a></li> <li><a href="#simple_shortened_mutate_example">Shortened Mutate Example</a></li> @@ -202,6 +203,36 @@ for (BlurResult result : results.getResults()) { } </code></pre> +<h3 id="simple_faceting_example">Faceting Example</h3> +<p> +This is an example of how to use the faceting feature in a query. This API will likely be update in a future version. +</p> +<pre><code class="java">Iface client = BlurClient.getClient("controller1:40010,controller2:40010"); + +Query query = new Query(); +query.setQuery("+docs.body:\"Hadoop is awesome\""); + +final BlurQuery blurQuery = new BlurQuery(); +blurQuery.setQuery(query); +// This facet will stop counting once the count has reached 10000. However this is only counted +// on each server, so it is likely you will receive a count larger than your max. +blurQuery.addToFacets(new Facet("fam1.col1:value1 OR fam1.col1:value2", 10000)); +blurQuery.addToFacets(new Facet("fam1.col1:value100 AND fam1.col1:value200", Long.MAX_VALUE)); + +BlurResults results = client.query(tableName, blurQuery); +System.out.println("Facet Results:"); +List<Long> facetCounts = results.getFacetCounts(); +List<Facet> facets = blurQuery.getFacets(); +for (int i = 0; i < facets.size(); i++) { + System.out.println("Facet [" + facets.get(i) + "] got [" + facetCounts.get(i) + "]"); +} + +BlurResults results = client.query("table1", blurQuery); +System.out.println("Total Results: " + results.totalResults); +for (BlurResult result : results.getResults()) { + System.out.println(result); +}</code></pre> + <h3 id="simple_fetch_data">Fetch Data</h3> <p> This is an example of how to fetch data via the Thrift API. All the records http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b94ae0b6/docs/using-blur.html ---------------------------------------------------------------------- diff --git a/docs/using-blur.html b/docs/using-blur.html index ec7794a..b20b9c1 100644 --- a/docs/using-blur.html +++ b/docs/using-blur.html @@ -63,6 +63,7 @@ </li> <li><a href="#simple_query_example">Query Example</a></li> <li><a href="#simple_query_example_data">Query Example with Data</a></li> + <li><a href="#simple_faceting_example">Faceting Example</a></li> <li><a href="#simple_fetch_data">Fetch Data</a></li> <li><a href="#simple_mutate_example">Mutate Example</a></li> <li><a href="#simple_shortened_mutate_example">Shortened Mutate Example</a></li> @@ -247,6 +248,36 @@ for (BlurResult result : results.getResults()) { } </code></pre> +<h3 id="simple_faceting_example">Faceting Example</h3> +<p> +This is an example of how to use the faceting feature in a query. This API will likely be update in a future version. +</p> +<pre><code class="java">Iface client = BlurClient.getClient("controller1:40010,controller2:40010"); + +Query query = new Query(); +query.setQuery("+docs.body:\"Hadoop is awesome\""); + +final BlurQuery blurQuery = new BlurQuery(); +blurQuery.setQuery(query); +// This facet will stop counting once the count has reached 10000. However this is only counted +// on each server, so it is likely you will receive a count larger than your max. +blurQuery.addToFacets(new Facet("fam1.col1:value1 OR fam1.col1:value2", 10000)); +blurQuery.addToFacets(new Facet("fam1.col1:value100 AND fam1.col1:value200", Long.MAX_VALUE)); + +BlurResults results = client.query(tableName, blurQuery); +System.out.println("Facet Results:"); +List<Long> facetCounts = results.getFacetCounts(); +List<Facet> facets = blurQuery.getFacets(); +for (int i = 0; i < facets.size(); i++) { + System.out.println("Facet [" + facets.get(i) + "] got [" + facetCounts.get(i) + "]"); +} + +BlurResults results = client.query("table1", blurQuery); +System.out.println("Total Results: " + results.totalResults); +for (BlurResult result : results.getResults()) { + System.out.println(result); +}</code></pre> + <h3 id="simple_fetch_data">Fetch Data</h3> <p> This is an example of how to fetch data via the Thrift API. All the records
