summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-lunr/src
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-05 13:36:38 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-05 13:36:38 +0200
commit86848e7acb5e5308297a0e4aaf0a164e7f9bf5f2 (patch)
tree745ec1374b3a051fb5c0660c4f4a6154e9abc70a /packages/gitbook-plugin-lunr/src
parent9ce3646d6e0d10035b6528e5384189fbed3d18c6 (diff)
downloadgitbook-86848e7acb5e5308297a0e4aaf0a164e7f9bf5f2.zip
gitbook-86848e7acb5e5308297a0e4aaf0a164e7f9bf5f2.tar.gz
gitbook-86848e7acb5e5308297a0e4aaf0a164e7f9bf5f2.tar.bz2
Fix format of lunr results
Diffstat (limited to 'packages/gitbook-plugin-lunr/src')
-rw-r--r--packages/gitbook-plugin-lunr/src/actions.js6
-rw-r--r--packages/gitbook-plugin-lunr/src/index.js10
-rw-r--r--packages/gitbook-plugin-lunr/src/reducer.js4
3 files changed, 18 insertions, 2 deletions
diff --git a/packages/gitbook-plugin-lunr/src/actions.js b/packages/gitbook-plugin-lunr/src/actions.js
index 8ead7ef..4d878c7 100644
--- a/packages/gitbook-plugin-lunr/src/actions.js
+++ b/packages/gitbook-plugin-lunr/src/actions.js
@@ -19,6 +19,12 @@ function load(json) {
*/
function fetch() {
return (dispatch, getState) => {
+ const { idx } = getState().lunr;
+
+ if (idx) {
+ return GitBook.Promise.resolve();
+ }
+
return GitBook.Promise.resolve()
.then(() => {
// TODO: resolve the file correctly
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());
});
}
diff --git a/packages/gitbook-plugin-lunr/src/reducer.js b/packages/gitbook-plugin-lunr/src/reducer.js
index 48c3c23..7e317c4 100644
--- a/packages/gitbook-plugin-lunr/src/reducer.js
+++ b/packages/gitbook-plugin-lunr/src/reducer.js
@@ -4,6 +4,10 @@ const { Record } = GitBook.Immutable;
const { TYPES } = require('./actions');
+/*
+ We store the lunr index an the document index in the store.
+ */
+
const LunrState = Record({
idx: null,
store: {}