Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for facet filters #24

Merged
merged 3 commits into from Nov 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions jquery.facetview.js
Expand Up @@ -961,8 +961,15 @@ Updates the URL string with the current query when the user changes the
}
}
} else {
var rel = $(this).attr('rel');
var facet = options.facets.filter(function(f) {
return f['field'] === rel && f['facet_filter'];
})[0];
var bobj = {'term':{}};
bobj['term'][ $(this).attr('rel') ] = $(this).attr('href');
bobj['term'][rel] = $(this).attr('href');
if (facet) {
qs['filter'] = facet['facet_filter'];
}
}

// check if this should be a nested query
Expand Down Expand Up @@ -1012,9 +1019,21 @@ Updates the URL string with the current query when the user changes the
qs['facets'] = {};
for ( var item = 0; item < options.facets.length; item++ ) {
var fobj = jQuery.extend(true, {}, options.facets[item] );
var facet_filter = fobj['facet_filter'];
delete fobj['display'];
delete fobj['facet_filter'];
var facet = {'terms': fobj};
if (facet_filter || qs['filter']) {
facet['facet_filter'] = {'and': []};
if (facet_filter) {
facet['facet_filter']['and'].push(facet_filter);
}
if (qs['filter']) {
facet['facet_filter']['and'].push(qs['filter']);
}
}
var parts = fobj['field'].split('.');
qs['facets'][fobj['field']] = {"terms":fobj};
qs['facets'][fobj['field']] = facet;
if ( options.nested.indexOf(parts[0]) != -1 ) {
nested ? qs['facets'][fobj['field']]["scope"] = parts[0] : qs['facets'][fobj['field']]["nested"] = parts[0];
}
Expand Down