diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3435dc5899106583cb685dd89b284136f74a9e..0548368dfe3d7ac7353c76e1d52b9caa8aa3582e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* The "google query" now splits the given string at the spaces and creates an + AND query (e.g., `john gibson` will result in `FIND ENTITY WHICH HAS A + PROPERTY LIKE '*john*' AND A PROPERTY LIKE '*gibson*'`, not in `FIND ENTITY + WHICH HAS A PROPERTY LIKE '*john gibson*'` as before). + ### Deprecated ### Removed diff --git a/src/core/js/webcaosdb.js b/src/core/js/webcaosdb.js index 6d8971c044af8231dddb6c9d8f9b823262120ca9..5d8ea6599316c1f202bf49a611df748cf29d014b 100644 --- a/src/core/js/webcaosdb.js +++ b/src/core/js/webcaosdb.js @@ -1410,7 +1410,11 @@ var queryForm = new function () { return; } if (!(value.startsWith("FIND") || value.startsWith("COUNT") || value.startsWith("SELECT"))) { - queryField.value = "FIND ENTITY WHICH HAS A PROPERTY LIKE '*" + queryField.value + "*'"; + // split words in query field at space and create query fragments + var words = queryField.value.split(" ").map(word => `A PROPERTY LIKE '*${word}*'`); + var query_string = "FIND ENTITY WHICH HAS "; + // send a query that combines all fragments with an AND + queryField.value = query_string + words.join(" AND "); } setter(queryField.value); @@ -1965,9 +1969,11 @@ function initOnDocumentReady() { if ("${BUILD_MODULE_SHOW_ID_IN_LABEL}" == "ENABLED") { // Remove the "display: none;" rule from the caosdb-label-id class [...document.styleSheets] - .map(s => {return [...s.cssRules].find(x=> x.selectorText=='.caosdb-label-id')}) + .map(s => { + return [...s.cssRules].find(x => x.selectorText == '.caosdb-label-id') + }) .filter(Boolean) - .forEach( rule => rule.style.removeProperty("display")); + .forEach(rule => rule.style.removeProperty("display")); } } diff --git a/test/core/js/modules/webcaosdb.js.js b/test/core/js/modules/webcaosdb.js.js index 5f45c32adb9d171c5d362467d0bba0840f02836f..1c456847e1dfda20eb3a4dd70b7b3bcd37086d08 100644 --- a/test/core/js/modules/webcaosdb.js.js +++ b/test/core/js/modules/webcaosdb.js.js @@ -1160,7 +1160,7 @@ QUnit.test("restoreLastQuery", function (assert) { QUnit.test("bindOnClick", function (assert) { assert.ok(queryForm.bindOnClick, "available"); - var done = assert.async(2); + var done = assert.async(3); queryForm.redirect = function (a, b) { done(); }; @@ -1191,19 +1191,29 @@ QUnit.test("bindOnClick", function (assert) { assert.equal(storage(), undefined, "after1: storage still empty."); - // test the click handler of the button - form.query.value = "free text"; + // test the click handler of the button, first without spaces ... + form.query.value = "freetext"; assert.equal(storage(), undefined, "before2: storage empty."); form.getElementsByClassName("caosdb-search-btn")[0].onclick(); - assert.equal(storage(), "FIND ENTITY WHICH HAS A PROPERTY LIKE '*free text*'", "after2: storage not empty."); + assert.equal(storage(), "FIND ENTITY WHICH HAS A PROPERTY LIKE '*freetext*'", "after2: storage not empty."); // test the form submit handler analogously - form.query.value = "free text 2"; + form.query.value = "freetext2"; + $("body").append(form); + $(form).append(submitButton); + submitButton.click(); + assert.equal(storage(), "FIND ENTITY WHICH HAS A PROPERTY LIKE '*freetext2*'", "after3: storage not empty."); + + $(form).remove(); + + // ... then with spaces + form.query.value = "free text 3"; $("body").append(form); $(form).append(submitButton); submitButton.click(); - assert.equal(storage(), "FIND ENTITY WHICH HAS A PROPERTY LIKE '*free text 2*'", "after3: storage not empty."); + assert.equal(storage(), "FIND ENTITY WHICH HAS A PROPERTY LIKE '*free*' AND A PROPERTY LIKE '*text*' AND A PROPERTY LIKE '*3*'", "after4: storage not empty."); + $(form).remove(); })