# new AlphabeticIndex(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
options to the parser |
Methods
# addElement(element) → {string|undefined}
Add an element to the index. The element is added to the appropriate bucket and sorted within that bucket according to the collation for the locale set up within this index.
Parameters:
Name | Type | Description |
---|---|---|
element |
string
|
undefined
|
the element to add |
the label of the bucket into which this element was added
string
|
undefined
# addLabels(labels, startopt)
Add labels to this index for characters that are not commonly used in the current locale. These are added into the list of bucket labels at the given start index. If start is not given, or is not within the range of 0 (the overflow bucket) to N (the underflow bucket), then the default position is at the end of the list right before the underflow bucket.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
labels |
Array.<string>
|
array of labels to add in the order you would like to see them returned |
|
start |
number
|
<optional> |
the position in the bucket labels list to add these new labels |
# clear()
Clear all elements from the buckets. This index can be reused for a new batch of elements by clearing it first.
# getAllBucketLabels() → {Array.<string>}
Return the all the bucket labels typically used in the locale. This includes all bucket labels, even if those buckets do not contain any elements.
the array of bucket labels for this index in collation order
Array.<string>
# getAllBuckets() → {Object}
Return a javascript hash containing all elements in the index. The hash has a property for each bucket, and the value of the property is an array of elements. Example:
[
{
label: "A",
elements: [ "A", "Aachen", "Adams", ... ]
},
{
label: "B",
elements: ["B", "Baaa", "Boo"]
},
...
{
label: "#",
elements: ["3par.com", "@handle"]
}
]
All elements within a bucket are sorted per the collation for the locale of this index.
a hash of all buckets and elements as per the description above.
Object
# getBucket(element) → {string|undefined}
Return the label of the bucket for a given element. This follows the rules set up when the index was instantiated to find the bucket into which the element would go if it were added to this index. The element is not added to the index, however. (See addElement for that.)
Parameters:
Name | Type | Description |
---|---|---|
element |
string
|
undefined
|
the element to check |
the label for the bucket for this element
string
|
undefined
# getBucketCount() → {number}
Return the total number of buckets in this index.
the number of buckets in this index
number
# getBucketLabels() → {Array.<string>}
Return the bucket labels for this index in order. This method only returns the index labels for buckets that actually contain elements. This will include the under- and overflow labels if they are used in this index.
the array of bucket labels for this index in collation order
Array.<string>
# getCollator() → {Collator}
Return the collator used to sort elements in this index.
the ilib Collator instance used in this index
# getElementCount() → {number}
Return the total number of elements in the index. This includes all elements across all buckets.
The number of elements in the index
number
# getIndexStyle() → {string}
Return default indexing style in the current locale.
the default indexing style for this locale.
string
# getLocale() → {Locale}
Return the locale used with this instance.
the Locale instance for this index
# getOverflowLabel() → {string}
Get the default label used in the for overflow bucket. This is the first item in a list. eg. ... A B C
the overflow bucket label
string
# getUnderflowLabel() → {string}
Get the default label used in underflow, This is the last item in a list. eg. the last item in: X Y Z #
the label used for underflow elements
string
# setOverflowLabel(overflowLabel)
Set the overflow bucket label.
Parameters:
Name | Type | Description |
---|---|---|
overflowLabel |
string
|
the label to use for the overflow buckets |
# setUnderflowLabel(underflowLabel)
Set the underflow bucket label.
Parameters:
Name | Type | Description |
---|---|---|
underflowLabel |
string
|
the label to use for the underflow buckets |