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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty