Skip to content

Commit

Permalink
Optionally set fields in query_string search
Browse files Browse the repository at this point in the history
  • Loading branch information
gneissone committed May 12, 2016
1 parent b5934a8 commit 1c3b97a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion es.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ function optionsFromQuery(query) {
if (qs.query_string) {
var string = unescapeQueryString(qs.query_string.query);
var field = qs.query_string.default_field;
var multi_field = qs.query_string.fields;
var op = qs.query_string.default_operator;
if (string) { opts["q"] = string }
if (field) { opts["searchfield"] = field }
if (multi_field) { opts["fields"] = multi_field }
if (op) { opts["default_operator"] = op }
} else if (qs.match_all) {
opts["q"] = ""
Expand Down Expand Up @@ -281,12 +283,17 @@ function elasticSearchQuery(params) {
var querystring = options.q;
var searchfield = options.searchfield;
var default_operator = options.default_operator;
var search_fields_multi = options.search_fields_multi;

var ftq = undefined;
if (querystring) {
ftq = {'query_string' : { 'query': fuzzify(querystring, options.default_freetext_fuzzify) }};
if (searchfield) {
ftq.query_string["default_field"] = searchfield
}
else if (search_fields_multi) {
ftq.query_string["fields"] = search_fields_multi
}
if (default_operator) {
ftq.query_string["default_operator"] = default_operator
}
Expand Down Expand Up @@ -520,4 +527,3 @@ function doElasticSearchQuery(params) {
complete: complete_callback
});
}

6 changes: 6 additions & 0 deletions jquery.facetview2.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ function getUrlVars() {
// field on which to focus the freetext search
"searchfield" : "", // e.g. title.exact

// fields to search on the freetext search
// NOTE ignored if searchfield is set.
// functionally, searchfield sets 'default_field' in the elasticsearch query
// while search_fields_multi sets 'fields'
"search_fields_multi" : "", // e.g. ["*folded","_all"]

// freetext search string
"q" : "",

Expand Down

0 comments on commit 1c3b97a

Please sign in to comment.