Quick Start
The following exercise builds on the Attivio Quick Start tutorial to introduce adding multi level facets using JAVA API. This is applicable from attivio installer 5.6.1
Prerequisites
In order to complete the following exercise, you'll need to have the following software installed:
Application | Recommended Version | Download Location | Notes |
---|---|---|---|
Maven | 3.5 or later | https://maven.apache.org/ | |
Eclipse | Oxygen or later | https://www.eclipse.org/ | Be sure to install the M2Eclipse plugin or use the Eclipse IDE for Java Developers installer which includes Maven integration. |
Deploy the Attivio Factbook Project
Open the Attivio Quick Start Tutorial in a new tab in your browser, follow the instructions to deploy the Factbook project, run the connectors and return to this page when complete.
Build a search request
Create a Java class to create a search request and add multi level facets to it.
// Create query request. query to search should be assigned for queryString. QueryRequest request = new QueryRequest(queryString,QueryLanguages.SIMPLE); // create Facet requests on specific fields FacetRequest parentFacet = new FacetRequest("table"); FacetRequest childFacet = new FacetRequest("country"); FacetRequest grandChildFacet = new FacetRequest("language"); //Facets needs to be added in an order. GrandChild facet to child, child to parent, parent to request. childFacet.setChildFacet(grandChildFacet); parentFacet.setChildFacet(childFacet); request.addFacet(parentFacet); //Capture search response QueryResponse response = searchClient.search(request);
Schema facet as a child facet
SchemaFacetRequest childFacet = new SchemaFacetRequest("fields");
Range facet as a Child Facet
RangeFacetRequest childFacet = new RangeFacetRequest("size"); childFacet.add("<150", 0, 150); childFacet.add(">150",150,600);
Filter based Facet as a Child Facet
FilterBasedFacetRequest parentFacet = new FilterBasedFacetRequest("table"); parentFacet.add("table", new QueryString("table:city",QueryLanguages.SIMPLE));
we can set these parameters at any level of facet
parentFacet.setMaxBuckets(10); parentFacet.setMinBucketCount(5); parentFacet.setCalculateStatistics(true); parentFacet.setSortOrder(SortBy.COUNT, Sort.ASC);
Drill down the response
Access the facet buckets and their children from response object using below code
System.out.println("Total documents matched: " + response.getDocuments().getNumberFound()); FacetResponse facet = response.getFacet("table"); //capturing parent facet //access buckets using a loop for (FacetBucket bucket : facet) { System.out.println("Parent: " + bucket.getDisplayValue() + " " + bucket.getCount()); FacetBuckets childBuckets = bucket.getChildren(); Iterator iterator = childBuckets.iterator(); while(iterator.hasNext()) { FacetBucket childBucket = (FacetBucket) iterator.next(); System.out.println(" child: " + childBucket.getDisplayValue() + " " + childBucket.getCount()); // System.out.println("Facet filter of parent:"+facet.getFacetFilter(bucket)); // System.out.println("facet filter of child "+facet.getFacetFilter(bucket,childBucket)); //following this order is very important. FacetBuckets grandChildBuckets = childBucket.getChildren(); Iterator iterator1 = grandChildBuckets.iterator(); while(iterator1.hasNext()) { FacetBucket grandChildBucket = (FacetBucket) iterator1.next(); System.out.println(" grandChild: " + grandChildBucket.getDisplayValue() + " " + grandChildBucket.getCount()); } } }