Package org.apache.ignite.cache

## Class QueryIndex

- java.lang.Object
- - org.apache.ignite.cache.QueryIndex

- All Implemented Interfaces:
    `Serializable`

      public class QueryIndex
      extends Object
      implements Serializable

  Contains list of fields to be indexed. It is possible to provide field name suffixed with index specific extension, for example for `sorted` index the list can be provided as following `(id, name asc, age desc)`.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `DFLT_INLINE_SIZE` | Default index inline size.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `QueryIndex()` | Creates an empty index.
    `QueryIndex​(String field)` | Creates single-field sorted ascending index.
    `QueryIndex​(String field, boolean asc)` | Creates single-field sorted index.
    `QueryIndex​(String field, boolean asc, String name)` | Creates single-field sorted index.
    `QueryIndex​(String field, QueryIndexType type)` | Creates index for one field.
    `QueryIndex​(String field, QueryIndexType type, boolean asc)` | Creates index for one field.
    `QueryIndex​(String field, QueryIndexType type, boolean asc, String name)` | Creates index for one field.
    `QueryIndex​(Collection<String> fields, QueryIndexType type)` | Creates index for a collection of fields.
    `QueryIndex​(LinkedHashMap<String,​Boolean> fields, QueryIndexType type)` | Creates index for a collection of fields.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `equals​(Object o)`
    `Collection<String>` | `getFieldNames()` |
    `LinkedHashMap<String,​Boolean>` | `getFields()` | Gets fields included in the index.
    `QueryIndexType` | `getIndexType()` | Gets index type.
    `int` | `getInlineSize()` | Gets index inline size in bytes.
    `String` | `getName()` | Gets index name.
    `int` | `hashCode()`
    `QueryIndex` | `setFieldNames​(Collection<String> fields, boolean asc)` | Sets a collection of field names altogether with the field sorting direction.
    `QueryIndex` | `setFields​(LinkedHashMap<String,​Boolean> fields)` | Sets fields included in the index.
    `QueryIndex` | `setIndexType​(QueryIndexType type)` | Sets index type.
    `QueryIndex` | `setInlineSize​(int inlineSize)` | Sets index inline size in bytes.
    `QueryIndex` | `setName​(String name)` | Sets index name.
    `String` | `toString()`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DFLT_INLINE_SIZE

          public static final int DFLT_INLINE_SIZE

      Default index inline size.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### QueryIndex

          public QueryIndex()

      Creates an empty index. Should be populated via setters.

    - #### QueryIndex

          public QueryIndex​(String field)

      Creates single-field sorted ascending index.
      Parameters:
        `field` - Field name.

    - #### QueryIndex

          public QueryIndex​(String field,
                            boolean asc)

      Creates single-field sorted index.
      Parameters:
        `field` - Field name.
        `asc` - Ascending flag.

    - #### QueryIndex

          public QueryIndex​(String field,
                            boolean asc,
                            String name)

      Creates single-field sorted index.
      Parameters:
        `field` - Field name.
        `asc` - Ascending flag.
        `name` - Index name.

    - #### QueryIndex

          public QueryIndex​(String field,
                            QueryIndexType type)

      Creates index for one field. If index is sorted, then ascending sorting is used by default. To specify sort order, use the next method. This constructor should also have a corresponding setter method.
      Parameters:
        `field` - Field name.
        `type` - Index type.

    - #### QueryIndex

          public QueryIndex​(String field,
                            QueryIndexType type,
                            boolean asc)

      Creates index for one field. The last boolean parameter is ignored for non-sorted indexes.
      Parameters:
        `field` - Field name.
        `type` - Index type.
        `asc` - Ascending flag.

    - #### QueryIndex

          public QueryIndex​(String field,
                            QueryIndexType type,
                            boolean asc,
                            String name)

      Creates index for one field. The last boolean parameter is ignored for non-sorted indexes.
      Parameters:
        `field` - Field name.
        `type` - Index type.
        `asc` - Ascending flag.
        `name` - Index name.

    - #### QueryIndex

          public QueryIndex​(Collection<String> fields,
                            QueryIndexType type)

      Creates index for a collection of fields. If index is sorted, fields will be sorted in ascending order.
      Parameters:
        `fields` - Collection of fields to create an index.
        `type` - Index type.

    - #### QueryIndex

          public QueryIndex​(LinkedHashMap<String,​Boolean> fields,
                            QueryIndexType type)

      Creates index for a collection of fields. The order of fields in the created index will be the same as iteration order in the passed map. Map value defines whether the index will be ascending.
      Parameters:
        `fields` - Field name to field sort direction for sorted indexes.
        `type` - Index type.

  - ### Method Detail

    - #### getName

          public String getName()

      Gets index name. Will be automatically set if not provided by a user.
      Returns:
        Index name.

    - #### setName

          public QueryIndex setName​(String name)

      Sets index name.
      Parameters:
        `name` - Index name.
      Returns:
        `this` for chaining.

    - #### getFields

          public LinkedHashMap<String,​Boolean> getFields()

      Gets fields included in the index.
      Returns:
        Collection of index fields.

    - #### setFields

          public QueryIndex setFields​(LinkedHashMap<String,​Boolean> fields)

      Sets fields included in the index.
      Parameters:
        `fields` - Collection of index fields.
      Returns:
        `this` for chaining.

    - #### getFieldNames

          public Collection<String> getFieldNames()

      Returns:
        Gets a collection of field names.

    - #### setFieldNames

          public QueryIndex setFieldNames​(Collection<String> fields,
                                          boolean asc)

      Sets a collection of field names altogether with the field sorting direction. Sorting direction will be ignored for non-sorted indexes.
      Parameters:
        `fields` - Collection of fields.
        `asc` - Ascending flag.
      Returns:
        `this` for chaining.

    - #### getIndexType

          public QueryIndexType getIndexType()

      Gets index type.
      Returns:
        Index type.

    - #### setIndexType

          public QueryIndex setIndexType​(QueryIndexType type)

      Sets index type.
      Parameters:
        `type` - Index type.
      Returns:
        `this` for chaining.

    - #### getInlineSize

          public int getInlineSize()

      Gets index inline size in bytes. When enabled part of indexed value will be placed directly to index pages, thus minimizing data page accesses, thus increasing query performance.

      Allowed values:

      - `-1` (default) - determine inline size automatically (see below)
      - `0` - index inline is disabled (not recommended)
      - positive value - fixed index inline
      When set to `-1`, Ignite will try to detect inline size automatically. It will be no more than `CacheConfiguration.getSqlIndexMaxInlineSize()`. Index inline will be enabled for all fixed-length types, but will not be enabled for `String`.
      Returns:
        Index inline size in bytes.

    - #### setInlineSize

          public QueryIndex setInlineSize​(int inlineSize)

      Sets index inline size in bytes. When enabled part of indexed value will be placed directly to index pages, thus minimizing data page accesses, thus increasing query performance.

      Allowed values:

      - `-1` (default) - determine inline size automatically (see below)
      - `0` - index inline is disabled (not recommended)
      - positive value - fixed index inline
      When set to `-1`, Ignite will try to detect inline size automatically. It will be no more than `CacheConfiguration.getSqlIndexMaxInlineSize()`. Index inline will be enabled for all fixed-length types, but will not be enabled for `String`.
      Parameters:
        `inlineSize` - Inline size.
      Returns:
        `this` for chaining.

    - #### equals

          public boolean equals​(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`