Skip to content

Commit 266ea02

Browse files
committed
Adding how to configure search index and index strategies
1 parent 3434fe8 commit 266ea02

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,46 @@ JsSearch.StopWordsMap.bob = true; // Treat "bob" as a stop word
134134
Note that stop words are lower case and so using a case-sensitive sanitizer may prevent some stop words from being
135135
removed.
136136

137-
### TF-IDF ranking
137+
### Configuring the search index
138+
139+
There are two search indices packaged with `js-search`.
138140

139141
Term frequency–inverse document frequency (or TF-IDF) is a numeric statistic intended to reflect how important a word
140142
(or words) are to a document within a corpus. The TF-IDF value increases proportionally to the number of times a word
141143
appears in the document but is offset by the frequency of the word in the corpus. This helps to adjust for the fact that
142144
some words (e.g. and, or, the) appear more frequently than others.
143145

144146
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:
147+
can specify an alternate [`ISearchIndex`](https://github.com/wuweiweiwu/js-search/blob/master/source/SearchIndex/SearchIndex.js)
148+
implementation in order to disable TF-IDF, like so:
146149

147150
```javascript
151+
// default
152+
search.searchIndex = new JsSearch.TfIdfSearchIndex();
153+
154+
// Search index capable of returning results matching a set of tokens
155+
// but without any meaningful rank or order.
148156
search.searchIndex = new JsSearch.UnorderedSearchIndex();
149157
```
158+
159+
### Configuring the index strategy
160+
161+
There are three index strategies packaged with `js-search`.
162+
163+
`PrefixIndexStrategy` indexes for prefix searches
164+
(e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups).
165+
166+
`AllSubstringsIndexStrategy` indexes for all substrings. In other word "c", "ca", "cat", "a", "at", and "t" all match "cat".
167+
168+
`ExactWordIndexStrategy` indexes for exact word matches. For example "bob" will match "bob jones".
169+
170+
```javascript
171+
// default
172+
search.indexStrategy = new JsSearch.PrefixIndexStrategy();
173+
174+
// this index strategy is built for all substrings matches.
175+
search.indexStrategy = new JsSearch.AllSubstringsIndexStrategy();
176+
177+
// this index strategy is built for exact word matches.
178+
search.indexStrategy = new JsSearch.ExactWordIndexStrategy();
179+
```

0 commit comments

Comments
 (0)