Skip to content

Commit

Permalink
Merge pull request #417 from soichih/patch-1
Browse files Browse the repository at this point in the history
Update index.js
  • Loading branch information
h-enk authored Aug 11, 2021
2 parents dfdc28a + b575ca0 commit 47a5626
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,36 @@ Source:
suggestions.addEventListener('click', accept_suggestion, true);

function show_results(){
const maxResult = 5;

var value = this.value;
var results = index.search(value, { limit: 5, index: ["content"], enrich: true });
var entry, childs = suggestions.childNodes;
var i = 0, len = results.length;
var results = index.search(value, {limit: maxResult, enrich: true});

suggestions.classList.remove('d-none');
suggestions.innerHTML = "";

//flatSearch now returns results for each index field. create a single list
const flatResults = {}; //keyed by href to dedupe results
results.forEach(result=>{
result.result.forEach(r=>{
flatResults[r.doc.href] = r.doc;
});
});

results.forEach(function(results) {

entry = document.createElement('div');

entry.innerHTML = '<a href><span></span><span></span></a>';

a = entry.querySelector('a'),
t = entry.querySelector('span:first-child'),
d = entry.querySelector('span:nth-child(2)');

// console.log(results);

a.href = results.result[i].doc.href;
t.textContent = results.result[i].doc.title;
d.textContent = results.result[i].doc.description;

suggestions.appendChild(entry);
//construct a list of suggestions list
for(const href in flatResults) {
const doc = flatResults[href];

});
const entry = document.createElement('div');
entry.innerHTML = '<a href><span></span><span></span></a>';

while(childs.length > len){
entry.querySelector('a').href = href;
entry.querySelector('span:first-child').textContent = doc.title;
entry.querySelector('span:nth-child(2)').textContent = doc.description;

suggestions.removeChild(childs[i])
suggestions.appendChild(entry);
if(suggestions.childElementCount == maxResult) break;
}

}

function accept_suggestion(){
Expand Down

0 comments on commit 47a5626

Please sign in to comment.