T53161 project user search now also elastic
This commit is contained in:
parent
d355e58f2f
commit
8b789d408e
@ -3,11 +3,25 @@
|
|||||||
* index and algolia settings are defined in layout.pug
|
* index and algolia settings are defined in layout.pug
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function() {
|
var elasticSearch = (function($, url) {
|
||||||
|
console.log(url);
|
||||||
|
return function findMatches(q, cb, async){
|
||||||
|
if (!cb) { return; }
|
||||||
|
$.fn.getSearch(q, cb, async, url);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
(function( $ ){
|
||||||
|
|
||||||
|
$.fn.getSearch = function(q, cb, async, url){
|
||||||
|
|
||||||
var getSearch = function(q, cb, async){
|
|
||||||
let newhits = [];
|
let newhits = [];
|
||||||
$.getJSON("/api/newsearch?q=" + q, function( data ) {
|
if(url === undefined){
|
||||||
|
url = '';
|
||||||
|
}
|
||||||
|
console.log('searching! '+ url + q);
|
||||||
|
$.getJSON("/api/newsearch" + url + "?q=" + q, function( data ) {
|
||||||
let hits = data.hits.hits;
|
let hits = data.hits.hits;
|
||||||
newhits = hits.map(function(hit){
|
newhits = hits.map(function(hit){
|
||||||
return hit._source;
|
return hit._source;
|
||||||
@ -17,19 +31,17 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var elasticSearch = (function() {
|
|
||||||
|
|
||||||
return function findMatches(q, cb, async){
|
}(jQuery));
|
||||||
if (!cb) { return; }
|
|
||||||
getSearch(q, cb, async);
|
|
||||||
};
|
$(document).ready(function() {
|
||||||
});
|
|
||||||
|
|
||||||
var searchInput = $('#cloud-search');
|
var searchInput = $('#cloud-search');
|
||||||
|
|
||||||
var tu = searchInput.typeahead({hint: true}, {
|
var tu = searchInput.typeahead({hint: true}, {
|
||||||
//source: algoliaIndex.ttAdapter(),
|
//source: algoliaIndex.ttAdapter(),
|
||||||
source: elasticSearch(),
|
source: elasticSearch($),
|
||||||
async: true,
|
async: true,
|
||||||
displayKey: 'name',
|
displayKey: 'name',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
(function ( $ ) {
|
(function ( $ ) {
|
||||||
// See organizations/view_embed.pug for example use.
|
// See organizations/view_embed.pug for example use.
|
||||||
$.fn.userSearch = function(algolia_application_id, algolia_public_key, algolia_index_users, on_selected) {
|
$.fn.userSearch = function(algolia_application_id, algolia_public_key, algolia_index_users, on_selected) {
|
||||||
var client = algoliasearch(algolia_application_id, algolia_public_key);
|
|
||||||
var index = client.initIndex(algolia_index_users);
|
|
||||||
|
|
||||||
var target = this;
|
var target = this;
|
||||||
this.autocomplete({hint: false}, [
|
this.autocomplete({hint: false}, [
|
||||||
{
|
{
|
||||||
source: function (q, cb) {
|
source: elasticSearch($, '/user'),
|
||||||
index.search(q, {hitsPerPage: 5}, function (error, content) {
|
|
||||||
if (error) {
|
|
||||||
cb([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cb(content.hits, content);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
displayKey: 'full_name',
|
displayKey: 'full_name',
|
||||||
minLength: 2,
|
async: true,
|
||||||
|
minLength: 1,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
templates: {
|
templates: {
|
||||||
suggestion: function (hit) {
|
suggestion: function (hit) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user