Commit 5ead24b6 authored by Daniel Witek's avatar Daniel Witek

added basic name search

parent 5cd01f67
......@@ -6,14 +6,22 @@
</head>
<body>
<section class="search">
<form action="">
<input id="input" autocomplete="off" /><button>Send</button>
<form class="searchForm" action="">
<input id="input" name="q" type="text" />
<button id="searchButton" type="submit" class="button">Send</button>
</form>
</section>
<section class="results">
<section id="results">
</section>
<script src="bundle.js"></script>
</body>
</html>
\ No newline at end of file
</html>
This diff is collapsed.
This diff is collapsed.
const solr = require('solr-client');
const $ = require('jquery');
// const $ = require('jquery');
const client = solr.createClient('127.0.0.1', '8983', 'gettingstarted', '/solr');
$('form').submit(function(){
sendQuery($('#input').val())
return false
})
// const startQuery = `q=id:3`;
function sendQuery(q){
var query = "q=poke_txt_en:" + q
// // DixMax query
// var query = client.createQuery()
// .q('laptop')
// .dismax()
// .qf({title_t : 0.2 , description_t : 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);
const request = client.search(query, function (error, result) {
console.log(error);
console.log(result);
})
}
let searchButton = document.getElementById('searchButton')
searchButton.addEventListener("click", search, false)
function search(e) {
e.preventDefault();
const searchValue = document.getElementById('input').value
// console.log(searchValue);
sendQuery(searchValue);
}
// $('searchForm').submit(function(){
//
// console.log(searchValue);
// console.log($('#input').val());
// sendQuery($('#input').val())
// console.log($('#input').val());
// // return false
// })
function sendQuery(q){
var query = "q=poke_txt_en:" + q +"&rows=100"
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"
}
for(var i = 0; i < results.length; i++){
let item = document.createElement("li")
const startquery = `q=name_txt_en:Bulbasaur`;
item.innerHTML = "<strong>" + results[i].poke_txt_en + "</strong>"
document.getElementById('results').appendChild(item)
const request = client.search(startquery, function (error, result) {
console.log(result);
})
}
// let countResult = obj.numFound;
// console.log(countResult)
// const Count = countResult[1]
// document.getElementById('results').innerHTML = Count;
console.log(obj);
}
});
}
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