Commit ffc596d7 authored by Daniel Witek's avatar Daniel Witek

clear suggestions

parent 8194e22a
......@@ -44,6 +44,7 @@ function search(e) {
function clearList() {
document.getElementById("results").innerHTML = ""
document.getElementById("suggestions").innerHTML = ""
}
// $('searchForm').submit(function(){
......
const solr = require('solr-client');
const $ = require('jquery');
const client = solr.createClient('127.0.0.1', '8983', 'gettingstarted', '/solr');
// const startQuery = `q=id:3`;
// // DisMax query
// var query = client.createQuery()
// .q('water')
// .dismax()
// .qf({poke_txt_en : 0.2 , about_txt_en : 3.3})
// .mm(2)
// .start(0)
// .rows(10);
// client.search(query,function(err,obj){
// if(err){
// console.log(err);
// }else{
// console.log(obj);
// }
// });
// Lucene query
// var query2 = client.createQuery()
// .q({poke_txt_en : 'bulbasaur'})
// .start(0)
// .rows(10);
let filter
$("select").change(function(){
filter=$("select").val()
});
let searchButton = document.getElementById('searchButton')
searchButton.addEventListener("click", search, false)
function search(e) {
e.preventDefault();
const searchValue = document.getElementById('input').value
console.log(searchValue);
clearList();
sendNameQuery(searchValue);
sendSpellcheck(searchValue);
}
function clearList() {
document.getElementById("results").innerHTML = ""
}
// $('searchForm').submit(function(){
//
// console.log(searchValue);
// console.log($('#input').val());
// sendQuery($('#input').val())
// console.log($('#input').val());
// // return false
// })
function sendNameQuery(q){
if(q.length==0){
document.getElementById("results").innerHTML = "Bitte gib' einen Suchbegriff ein!"
}else{
//var query = "q=about_txt_en:("+ q +")&rows=100" //rows ist nötig, sonst nur 10 results
var query = client.createQuery()
.q(q)
.dismax()
.qf({poke_txt_en : 0.2 , about_txt_en : 3.3})
.start(0)
.rows(10)
if(filter)
query.matchFilter('types_features_str', filter)
// console.log(query);
client.search(query,function(err,obj){
if(err){
console.log(err);
}else{
results = obj.response.docs
if (results.length == 0) {
document.getElementById("results").innerHTML = "No results"
}
else{
obj.response.docs.forEach(function(entry){
let item = document.createElement("p")
item.innerHTML =
"<li>Id: <strong>" + entry.id + "</strong></li>" +
"<li>Name: <strong>" + entry.poke_txt_en + "</strong></li>" +
"<li>Description: " + entry.about_txt_en + "</li>" +
"<li>Gen: " + entry.gen_txt_en + "</li>" +
"<li>MaxHP: " + entry.maxHP_txt_en + "</li>" +
"<li>MaxCP: " + entry.maxCP_txt_en + "</li>" +
"<li>Types:</li>" +
`<ul id='${entry.id}'></ul>`;
document.getElementById('results').appendChild(item)
entry.types_features.forEach(function(type){
let item3 = document.createElement("li")
item3.innerHTML = type;
document.getElementById(entry.id).appendChild(item3)
})
// console.log(entry);
})
}
}
});
}
}
function sendSpellcheck(spell){
var spell = client.createQuery()
.dismax()
.qf({poke_txt_en : 0.2 , about_txt_en : 3.3})
.start(0)
.rows(10)
.set(`spellcheck=on`)
.set(`spellcheck.q=`+spell)
if(filter)
query.matchFilter('types_features_str', filter)
client.spell(spell,function(err,obj){
if(err){
console.log(err);
}else{
suggest = obj.spellcheck.collations
// console.log(suggest[1].collationQuery)
// console.log(suggest.length)
for (var i = 1; i < suggest.length; i++) {
let test= suggest[i].collationQuery
console.log(test)
let word = document.createElement("li")
i++;
word.innerHTML = test;
document.getElementById("suggestions").appendChild(word)
// if ((i+1)<suggest.length) words +=", "
}
}});
}
......@@ -54,4 +54,4 @@ body{
width: 20em;
height: 2em;
margin-top: 1em;
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment