|
3 | 3 | [Tokenization](#tokenization) | |
4 | 4 | [Stemming](#stemming) | |
5 | 5 | [Stop Words](#stop-words) | |
6 | | -[TF-IDF ranking](#tf-idf-ranking) |
| 6 | +[Search Index](#configuring-the-search-index) | |
| 7 | +[Index Strategy](#configuring-the-index-strategy) |
7 | 8 |
|
8 | 9 | # Js Search: client-side search library |
9 | 10 |
|
@@ -134,16 +135,50 @@ JsSearch.StopWordsMap.bob = true; // Treat "bob" as a stop word |
134 | 135 | Note that stop words are lower case and so using a case-sensitive sanitizer may prevent some stop words from being |
135 | 136 | removed. |
136 | 137 |
|
137 | | -### TF-IDF ranking |
| 138 | +### Configuring the search index |
| 139 | + |
| 140 | +There are two search indices packaged with `js-search`. |
138 | 141 |
|
139 | 142 | Term frequency–inverse document frequency (or TF-IDF) is a numeric statistic intended to reflect how important a word |
140 | 143 | (or words) are to a document within a corpus. The TF-IDF value increases proportionally to the number of times a word |
141 | 144 | appears in the document but is offset by the frequency of the word in the corpus. This helps to adjust for the fact that |
142 | 145 | some words (e.g. and, or, the) appear more frequently than others. |
143 | 146 |
|
144 | 147 | By default Js Search supports TF-IDF ranking but this can be disabled for performance reasons if it is not required. You |
145 | | -can specify an alternate `ISearchIndex` implementation in order to disable TF-IDF, like so: |
| 148 | +can specify an alternate [`ISearchIndex`](https://github.com/bvaughn/js-search/blob/master/source/SearchIndex/SearchIndex.js) |
| 149 | +implementation in order to disable TF-IDF, like so: |
146 | 150 |
|
147 | 151 | ```javascript |
| 152 | +// default |
| 153 | +search.searchIndex = new JsSearch.TfIdfSearchIndex(); |
| 154 | + |
| 155 | +// Search index capable of returning results matching a set of tokens |
| 156 | +// but without any meaningful rank or order. |
148 | 157 | search.searchIndex = new JsSearch.UnorderedSearchIndex(); |
149 | 158 | ``` |
| 159 | + |
| 160 | +### Configuring the index strategy |
| 161 | + |
| 162 | +There are three index strategies packaged with `js-search`. |
| 163 | + |
| 164 | +`PrefixIndexStrategy` indexes for prefix searches. |
| 165 | +(e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups). |
| 166 | + |
| 167 | +`AllSubstringsIndexStrategy` indexes for all substrings. In other word "c", "ca", "cat", "a", "at", and "t" all match "cat". |
| 168 | + |
| 169 | +`ExactWordIndexStrategy` indexes for exact word matches. For example "bob" will match "bob jones" (but "bo" will not). |
| 170 | + |
| 171 | +By default Js Search supports prefix indexing but this is configurable. You |
| 172 | +can specify an alternate [`IIndexStrategy`](https://github.com/bvaughn/js-search/blob/master/source/IndexStrategy/IndexStrategy.js) |
| 173 | +implementation in order to disable prefix indexing, like so: |
| 174 | + |
| 175 | +```javascript |
| 176 | +// default |
| 177 | +search.indexStrategy = new JsSearch.PrefixIndexStrategy(); |
| 178 | + |
| 179 | +// this index strategy is built for all substrings matches. |
| 180 | +search.indexStrategy = new JsSearch.AllSubstringsIndexStrategy(); |
| 181 | + |
| 182 | +// this index strategy is built for exact word matches. |
| 183 | +search.indexStrategy = new JsSearch.ExactWordIndexStrategy(); |
| 184 | +``` |
0 commit comments