summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-lunr/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-plugin-lunr/src/index.js')
-rw-r--r--packages/gitbook-plugin-lunr/src/index.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/gitbook-plugin-lunr/src/index.js b/packages/gitbook-plugin-lunr/src/index.js
index eab5975..1135f51 100644
--- a/packages/gitbook-plugin-lunr/src/index.js
+++ b/packages/gitbook-plugin-lunr/src/index.js
@@ -7,10 +7,16 @@ const actions = require('./actions');
* @param {String} query
* @return {Promise<List>}
*/
-function searchHandler(query, dispatch) {
+function searchHandler(query, dispatch, getState) {
+ // Fetch the index if non loaded
return dispatch(actions.fetch())
+
+ // Execute the search
.then(() => {
- return [];
+ const { idx, store } = getState().lunr;
+ const results = idx.search(query);
+
+ return results.map(({ref}) => store.get(ref).toJS());
});
}