Skip to content

Commit

Permalink
jmvanel#163 - Enhance autocompete with QueryClass
Browse files Browse the repository at this point in the history
  • Loading branch information
ModuloM committed May 30, 2017
1 parent 21fe7cc commit 267c728
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 10 additions & 4 deletions scala/forms_play/public/javascripts/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ $(document).ready(function() {
},
source: function(request, callback) {
console.log("Déclenche l'événement :")
console.log($(event.target));
console.log(event.target.value);
console.log(event.target.title);
var typeName
var $el = $(event.target);
if ($el) {
var type = $el.attr('data-rdf-type').split('/');
if (type) {
typeName = type[type.length - 1];
}
}

$.ajax({
url: "/lookup",
data: { QueryClass: event.target.title, QueryString: request.term + "*" },
data: { QueryClass: typeName, QueryString: request.term + "*" },
dataType: "json",
timeout: 5000
}).done(function(response) {
Expand Down
15 changes: 11 additions & 4 deletions scala/forms_play/public/javascripts/wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ $(document).ready(function() {
},
source: function(request, callback) {
console.log("Déclenche l'événement :")
console.log($(event.target));
console.log(event.target.value);

// TODO add QueryClass
// compare results: QueryClass=person , and ?QueryClass=place
Expand All @@ -64,9 +62,18 @@ $(document).ready(function() {

// QueryClass comes from attribute data-rdf-type in <input> tag , but data-rdf-type is a full URI !

var typeName
var $el = $(event.target);
if ($el) {
var type = $el.attr('data-rdf-type').split('/');
if (type) {
typeName = type[type.length - 1];
}
}

$.ajax({
url: "http://lookup.dbpedia.org/api/search/PrefixSearch",
data: { MaxHits: resultsCount, QueryString: request.term },
data: { MaxHits: resultsCount, QueryClass: typeName, QueryString: request.term },
dataType: "json",
timeout: 5000
}).done(function (response) {
Expand All @@ -79,7 +86,7 @@ $(document).ready(function() {
}).fail(function (error){
$.ajax({
url: "/lookup",
data: { MaxHits: resultsCount, QueryString: request.term + "*" },
data: { MaxHits: resultsCount, QueryClass: typeName, QueryString: request.term + "*" },
dataType: "json",
timeout: 5000
}).done(function(response) {
Expand Down

0 comments on commit 267c728

Please sign in to comment.