|
| 1 | +/* global instantsearch */ |
| 2 | + |
| 3 | +var search = instantsearch({ |
| 4 | + appId: '3IMV4A54L6', |
| 5 | + apiKey: '14764fe83aec89f7335d3f2c85b21774', |
| 6 | + indexName: 'open_data_v3', |
| 7 | + urlSync: {} |
| 8 | +}); |
| 9 | + |
| 10 | +search.addWidget( |
| 11 | + instantsearch.widgets.searchBox({ |
| 12 | + container: '#q' |
| 13 | + }) |
| 14 | +); |
| 15 | + |
| 16 | +search.addWidget( |
| 17 | + instantsearch.widgets.stats({ |
| 18 | + container: '#stats' |
| 19 | + }) |
| 20 | +); |
| 21 | + |
| 22 | +var hitTemplate = |
| 23 | + '<div class="hit media">' + |
| 24 | + '<div class="media-body">' + |
| 25 | + '<a href="{{Url}}"><h4 class="media-heading">{{{_highlightResult.Name.value}}}</h4></a>' + |
| 26 | + '<p class="description">{{{_highlightResult.Description.value}}}</p>'+ |
| 27 | + '<p class="genre">'+ |
| 28 | + '<span class="badge">by: {{{_highlightResult.Host.value}}}</span> '+ |
| 29 | + '<span class="badge">{{{_highlightResult.Format.value}}}</span> '+ |
| 30 | + '<span class="badge">{{{_highlightResult.Domain.value}}}</span> '+ |
| 31 | + '</p>' + |
| 32 | + '</div>' + |
| 33 | + '</div>'; |
| 34 | + |
| 35 | +var noResultsTemplate = |
| 36 | + '<div class="text-center">No results found matching <strong>{{query}}</strong>.</div>'; |
| 37 | + |
| 38 | +search.addWidget( |
| 39 | + instantsearch.widgets.hits({ |
| 40 | + container: '#hits', |
| 41 | + hitsPerPage: 10, |
| 42 | + templates: { |
| 43 | + empty: noResultsTemplate, |
| 44 | + item: hitTemplate |
| 45 | + } |
| 46 | + |
| 47 | + }) |
| 48 | +); |
| 49 | + |
| 50 | +search.addWidget( |
| 51 | + instantsearch.widgets.pagination({ |
| 52 | + container: '#pagination', |
| 53 | + cssClasses: { |
| 54 | + root: 'pagination', |
| 55 | + active: 'active' |
| 56 | + } |
| 57 | + }) |
| 58 | +); |
| 59 | + |
| 60 | +search.addWidget( |
| 61 | + instantsearch.widgets.rangeSlider({ |
| 62 | + container: '#sizemb', |
| 63 | + attributeName: 'Size', |
| 64 | + min: 0, |
| 65 | + max: 100000, |
| 66 | + step: 1000, |
| 67 | + pips: false, |
| 68 | + tooltips: {format: function(rawValue) {return parseInt(rawValue)}}, |
| 69 | + cssClasses: { |
| 70 | + body: 'nav-narrow' |
| 71 | + } |
| 72 | + }) |
| 73 | +); |
| 74 | + |
| 75 | +search.addWidget( |
| 76 | + instantsearch.widgets.refinementList({ |
| 77 | + container: '#organizations', |
| 78 | + attributeName: 'Host', |
| 79 | + limit: 5, |
| 80 | + showMore: true, |
| 81 | + cssClasses: { |
| 82 | + list: 'nav nav-list', |
| 83 | + count: 'badge pull-right', |
| 84 | + active: 'active' |
| 85 | + } |
| 86 | + }) |
| 87 | +); |
| 88 | + |
| 89 | +search.addWidget( |
| 90 | + instantsearch.widgets.refinementList({ |
| 91 | + container: '#formats', |
| 92 | + attributeName: 'Format', |
| 93 | + limit: 5, |
| 94 | + showMore: true, |
| 95 | + cssClasses: { |
| 96 | + list: 'nav nav-list', |
| 97 | + count: 'badge pull-right', |
| 98 | + active: 'active' |
| 99 | + } |
| 100 | + }) |
| 101 | +); |
| 102 | + |
| 103 | +search.addWidget( |
| 104 | + instantsearch.widgets.refinementList({ |
| 105 | + container: '#domains', |
| 106 | + attributeName: 'Domain', |
| 107 | + limit: 5, |
| 108 | + showMore: true, |
| 109 | + cssClasses: { |
| 110 | + list: 'nav nav-list', |
| 111 | + count: 'badge pull-right', |
| 112 | + active: 'active' |
| 113 | + } |
| 114 | + }) |
| 115 | +); |
| 116 | + |
| 117 | +search.start(); |
0 commit comments