You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This plugin adds a **search()** method to the vuex-orm query methods to easily filter matched records using fuzzy search logic from the [Fuse.js](http://fusejs.io/) library.
Vuex ORM Search plugin adds a **search()** method to the vuex-orm query methods to easily filter matched records using fuzzy search logic from the [Fuse.js](http://fusejs.io/) library.
4
23
5
24
A simple example to search for '_john_' within your query:
Import the search plugin in the Vuex Store entry file.
45
45
46
-
```javascript
47
-
// ex: store/index.js
46
+
```js
48
47
importVuexORMfrom'@vuex-orm/core'
49
48
importVuexORMSearchfrom'@vuex-orm/plugin-search'
50
-
````
51
-
52
-
Tell VuexORM to install the plugin
53
49
54
-
```javascript
55
50
VuexORM.use(VuexORMSearch, {
56
-
// configure default fuse.js options here (see below)
51
+
//Configure default fuse.js options here (see "Configuration" section below).
57
52
})
58
53
```
59
54
60
-
## Fuse.js Default Options
55
+
### API
56
+
57
+
The search plugin method accepts two parameters.
58
+
59
+
```ts
60
+
search(terms: string|string[], options: object): this
61
+
```
62
+
63
+
-**terms** – any string or an array of strings.
64
+
-**options** – see the "Configurations" section below.
65
+
66
+
> **NOTE:** If passing an array of search terms, the results assume some element in the array to be matched.
61
67
62
-
The plugin provides opinionated default fuse.js options for token based matching for optimum performance. These options are easily changed at two stages of the plugin lifecycle:
68
+
## Configurations
63
69
64
-
-Plugininstallation (sets the global default options)
65
-
- Runtime within the **search()** query chain
70
+
The plugin provides opinionated default Fuse.js options for token-based matching for optimum performance. These options can be easily changed at two stages of the plugin lifecycle:
66
71
67
-
see: [Fuse.js](http://fusejs.io/) for demo
72
+
- Plugin installation (sets the global default options).
73
+
- Runtime within the **search()** query chain.
74
+
75
+
See: [Fuse.js](http://fusejs.io/) for demo.
68
76
69
77
| Property | Description | Default |
70
78
| --- | --- | --- |
71
-
| searchPrimaryKey | Also search the primary key |false|
72
-
| location | Approximately where in the text is the pattern expected to be found |0|
73
-
| distance | Determines how close the match must be to the fuzzy location |100|
74
-
| threshold |**0.0** requires a perfect match, and a threshold of**1.0** would match anything |0.3|
75
-
| maxPatternLength | Machine word size |32|
76
-
| caseSensitive | Indicates whether comparisons should be case sensitive |false|
77
-
| tokenSeparator | Regex used to separate words when searching. Only applicable when **tokenize** is **true**|/+/g |
78
-
| findAllMatches | When true, the algorithm continues searching to even if a perfect match is found |false|
79
-
| minMatchCharLength | Minimum number of characters that must be matched before a result is considered a match |1|
80
-
| keys | An array offields (columns) to be included in the search |Model.$fields() |
81
-
| shouldSort | Whether to sort the result list, by score |false|
82
-
| tokenize | When true, the search algorithm will search individual words **and** the full string, computing the final score as a function of both. **Note**: that when _tokenize_ is _true_, the **threshold**, **distance**, and **location** are inconsequential for individual tokens | false |
83
-
| matchAllTokens | When true, the result set will only include records that match all tokens. Will only work if **tokenize** is also true. **Note**: It is better to use multiple **.search()** query chains if you have multiple terms that need to match. | false |
84
-
| verbose | Will print to the console. Useful for debugging. | false |
85
-
86
-
## Option Use Examples
87
-
88
-
Some examples on how to use the search plugin with case specific options
79
+
| searchPrimaryKey | Also search the primary key |`false`|
80
+
| location | Approximately where in the text is the pattern expected to be found |`0`|
81
+
| distance | Determines how close the match must be to the fuzzy location |`100`|
82
+
| threshold |**0.0** requires a perfect match, and a threshold of **1.0** would match anything |`0.3`|
83
+
| maxPatternLength | Machine word size |`32`|
84
+
| caseSensitive | Indicates whether comparisons should be case sensitive |`false`|
85
+
| tokenSeparator | Regex used to separate words when searching. Only applicable when **tokenize** is **true**|`/ +/g`|
86
+
| findAllMatches | When true, the algorithm continues searching to even if a perfect match is found |`false`|
87
+
| minMatchCharLength | Minimum number of characters that must be matched before a result is considered a match |`1`|
88
+
| keys | An array of fields (columns) to be included in the search |Keys from `Model.fields()`|
89
+
| shouldSort | Whether to sort the result list, by score |`false`|
90
+
| tokenize | When true, the search algorithm will search individual words **and** the full string, computing the final score as a function of both. **NOTE**: that when _tokenize_ is _true_, the **threshold**, **distance**, and **location** are inconsequential for individual tokens |`false`|
91
+
| matchAllTokens | When true, the result set will only include records that match all tokens. Will only work if **tokenize** is also true. **NOTE**: It is better to use multiple **.search()** query chains if you have multiple terms that need to match. |`false`|
92
+
| verbose | Will print to the console. Useful for debugging. |`false`|
93
+
94
+
## Option Examples
95
+
96
+
Here are some examples on how to use the search plugin with case specific options.
89
97
90
98
### During Plugin Install
91
99
92
-
For example, if we want to match based on case sensitive and no fuzzy search logic (perfect match)
93
-
```javascript
100
+
For example, if we want to match based on case sensitive and no fuzzy search logic (perfect match).
101
+
102
+
```js
94
103
VuexORM.use(VuexORMSearch, {
95
104
caseSensitive:true,
96
105
threshold:0
@@ -103,35 +112,60 @@ The global install options will now default to case sensitive and no fuzzy logic
103
112
104
113
Let's also specify the need to only search the **firstName** and **lastName** fields.
We are excited that you are interested in contributing to Vuex ORM Search! Anything from raising an issue, submitting an idea of a new feature, or making a pull request is welcome!
136
+
137
+
### Development
138
+
139
+
```bash
140
+
$ yarn build
141
+
```
142
+
143
+
Compile files and generate bundles in `dist` directory.
144
+
145
+
```bash
146
+
$ yarn lint
147
+
```
148
+
149
+
Lint files using a rule of Standard JS.
150
+
151
+
```bash
152
+
$ yarn test
153
+
```
154
+
155
+
Run the test using [Jest](https://jestjs.io/).
156
+
157
+
```bash
158
+
$ yarn test:watch
159
+
```
160
+
161
+
Run the test in watch mode.
162
+
163
+
```bash
164
+
$ yarn coverage
133
165
```
134
166
167
+
Generate test coverage in `coverage` directory.
168
+
135
169
## License
136
170
137
171
The Vuex ORM Plugin Search is open-sourced software licensed under the [MIT license](LICENSE.md).
0 commit comments