I am trying to implement a VisualSearch.js Query box that can be used to search the attributes of particular objects. VisualSearch.js provides Facets that can have categories but does any one know of a way that I can load a facet for the model name .e.g ‘user’) then once clicked/selected load a second sub facet with a list of attributes before then giving the user a chance to finally click on the values which will be load via a JSON call. I have searched and cannot find any reference to this sort of functionality but I may just be using the incorrect term “Sub Facet”.
Here is a JSFiddle I have been playing with. http://jsfiddle.net/Savvy84/HRuAP/13/
var visualSearch = VS.init({
container: $('#visual_search'),
query: '',
callbacks: {
search: function(query, searchCollection) {},
facetMatches: function(callback) {
callback([
{
value: 'user.email',
label: 'users.email',
category: 'Users'},
{
value: 'job.name',
label: 'job.name',
category: 'Jobs'},
{
value: 'job.startDate',
label: 'job.startDate',
category: 'Jobs'}
]);
},
valueMatches: function(facet, searchTerm, callback) {
if (searchTerm.length > 0) {
//pass the facet to the search and let the server deal with it.
switch (facet) {
case 'user.email':
callback([
{
label: 'john.smith@example.com'},
{
label: 'jane.doe@example.com'}
]);
break;
}
}
}
} });
Many Thanks.
After reading through the source code I can see that to create this functionality I will have to fork VisualSearch.js and edit some of its classes.
http://documentcloud.github.com/visualsearch/docs/search_facet.html