org.apache.solr.request

## Class IntervalFacets

- java.lang.Object
- - org.apache.solr.request.IntervalFacets

- All Implemented Interfaces:
    Iterable<IntervalFacets.FacetInterval>

      public class IntervalFacets
      extends Object
      implements Iterable<IntervalFacets.FacetInterval>

  Computes interval facets for docvalues field (single or multivalued).

  Given a set of intervals for a field and a DocSet, it calculates the number of documents that match each of the intervals provided. The final count for each interval should be exactly the same as the number of results of a range query using the DocSet and the range as filters. This means that the count of `facet.query=field:[A TO B]` should be the same as the count of `f.field.facet.interval.set=[A,B]`, however, this method will usually be faster in cases where there are a larger number of intervals per field.

  To use this class, create an instance using `IntervalFacets(SchemaField, SolrIndexSearcher, DocSet, String[], SolrParams)` and then iterate the `IntervalFacets.FacetInterval` using `iterator()`

  Intervals Format
  Intervals must begin with either '(' or '[', be followed by the start value, then a comma ',', the end value, and finally ')' or ']'. For example:

  - (1,10) -> will include values greater than 1 and lower than 10
  - [1,10) -> will include values greater or equal to 1 and lower than 10
  - [1,10] -> will include values greater or equal to 1 and lower or equal to 10
  The initial and end values can't be empty, if the interval needs to be unbounded, the special character '*' can be used for both, start and end limit. When using '*', '(' and '[', and ')' and ']' will be treated equal. [*,*] will include all documents with a value in the field

  The interval limits may be strings, there is no need to add quotes, all the text until the comma will be treated as the start limit, and the text after that will be the end limit, for example: [Buenos Aires,New York]. Keep in mind that a string-like comparison will be done to match documents in string intervals (case-sensitive). The comparator can't be changed. Commas, brackets and square brackets can be escaped by using '\' in front of them. Whitespaces before and after the values will be omitted. Start limit can't be grater than the end limit. Equal limits are allowed.

  As with facet.query, the key used to display the result can be set by using local params syntax, for example:

  `{!key='First Half'}[0,5)`

  To use this class:

       IntervalFacets intervalFacets = new IntervalFacets(schemaField, searcher, docs, intervalStrs, params);
       for (FacetInterval interval : intervalFacets) {
           results.add(interval.getKey(), interval.getCount());
       }

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `IntervalFacets.FacetInterval` Helper class to match and count of documents in specified intervals

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IntervalFacets(SchemaField schemaField, SolrIndexSearcher searcher, DocSet docs, IntervalFacets.FacetInterval[] intervals)` Constructor that accepts an already constructed array of `IntervalFacets.FacetInterval` objects.
    `IntervalFacets(SchemaField schemaField, SolrIndexSearcher searcher, DocSet docs, String[] intervals, SolrParams params)` Constructor that accepts un-parsed intervals using "interval faceting" syntax.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Iterator<IntervalFacets.FacetInterval>` | `iterator()` Iterate over all the intervals

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### IntervalFacets

          public IntervalFacets(SchemaField schemaField,
                                SolrIndexSearcher searcher,
                                DocSet docs,
                                String[] intervals,
                                SolrParams params)
                         throws SyntaxError,
                                IOException

      Constructor that accepts un-parsed intervals using "interval faceting" syntax. See `IntervalFacets` for syntax. Intervals don't need to be in order.
      Throws:
        `SyntaxError`
        `IOException`

    - #### IntervalFacets

          public IntervalFacets(SchemaField schemaField,
                                SolrIndexSearcher searcher,
                                DocSet docs,
                                IntervalFacets.FacetInterval[] intervals)
                         throws IOException

      Constructor that accepts an already constructed array of `IntervalFacets.FacetInterval` objects. This array needs to be sorted by start value in weakly ascending order. null values are not allowed in the array.
      Throws:
        `IOException`

  - ### Method Detail

    - #### iterator

          public Iterator<IntervalFacets.FacetInterval> iterator()

      Iterate over all the intervals
      Specified by:
        `iterator` in interface `Iterable<IntervalFacets.FacetInterval>`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.