瀏覽代碼

fix: lowercased block content in search result

Junyi Du 3 年之前
父節點
當前提交
4775be1baf

+ 6 - 4
e2e-tests/page-refs.spec.ts

@@ -75,7 +75,6 @@ async function alias_test (page, page_name: string){
 
   const results = await page.$$('#ui__ac-inner .block')
   expect(results.length).toEqual(3) // page + block + alias property
-  await page.pause()
 
   // test search results
   expect(await results[0].innerText()).toContain("Alias -> " + target_name)
@@ -86,20 +85,23 @@ async function alias_test (page, page_name: string){
   expect(await results[2].innerText()).toContain("alias:: [[" + alias_name + "]]")
 
   // test search entering (page)
-  await page.keyboard.press("Enter")
+  page.keyboard.press("Enter")
+  await page.waitForNavigation()
   await lastInnerBlock(page)
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(alias_test_content_3)
-  await page.keyboard.press(hotkeyBack)
 
   // test search clicking (block)
   await page.click('#search-button')
   await page.waitForSelector('[placeholder="Search or create page"]')
   await page.fill('[placeholder="Search or create page"]', alias_name)
   await page.waitForTimeout(500)
-  await page.click(":nth-match(.menu-link, 1)")
+  page.click(":nth-match(.menu-link, 2)")
+  await page.waitForNavigation()
   await lastInnerBlock(page)
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe("[[" + alias_name + "]]")
   await page.keyboard.press(hotkeyBack)
+
+  // TODO: search clicking (alias property)
 }
 
 test('page alias', async ({ page }) => {

+ 2 - 2
src/main/frontend/components/search.cljs

@@ -43,8 +43,8 @@
                                 result []]
                            (if (and (seq words) content)
                              (let [word (first words)
-                                   lc-word (string/lower-case word)
-                                   lc-content (string/lower-case content)]
+                                   lc-word (util/search-normalize word)
+                                   lc-content (util/search-normalize content)]
                                (if-let [i (string/index-of lc-content lc-word)]
                                  (recur (rest words)
                                         (subs content (+ i (count word)))

+ 2 - 1
src/main/frontend/search/db.cljs

@@ -17,11 +17,12 @@
   (nil? (get @indices repo)))
 
 (defn block->index
+  "Convert a block to the contents for searching (will be displayed in the search results)"
   [{:block/keys [uuid content format page] :as block}]
   (when-let [result (->> (text/remove-level-spaces content format)
                          (drawer/remove-logbook)
                          (property/remove-built-in-properties format)
-                         (util/search-normalize))]
+                         (util/search-normalize-content))]
     {:id (:db/id block)
      :uuid (str uuid)
      :page page

+ 6 - 0
src/main/frontend/util.cljc

@@ -1175,6 +1175,12 @@
   [s]
   (.normalize s "NFC"))
 
+(defn search-normalize-content
+  "Normalize string for searching (loose, without lowercasing)
+   Case-sensitivity is ensured by the search engine"
+  [s]
+  (.normalize s "NFKD"))
+
 (defn search-normalize
   "Normalize string for searching (loose)"
   [s]