Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-8185

Needs better example to have to extract Facet Data in Java SDK 3.x

    XMLWordPrintable

Details

    Description

      Currently we have under facet the following example:
      https://docs.couchbase.com/java-sdk/current/howtos/full-text-searching-with-sdk.html#facets

      Map<String, SearchFacet> facets = new HashMap<>();
      facets.put("categories", SearchFacet.term("category", 5));
       
      SearchResult result = cluster.searchQuery(
        "index",
        SearchQuery.queryString("query"),
        searchOptions().facets(facets)
      );
      

      this example is over simplistic and doesn't cover how to retrieve the facet data.

      I would recommend to add something like the following that shows the casting:

              for (SearchFacetResult sfr : result.facets().values()) {
                  System.out.println("facet_field: " + sfr.field());
                  List<SearchTermRange> tsfRange = ((TermSearchFacetResult) sfr).terms();
                  for (SearchTermRange tsfr: tsfRange) {
                      System.out.println(tsfr.name() +": " + tsfr.count());
                  }
              }
      

      +Add printout

      Reporter: Roi Katz
      E-mail: roi.katz@Couchbase.com

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            roi.katz Roi Katz created issue -
            roi.katz Roi Katz made changes -
            Field Original Value New Value
            Description Currently we have under facet the following example:
            https://docs.couchbase.com/java-sdk/current/howtos/full-text-searching-with-sdk.html#facets

            {code}
            Map<String, SearchFacet> facets = new HashMap<>();
            facets.put("categories", SearchFacet.term("category", 5));

            SearchResult result = cluster.searchQuery(
              "index",
              SearchQuery.queryString("query"),
              searchOptions().facets(facets)
            );
            {code}

            this example is over simplistic and doesn't cover how to retrieve the facet data.

            I would recommend to add something like the following that shows the casting:
            {code}
                 for (SearchFacetResult sfr : result.facets().values()) {
                        System.out.println("facet_field: " + sfr.field());
                        System.out.println(((TermSearchFacetResult) sfr).terms());
                    }
                }
            {code}

            *Reporter*: Roi Katz
            *E-mail*: [mailto:roi.katz@Couchbase.com]
            Currently we have under facet the following example:
            https://docs.couchbase.com/java-sdk/current/howtos/full-text-searching-with-sdk.html#facets

            {code}
            Map<String, SearchFacet> facets = new HashMap<>();
            facets.put("categories", SearchFacet.term("category", 5));

            SearchResult result = cluster.searchQuery(
              "index",
              SearchQuery.queryString("query"),
              searchOptions().facets(facets)
            );
            {code}

            this example is over simplistic and doesn't cover how to retrieve the facet data.

            I would recommend to add something like the following that shows the casting:
            {code}
                    for (SearchFacetResult sfr : result.facets().values()) {
                        System.out.println("facet_field: " + sfr.field());
                        List<SearchTermRange> tsfRange = ((TermSearchFacetResult) sfr).terms();
                        for (SearchTermRange tsfr: tsfRange) {
                            System.out.println(tsfr.name() +": " + tsfr.count());
                        }
                    }
            {code}

            *Reporter*: Roi Katz
            *E-mail*: [mailto:roi.katz@Couchbase.com]
            roi.katz Roi Katz made changes -
            Description Currently we have under facet the following example:
            https://docs.couchbase.com/java-sdk/current/howtos/full-text-searching-with-sdk.html#facets

            {code}
            Map<String, SearchFacet> facets = new HashMap<>();
            facets.put("categories", SearchFacet.term("category", 5));

            SearchResult result = cluster.searchQuery(
              "index",
              SearchQuery.queryString("query"),
              searchOptions().facets(facets)
            );
            {code}

            this example is over simplistic and doesn't cover how to retrieve the facet data.

            I would recommend to add something like the following that shows the casting:
            {code}
                    for (SearchFacetResult sfr : result.facets().values()) {
                        System.out.println("facet_field: " + sfr.field());
                        List<SearchTermRange> tsfRange = ((TermSearchFacetResult) sfr).terms();
                        for (SearchTermRange tsfr: tsfRange) {
                            System.out.println(tsfr.name() +": " + tsfr.count());
                        }
                    }
            {code}

            *Reporter*: Roi Katz
            *E-mail*: [mailto:roi.katz@Couchbase.com]
            Currently we have under facet the following example:
            https://docs.couchbase.com/java-sdk/current/howtos/full-text-searching-with-sdk.html#facets

            {code}
            Map<String, SearchFacet> facets = new HashMap<>();
            facets.put("categories", SearchFacet.term("category", 5));

            SearchResult result = cluster.searchQuery(
              "index",
              SearchQuery.queryString("query"),
              searchOptions().facets(facets)
            );
            {code}

            this example is over simplistic and doesn't cover how to retrieve the facet data.

            I would recommend to add something like the following that shows the casting:
            {code}
                    for (SearchFacetResult sfr : result.facets().values()) {
                        System.out.println("facet_field: " + sfr.field());
                        List<SearchTermRange> tsfRange = ((TermSearchFacetResult) sfr).terms();
                        for (SearchTermRange tsfr: tsfRange) {
                            System.out.println(tsfr.name() +": " + tsfr.count());
                        }
                    }
            {code}
            +Add printout

            *Reporter*: Roi Katz
            *E-mail*: [mailto:roi.katz@Couchbase.com]
            Priority Test Blocker [ 6 ]
            richard.smedley Richard Smedley made changes -
            Link This issue relates to DOC-8176 [ DOC-8176 ]
            richard.smedley Richard Smedley made changes -
            Component/s server dev guide and SDKs [ 11814 ]
            Epic Link DOC-8196 [ 152156 ]
            Fix Version/s sdk3.1-backlog [ 17244 ]
            Fix Version/s sdk3.2-backlog [ 17245 ]
            Story Points 1
            Affects Version/s SDK-3.1 [ 17058 ]
            Assignee Amarantha Kulkarni [ amarantha.kulkarni ] Richard Smedley [ richard smedley ]
            Labels collector-709818cb collector-709818cb fts search
            richard.smedley Richard Smedley made changes -
            Labels collector-709818cb fts search SDKDOC-improvement collector-709818cb fts search
            hakim.cassimally Hakim Cassimally made changes -
            Assignee Richard Smedley [ richard smedley ] Hakim Cassimally [ JIRAUSER25269 ]

            People

              hakim.cassimally Hakim Cassimally
              roi.katz Roi Katz
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty