search-gold 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -39
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
Your page displays a list columnar information, based on the
|
|
5
|
+
Your web page displays a list of columnar information, based on the common data stucture:
|
|
6
6
|
|
|
7
7
|
`array of objects`
|
|
8
8
|
|
|
@@ -22,25 +22,30 @@ $ bun i search-gold
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
The following should provide enough to get
|
|
25
|
+
The following should provide enough to get local search up and running and keep your users in a happy place!
|
|
26
26
|
|
|
27
|
-
`my-data-list-component.ts
|
|
27
|
+
Provide the following in your component, e.g., `my-data-list-component.ts`.
|
|
28
|
+
|
|
29
|
+
### 1. Import the two types and methods.
|
|
28
30
|
```javascript
|
|
29
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
30
|
-
// 1. Import the two types and methods.
|
|
31
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
32
31
|
import {
|
|
33
32
|
ConfigParams,
|
|
34
33
|
ItemRecord,
|
|
35
34
|
searchHandler,
|
|
36
35
|
searchSetConfig,
|
|
37
36
|
} from 'search-gold'
|
|
37
|
+
````
|
|
38
|
+
|
|
39
|
+
### 2. Create a method to set search configuration.
|
|
40
|
+
|
|
41
|
+
This wrapper method only needs to be called in the following two cases:
|
|
42
|
+
|
|
43
|
+
* when component is initialized and when data is ready.
|
|
44
|
+
* when data changes (record has been created, edited, deleted)
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// The configuration will be custom for your data.
|
|
43
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
46
|
+
You can name this wrapper method anything you want.
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
44
49
|
const initSearchConfig = () => {
|
|
45
50
|
const config: ConfigParams = {
|
|
46
51
|
// required: items must reference an array of
|
|
@@ -59,48 +64,56 @@ const initSearchConfig = () => {
|
|
|
59
64
|
caseSensitive: true,
|
|
60
65
|
},
|
|
61
66
|
|
|
67
|
+
// Call the imported method with config arg.
|
|
62
68
|
searchSetConfig(config)
|
|
63
69
|
|
|
64
|
-
//
|
|
65
|
-
//
|
|
70
|
+
// After setting the config, you can call searchHandler()
|
|
71
|
+
// as many times as necessary without having to set the
|
|
72
|
+
// config again.
|
|
66
73
|
//
|
|
67
|
-
//
|
|
68
|
-
// the
|
|
69
|
-
//
|
|
70
|
-
//
|
|
74
|
+
// Passing an empty string effectively returns the
|
|
75
|
+
// the unfiltered set of records, the same as MyData.
|
|
76
|
+
//
|
|
77
|
+
// How you set up your component to display the filtered
|
|
78
|
+
// data is up to you and how your component is structured.
|
|
79
|
+
// This is just an example.
|
|
71
80
|
myFilteredData = <ItemRecord[]>searchHandler('')
|
|
72
81
|
}
|
|
82
|
+
````
|
|
83
|
+
|
|
84
|
+
### 3. Initialize the search engine.
|
|
73
85
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
//
|
|
86
|
+
This method (from Step 2.) should be called when your component has been
|
|
87
|
+
initialized and your data is ready.
|
|
88
|
+
|
|
89
|
+
Also, this `initSearchConfig()` method should be called whenever your
|
|
90
|
+
data changes via a record create, edit, or delete.
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// For this example we chose this method name; you
|
|
94
|
+
// can name this wrapper method anything you want.
|
|
83
95
|
initSearchConfig()
|
|
96
|
+
````
|
|
97
|
+
|
|
98
|
+
### 4. Execute search queries and get results.
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// 'searchMyData') and is called on every keystroke.
|
|
91
|
-
//
|
|
92
|
-
// You can optionally add a debounce in your component.
|
|
93
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
100
|
+
Presumably, a method is binded to the UI's search field (in this example it's called
|
|
101
|
+
`searchMyData`) and is called on every keystroke.
|
|
102
|
+
|
|
103
|
+
(You can optionally add a debounce mechanism in your component if need be.)
|
|
104
|
+
```javascript
|
|
94
105
|
const searchMyData = (query: string) => {
|
|
106
|
+
// Call the imported method and get results.
|
|
95
107
|
myFilteredData = searchHandler(query)
|
|
96
108
|
}
|
|
97
109
|
```
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
## Author's Development
|
|
112
|
+
|
|
113
|
+
During development of the `search-gold` package, I integrated it
|
|
114
|
+
into a couple of apps I had built with Vue using its Composition API.
|
|
101
115
|
|
|
102
|
-
I tried to keep the Usage code
|
|
103
|
-
neutral.
|
|
116
|
+
In this documentation I tried to keep the Usage code snippets framework neutral.
|
|
104
117
|
|
|
105
118
|
# Credits
|
|
106
119
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "search-gold",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"description": "speedy search engine targeting an array of objects",
|
|
6
6
|
"author": "gold",
|
|
7
7
|
"main": "./src/search.ts",
|
|
@@ -30,6 +30,9 @@
|
|
|
30
30
|
"keywords": [
|
|
31
31
|
"data search",
|
|
32
32
|
"search",
|
|
33
|
+
"local search",
|
|
34
|
+
"search for gold",
|
|
35
|
+
"search for 金",
|
|
33
36
|
"data filter",
|
|
34
37
|
"simple search",
|
|
35
38
|
"fast search"
|