diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/IndexParser.java b/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/IndexParser.java index d1b9656..d672bf6 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/IndexParser.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/IndexParser.java @@ -8,6 +8,7 @@ import java.io.PrintWriter; import java.util.Map; import java.util.TreeMap; +import java.util.stream.Collectors; public class IndexParser extends Compiler { protected int idx = -1; @@ -61,7 +62,8 @@ public void putFeaturePhrase(String featureId, String rawPhrase){ public void buildIndex(PrintWriter out) throws IOException { out.print("let indexPhrases = "); - mapper.writeValue(out, phrases); + mapper.writeValue(out, phrases.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))); out.println(";"); out.print("let indexMap = "); diff --git a/core/src/main/resources/htmlTemplate/dist/feature-pasta.min.js b/core/src/main/resources/htmlTemplate/dist/feature-pasta.min.js index 28220c5..7ee5e99 100644 --- a/core/src/main/resources/htmlTemplate/dist/feature-pasta.min.js +++ b/core/src/main/resources/htmlTemplate/dist/feature-pasta.min.js @@ -562,22 +562,22 @@ $("#btn-diff").click(function(){ }); // TYPE HEAD -var substringMatcher = function(strs) { +var substringMatcher = function(indexPhrases, indexMap) { return function findMatches(q, cb) { var matches = []; var substrRegex = new RegExp(q, 'i'); - $.each(strs, function (featureId, indiceItem) { - $.each(indiceItem.values, function (i, txt) { - if (substrRegex.test(txt)) { + for(let i in indexMap){ + for(let j in indexMap[i].phrases){ + if(substrRegex.test(indexPhrases[indexMap[i].phrases[j]])){ matches.push({ - "url": featureId, - "name": indiceItem.name, - "txt": txt + "url": indexPhrases[i], + "name": indexPhrases[indexMap[i].title], + "txt": indexPhrases[indexMap[i].phrases[j]] }); } - }); - }); + } + } cb(matches); }; @@ -590,7 +590,7 @@ $('#busca').typeahead({ displayKey: 'txt', name: 'txt', display: 'txt', - source: substringMatcher(indice), + source: substringMatcher(indexPhrases, indexMap), templates: { suggestion: Handlebars.compile("
{{name}}
{{txt}}{{name}}
{{txt}}