Skip to content

Commit

Permalink
impl. index at UI
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 11, 2024
1 parent 44377a5 commit 4d3cda8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = ");
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/resources/htmlTemplate/dist/feature-pasta.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions core/src/main/resources/htmlTemplate/js/template-feature-pasta.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,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);
};
Expand All @@ -46,7 +46,7 @@ $('#busca').typeahead({
displayKey: 'txt',
name: 'txt',
display: 'txt',
source: substringMatcher(indice),
source: substringMatcher(indexPhrases, indexMap),
templates: {
suggestion: Handlebars.compile("<div><p><strong>{{name}}</strong></p>{{txt}}</div>")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void buildIndex() throws IOException {
}

Assertions.assertThat(sw.toString())
.contains("let indexPhrases = {\"a new func\":1,\"checkpoint\":2,\"f-id\":0};")
.contains("let indexPhrases = {\"0\":\"f-id\",\"1\":\"a new func\",\"2\":\"checkpoint\"};")
.contains("let indexMap = {\"0\":{\"title\":2,\"phrases\":[1]}};");
}
}

0 comments on commit 4d3cda8

Please sign in to comment.