From 2c85be3e94481a88133f0d7553019d4e1032f6ec Mon Sep 17 00:00:00 2001 From: Alexander Chibrikin Date: Mon, 16 Oct 2017 19:39:02 +0300 Subject: [PATCH] #257 fix duplicate results in search --- src/plugins/search/search.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 3615ea4ba..7ecf21a62 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -65,14 +65,22 @@ export function genIndex (path, content = '', router, depth) { return index } -export function search (keywords) { +/** + * @param {String} query + * @returns {Array} + */ +export function search (query) { const matchingResults = [] let data = [] Object.keys(INDEXS).forEach(key => { data = data.concat(Object.keys(INDEXS[key]).map(page => INDEXS[key][page])) }) - keywords = [].concat(keywords, keywords.trim().split(/[\s\-\,\\/]+/)) + query = query.trim() + let keywords = query.split(/[\s\-\,\\/]+/) + if (keywords.length !== 1) { + keywords = [].concat(query, keywords) + } for (let i = 0; i < data.length; i++) { const post = data[i]