Fixed project search
The project ID wasn't used at all when searching in a project's context.
This commit is contained in:
parent
257793dcd5
commit
df6297d40f
@ -55,7 +55,7 @@ def nested_bool(must: list, should: list, terms: dict, *, index_alias: str) -> S
|
||||
return search
|
||||
|
||||
|
||||
def do_node_search(query: str, terms: dict, page: int) -> dict:
|
||||
def do_node_search(query: str, terms: dict, page: int, project_id: str='') -> dict:
|
||||
"""
|
||||
Given user query input and term refinements
|
||||
search for public published nodes
|
||||
@ -73,6 +73,8 @@ def do_node_search(query: str, terms: dict, page: int) -> dict:
|
||||
]
|
||||
|
||||
must = []
|
||||
if project_id:
|
||||
must.append({'term': {'project.id': project_id}})
|
||||
|
||||
if not query:
|
||||
should = []
|
||||
|
@ -42,10 +42,11 @@ def _page_index() -> int:
|
||||
@blueprint_search.route('/')
|
||||
def search_nodes():
|
||||
searchword = request.args.get('q', '')
|
||||
project_id = request.args.get('project', '')
|
||||
terms = _term_filters()
|
||||
page_idx = _page_index()
|
||||
|
||||
result = queries.do_node_search(searchword, terms, page_idx)
|
||||
result = queries.do_node_search(searchword, terms, page_idx, project_id)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
@ -17,26 +17,28 @@ $(document).ready(function() {
|
||||
var sliderTemplate = Hogan.compile($('#slider-template').text());
|
||||
var paginationTemplate = Hogan.compile($('#pagination-template').text());
|
||||
|
||||
// something elasticy!
|
||||
// defined in tutti/4_search.js
|
||||
var search = elasticSearcher;
|
||||
|
||||
// what are we looking for? users? assets (default)
|
||||
what = $inputField.attr('what');
|
||||
|
||||
// Input binding
|
||||
$inputField.on('keyup change', function() {
|
||||
var query = $inputField.val();
|
||||
|
||||
function do_search(query) {
|
||||
if (query === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
toggleIconEmptyInput(!query.trim());
|
||||
|
||||
// what could be like "/users"
|
||||
search.setQuery(query, what);
|
||||
// setURLParams(search);
|
||||
search.setQuery(query, what); // what could be like "/users"
|
||||
var pid = ProjectUtils.projectId();
|
||||
if (pid) search.setProjectID(pid);
|
||||
search.execute();
|
||||
}
|
||||
|
||||
// Input binding
|
||||
$inputField.on('keyup change', function() {
|
||||
var query = $inputField.val();
|
||||
do_search(query);
|
||||
}).focus();
|
||||
|
||||
search.on('results', function(content) {
|
||||
@ -330,6 +332,5 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
// do empty search to fill aggregations
|
||||
search.setQuery('', what);
|
||||
search.execute();
|
||||
do_search('');
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ var elasticSearcher = (function() {
|
||||
var deze = {
|
||||
|
||||
query:"",
|
||||
project_id:"",
|
||||
url:"",
|
||||
newhits: [],
|
||||
terms: {},
|
||||
@ -21,6 +22,10 @@ var elasticSearcher = (function() {
|
||||
}
|
||||
}),
|
||||
|
||||
setProjectID: (function(pid){
|
||||
deze.project_id = pid;
|
||||
}),
|
||||
|
||||
setCurrentPage: (function(page){
|
||||
if(page === undefined){
|
||||
return;
|
||||
@ -66,6 +71,7 @@ var elasticSearcher = (function() {
|
||||
params = {
|
||||
q: deze.query,
|
||||
page: deze.page,
|
||||
project: deze.project_id,
|
||||
};
|
||||
//add term filters
|
||||
Object.assign(params, deze.terms);
|
||||
@ -105,6 +111,7 @@ var elasticSearcher = (function() {
|
||||
execute: deze.execute,
|
||||
on: deze.on,
|
||||
setQuery: deze.setQuery,
|
||||
setProjectID: deze.setProjectID,
|
||||
setCurrentPage: deze.setCurrentPage,
|
||||
query: deze.query,
|
||||
page: deze.page,
|
||||
|
@ -23,6 +23,10 @@ meta(name="twitter:description", content="{{project.summary}}")
|
||||
| {% endblock %}
|
||||
|
||||
| {% block body %}
|
||||
| {% if project %}
|
||||
script.
|
||||
document.body.dataset["projectId"] = "{{project._id}}";
|
||||
| {% endif %}
|
||||
|
||||
#search-container
|
||||
|
||||
@ -171,27 +175,11 @@ script(type="text/template", id="stats-template")
|
||||
|
||||
| {% block footer_scripts %}
|
||||
script(src="//releases.flowplayer.org/6.0.5/flowplayer.min.js", async)
|
||||
script().
|
||||
var APPLICATION_ID = '{{config.ALGOLIA_USER}}';
|
||||
var SEARCH_ONLY_API_KEY = '{{config.ALGOLIA_PUBLIC_KEY}}';
|
||||
var INDEX_NAME = '{{config.ALGOLIA_INDEX_NODES}}';
|
||||
var sortByCountDesc = null;
|
||||
var FACET_CONFIG = [
|
||||
{ name: 'node_type', title: 'Type', disjunctive: false, sortFunction: sortByCountDesc },
|
||||
{ name: 'media', title: 'Media', disjunctive: false, sortFunction: sortByCountDesc },
|
||||
{ name: 'tags', title: 'Tags', disjunctive: false, sortFunction: sortByCountDesc },
|
||||
{ name: 'is_free', title: 'Free Access', disjunctive: false, sortFunction: sortByCountDesc },
|
||||
];
|
||||
{% if project %}
|
||||
FACET_CONFIG.push({ name: 'project._id', title: 'Project', disjunctive: false, hidden: true, value: '{{project._id}}' })
|
||||
{% endif %}
|
||||
|
||||
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/hogan.common-3.0.0.js') }}")
|
||||
script(src="{{ url_for('static_pillar', filename='assets/js/elasticsearch.min.js') }}")
|
||||
|
||||
script(type="text/javascript").
|
||||
|
||||
function displayUser(userId) {
|
||||
script.
|
||||
function displayNode(userId) {
|
||||
var url = '/nodes/' + userId + '/view';
|
||||
|
||||
$.get(url, function(dataHtml){
|
||||
@ -215,7 +203,7 @@ script(type="text/javascript").
|
||||
}
|
||||
$(this).find('#search-loading').addClass('active');
|
||||
|
||||
displayUser($(this).data('hit-id'));
|
||||
displayNode($(this).data('hit-id'));
|
||||
$('.search-hit').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user