Skip to content

Commit 445d475

Browse files
authored
Merge pull request #54 from wuweiweiwu/issue-38
Updating docs about searchIndex and indexStrategy
2 parents 3434fe8 + fe4febb commit 445d475

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
[Tokenization](#tokenization) |
44
[Stemming](#stemming) |
55
[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)
78

89
# Js Search: client-side search library
910

@@ -134,16 +135,50 @@ JsSearch.StopWordsMap.bob = true; // Treat "bob" as a stop word
134135
Note that stop words are lower case and so using a case-sensitive sanitizer may prevent some stop words from being
135136
removed.
136137

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

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

144147
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:
146150

147151
```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.
148157
search.searchIndex = new JsSearch.UnorderedSearchIndex();
149158
```
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

Comments
 (0)