Skip to content

Commit 3476f6f

Browse files
alek13QingWei-Li
authored andcommitted
fix: duplicate results in search fixed #257 (#284)
1 parent fac7ce6 commit 3476f6f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/plugins/search/search.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,22 @@ export function genIndex (path, content = '', router, depth) {
6565
return index
6666
}
6767

68-
export function search (keywords) {
68+
/**
69+
* @param {String} query
70+
* @returns {Array}
71+
*/
72+
export function search (query) {
6973
const matchingResults = []
7074
let data = []
7175
Object.keys(INDEXS).forEach(key => {
7276
data = data.concat(Object.keys(INDEXS[key]).map(page => INDEXS[key][page]))
7377
})
7478

75-
keywords = [].concat(keywords, keywords.trim().split(/[\s\-\,\\/]+/))
79+
query = query.trim()
80+
let keywords = query.split(/[\s\-\,\\/]+/)
81+
if (keywords.length !== 1) {
82+
keywords = [].concat(query, keywords)
83+
}
7684

7785
for (let i = 0; i < data.length; i++) {
7886
const post = data[i]

0 commit comments

Comments
 (0)