Skip to content

Commit

Permalink
For mapr 'Cell Line' option, front page uses searchengine for auto-co…
Browse files Browse the repository at this point in the history
…mplete
  • Loading branch information
will-moore committed Oct 4, 2023
1 parent d75934a commit 1918139
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 19 additions & 6 deletions idr_gallery/static/idr_gallery/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,23 @@ function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}

function autoCompleteDisplayResults(queryVal, data) {
function autoCompleteDisplayResults(queryVal, data, filterImageKeys) {
// For showing the searchengine results in a panel
// filterImageKey is used if we want mapr-like behaviour showing results from a single Key
let queryRegex = new RegExp(escapeRegExp(queryVal), "ig"); // ignore-case, global

// Search-engine results...
let results = [...data.data];

// Also show 'instant' filtering of studies
// Also show 'instant' filtering of studies (if we're not filtering images)
// If there are no search-engine Image results, we highlight first Study
const highlightStudy = results.length === 0;
let studiesHtml = getMatchingStudiesHtml(queryVal, highlightStudy);
let studiesHtml = ""
if (!filterImageKeys) {
getMatchingStudiesHtml(queryVal, highlightStudy);
} else {
results = results.filter(res => filterImageKeys.includes(res.Key));
}

results.sort(autocompleteSort(queryVal));
let imagesHtml = results
Expand Down Expand Up @@ -163,6 +169,8 @@ $("#maprQuery")
source: function (request, response) {
// if configId is not from mapr, we filter on mapValues...
let configId = document.getElementById("maprConfig").value;
// we only need mapr allKeys if we're filtering searchengine results by mapr keys
let allKeys = document.querySelector('#maprConfig option:checked').dataset.allkeys;
// Don't handle empty queries
if (request.term.trim().length == 0) {
response();
Expand Down Expand Up @@ -191,7 +199,8 @@ $("#maprQuery")
case_sensitive: case_sensitive,
};
let url;
if (configId === "any") {
// NB: Don't use mapr for some slow queries
if (configId === "any" || configId === "cellline") {
// Use searchengine...
url = `${SEARCH_ENGINE_URL}resources/image/searchvalues/`;
requestData = { value: request.term };
Expand All @@ -214,8 +223,12 @@ $("#maprQuery")
let queryVal = $("#maprQuery").val().trim();
let results = [];
// check that input hasn't changed during the call
if (configId === "any" && request.term.trim() == queryVal) {
autoCompleteDisplayResults(queryVal, data);
if ((configId === "any" || configId === "cellline") && request.term.trim() == queryVal) {
let filterImageKeys;
if (allKeys) {
filterImageKeys = allKeys.split(",");
}
autoCompleteDisplayResults(queryVal, data, filterImageKeys);
} else {
results = data;
}
Expand Down
3 changes: 2 additions & 1 deletion idr_gallery/static/idr_gallery/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ async function init() {

let options = FILTER_MAPR_KEYS.map((key) => {
let config = mapr_settings[key];
let allKeys = config.all.join(",");
if (config) {
return `<option value="mapr_${key}">${config.label}</option>`;
return `<option value="mapr_${key}" data-allkeys="${allKeys}">${config.label}</option>`;
} else {
return "";
}
Expand Down

0 comments on commit 1918139

Please sign in to comment.