mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Simplify the front page
This commit is contained in:
parent
7be275b692
commit
b0c31500fc
@ -1,11 +1,9 @@
|
|||||||
var request = null;
|
var request = null;
|
||||||
var timeoutID = null;
|
var timeoutID = null;
|
||||||
var selected_facets = {};
|
|
||||||
|
|
||||||
$('#query, #filters').on('input', function () {
|
$('#query, #filters').on('input', function () {
|
||||||
var query = $('#query').val();
|
var query = $('#query').val();
|
||||||
var filters = $('#filters').val();
|
var filters = $('#filters').val();
|
||||||
var facet_filters = selectedFacetsToArray(selected_facets);
|
|
||||||
var timeoutMs = 100;
|
var timeoutMs = 100;
|
||||||
|
|
||||||
if (timeoutID !== null) {
|
if (timeoutID !== null) {
|
||||||
@ -20,12 +18,11 @@ $('#query, #filters').on('input', function () {
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
'query': query,
|
'query': query,
|
||||||
'filters': filters,
|
'filters': filters,
|
||||||
'facetFilters': facet_filters,
|
|
||||||
"facetDistribution": true,
|
"facetDistribution": true,
|
||||||
}),
|
}),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
success: function (data, textStatus, request) {
|
success: function (data, textStatus, request) {
|
||||||
documents.innerHTML = '';
|
results.innerHTML = '';
|
||||||
facets.innerHTML = '';
|
facets.innerHTML = '';
|
||||||
|
|
||||||
let timeSpent = request.getResponseHeader('Time-Ms');
|
let timeSpent = request.getResponseHeader('Time-Ms');
|
||||||
@ -35,39 +32,15 @@ $('#query, #filters').on('input', function () {
|
|||||||
time.classList.remove('fade-in-out');
|
time.classList.remove('fade-in-out');
|
||||||
|
|
||||||
for (facet_name in data.facets) {
|
for (facet_name in data.facets) {
|
||||||
// Append an header to the list of facets
|
for (value in data.facets[facet_name]) {
|
||||||
let upperCaseName = facet_name.charAt(0).toUpperCase() + facet_name.slice(1);
|
const elem = document.createElement('span');
|
||||||
$("<h3></h3>").text(upperCaseName).appendTo($('#facets'));
|
const count = data.facets[facet_name][value];
|
||||||
|
elem.classList.add("tag");
|
||||||
// Create a div for a bulma select
|
elem.setAttribute('data-name', facet_name);
|
||||||
const header = document.createElement('div');
|
elem.setAttribute('data-value', value);
|
||||||
let div = $("<div></div>").addClass('select is-multiple');
|
elem.innerHTML = `${facet_name}:${value} (${count})`;
|
||||||
|
facets.appendChild(elem);
|
||||||
// Create the select element
|
|
||||||
let select = $(`<select data-facet-name='${facet_name}' multiple size=\"8\"></select>`);
|
|
||||||
let selected_values = selected_facets[facet_name] || [];
|
|
||||||
// Create the previously selected facets (mark them as selected)
|
|
||||||
for (value of selected_values) {
|
|
||||||
let option = $('<option></option>')
|
|
||||||
.text(value)
|
|
||||||
.attr('selected', "selected")
|
|
||||||
.attr('value', value)
|
|
||||||
.attr('title', value);
|
|
||||||
select.append(option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the newly discovered facets
|
|
||||||
let diff = diffArray(Object.keys(data.facets[facet_name]), selected_values);
|
|
||||||
for (value of diff) {
|
|
||||||
let option = $('<option></option>')
|
|
||||||
.text(value)
|
|
||||||
.attr('value', value)
|
|
||||||
.attr('title', value);
|
|
||||||
select.append(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
div.append(select);
|
|
||||||
$('#facets').append(div);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (element of data.documents) {
|
for (element of data.documents) {
|
||||||
@ -95,15 +68,21 @@ $('#query, #filters').on('input', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elem.appendChild(ol);
|
elem.appendChild(ol);
|
||||||
documents.appendChild(elem);
|
results.appendChild(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we click on a facet value we change the global values
|
// When we click on a tag we append the facet value
|
||||||
// to make sure that we don't loose the selection between requests.
|
// at the end of the facet query.
|
||||||
$('#facets select').on('change', function(e) {
|
$('#facets .tag').on('click', function () {
|
||||||
let facet_name = $(this).attr('data-facet-name');
|
let name = $(this).attr("data-name");
|
||||||
selected_facets[facet_name] = $(this).val();
|
let value = $(this).attr("data-value");
|
||||||
$('#query').trigger('input');
|
|
||||||
|
let facet_query = $('#filters').val().trim();
|
||||||
|
if (facet_query === "") {
|
||||||
|
$('#filters').val(`${name} = "${value}"`).trigger('input');
|
||||||
|
} else {
|
||||||
|
$('#filters').val(`${facet_query} AND ${name} = "${value}"`).trigger('input');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
beforeSend: function () {
|
beforeSend: function () {
|
||||||
|
@ -1,5 +1,24 @@
|
|||||||
#results {
|
#results {
|
||||||
|
max-width: 900px;
|
||||||
margin: 20px auto 0 auto;
|
margin: 20px auto 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#facets .tag {
|
||||||
|
margin-right: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#facets {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 20px auto 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
max-height: 16em;
|
||||||
|
overflow: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
#facets .tag:hover {
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#logo-white {
|
#logo-white {
|
||||||
@ -61,6 +80,14 @@
|
|||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
max-width: 65%;
|
||||||
|
flex: 0 0 65%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding-left: 10px;
|
||||||
|
color: rgba(0,0,0,.9);
|
||||||
|
}
|
||||||
|
|
||||||
.content mark {
|
.content mark {
|
||||||
background-color: hsl(204, 86%, 88%);
|
background-color: hsl(204, 86%, 88%);
|
||||||
color: hsl(204, 86%, 25%);
|
color: hsl(204, 86%, 25%);
|
||||||
|
@ -84,20 +84,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="results" class="container">
|
<section id="facets">
|
||||||
<div class="columns">
|
<!-- facet values -->
|
||||||
<div class="column is-one-fifth">
|
</section>
|
||||||
<div id="facets" class="content">
|
|
||||||
<!-- facets matching requests -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="column is-four-fifths">
|
<section>
|
||||||
<ol id="documents" class="content">
|
<ol id="results" class="content">
|
||||||
<!-- documents matching requests -->
|
<!-- documents matching requests -->
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user