Page tree
Skip to end of metadata
Go to start of metadata

Overview

Discrete facets return one bucket for every distinct field value in a result set for a specified field.

View incoming links.

Discrete Facet Example

A discrete facet request for the "concepts" field might look like this:

The list does not contain all possible facet values, but only the values that are present in the current result set. Selecting a value refines the search criteria, resulting in a smaller result set.

Java Client API

Discrete Facets can be requested via the Java Client API  using the FacetRequest . Note that multiple FacetRequest objects can be added to the QueryRequest  to request multiple facets.

Syntax

Consult the javadoc page for FacetRequest

Example (Java)

The following example shows how to use AIE's Java Client API to request a facet for the "concepts" field:

Java
SearchClient client = ...;
QueryRequest query = new QueryRequest("*:*");  //query for all results

// Add the facet to the query
query.addFacet( new FacetRequest("concepts") );

// Get the response
QueryResponse results = client.search(query);

// Display the categories
System.out.println("Concept Facet:");
for (FacetBucket bucket : results.getFacet("concepts")) {
  System.out.printf("%s - %d\n", bucket.getLabel(), bucket.getCount());
}

 

JSON REST API

See the REST API Tutorial for examples showing how to issue a JSON REST query. 

See the REST Query API page for details of composing JSON REST queries.

{
    "workflow": "search",
    "query": "*:*",
    "queryLanguage": "advanced",
    "locale": "en",
    "facets" : ["size(sortBy=VALUE, primarySort=DESC,minBucketCount=1)"],
    "fields": [ ".id", "title", "text", "date" ]      
}

 

XML REST API

Discrete Facets can be requested via the JSON REST API using the facet HTTP query parameter. Note that the facet parameter can be specified multiple times to request multiple facets.

Syntax

facet=fieldname[(parameter1=value1[, parameter2=value2[, ...]])]

Parameters

Parameter

Type

Default Value

Description

sortBy

enum (COUNT, VALUE)

COUNT

See Facet Bucket Sorting

primarySort

enum (ASC, DESC)

DESC

See Facet Bucket Sorting

secondarySort

enum (ASC, DESC)

ASC

See Facet Bucket Sorting

maxBuckets

integer

10

See Bucket Filtering

minBucketCount

integer

1

See Bucket Filtering

distributedMaxBuckets

integer

-1 (unlimited)

See Bucket Filtering

distributedMinBucketCount

integer

1

See Bucket Filtering

statistics

boolean

false

See Facet Statistics

Examples (HTTP/REST)

The following three examples show HTTP GET/POST arguments required for Discrete Facet requests, followed by four further examples showing arguments for schema facet requests, range-based facet requests, filter-based facet requests, and field expression-based facet requests:

// facet on category field
facet=category

// Facet on category and contenttype field
facet=category&facet=contenttype

// Facet with additional parameters
facet=category(sortBy=VALUE, primarySort=ASC, secondarySort=DESC, maxBuckets=100)


// a schema facet request for all fields present on documents matching the query
facet=populatedFields(field=.fields, sortBy=VALUE, primarySort=ASC, maxBuckets=2000)
 
// a range-based facet request
facet=size(range=("Under 1 KB", 0, 1024), range=("Over 1 KB", 1024, *), sortBy=COUNT, primarySort=ASC)
 
// a filter-based facet request
facet=country(filter="North America"(OR("United States", Canada, Mexico)), filter=Australia(Australia))
 
// a facet using a field expression
facet=authors(function=TITLECASE(author), maxBuckets=100)
  • No labels