-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
searchResults decoupled from solr client
- Loading branch information
1 parent
6ce2973
commit eb3b5e9
Showing
9 changed files
with
216 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Handles the requests by executing stuff and replying to the client. Uses promises to get stuff done. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const boom = require('boom'), //Boom gives us some predefined http codes and proper responses | ||
suggestions = require('../solr/suggestions'); | ||
|
||
module.exports = { | ||
|
||
// Suggest users for autosuggest functionality or INTERNAL_SERVER_ERROR | ||
findUsers: function(request, reply){ | ||
suggestions.findUsers(request.params.q).then( (results) => { | ||
reply(results); | ||
}).catch( (error) => { | ||
request.log('suggestions.findUsers', error); | ||
reply(boom.badImplementation()); | ||
}); | ||
|
||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const solrClient = require('./solrClient'), | ||
helper = require('./helper'); | ||
|
||
|
||
module.exports = { | ||
|
||
get: function (params) { | ||
let promise = new Promise( (resolve, reject) => { | ||
|
||
let solr_params = helper.getSolrParameters(params); | ||
|
||
let queryString = ''; | ||
|
||
let rootQ = ''; | ||
// query only child docs | ||
if(params.hasOwnProperty('fields')){ | ||
rootQ = (solr_params.rootQ !== '') ? solr_params.rootQ + ' AND ' : ''; | ||
} | ||
// query both parent and child docs | ||
else{ | ||
rootQ = '(' + solr_params.childQ +' AND (kind:slide OR kind:deck)) OR '; | ||
} | ||
|
||
let childQAndFQ = solr_params.childQ; | ||
childQAndFQ += (solr_params.childFQ !== '') ? (' AND ' + solr_params.childFQ) : ''; | ||
|
||
queryString = | ||
'q=' + rootQ + '{!join from=solr_parent_id to=solr_id score=max v=\'' + childQAndFQ + '\'}' + | ||
'&fq=' + solr_params.rootFQ + | ||
'&fl=*,revisions:[subquery]' + | ||
'&revisions.q=' + solr_params.childQ + ' AND {!terms f=solr_parent_id v=$row.solr_id}' + | ||
'&revisions.fq=' + solr_params.childFQ + | ||
// '&revisions.sort=id asc' + | ||
'&rows=50&wt=json'; | ||
|
||
|
||
// let requestUri = 'http://' + solrUri + queryString; | ||
solrClient.query(queryString).then( (resp) => { | ||
this.checkResponse(resp).then( (res) => { | ||
|
||
for(let i in res){ | ||
resp.docs[res[i].item].revisions = res[i]; | ||
} | ||
resolve(resp); | ||
}).catch( (error) => { | ||
reject('in checkResponse. solrResponse: ' + solrResponse); | ||
}); | ||
}).catch( (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
return promise; | ||
}, | ||
checkResponse: function(response){ | ||
let promises = []; | ||
|
||
for (let i in response.docs){ | ||
let curDoc = response.docs[i]; | ||
|
||
// if results has no children | ||
if(curDoc.revisions.numFound === 0){ | ||
|
||
// fetch active child | ||
let query = 'q=solr_parent_id:' + curDoc.solr_id + ' AND active:true'; | ||
promises.push(solrClient.query(query, i)); | ||
} | ||
} | ||
return Promise.all(promises); | ||
}, | ||
}; |
Oops, something went wrong.