Skip to content

Commit

Permalink
fix: lowercased block content in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman authored and tiensonqin committed Jan 13, 2022
1 parent 9270c79 commit 4775be1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 6 additions & 4 deletions e2e-tests/page-refs.spec.ts
Expand Up @@ -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)
Expand All @@ -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 }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/components/search.cljs
Expand Up @@ -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)))
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/search/db.cljs
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/main/frontend/util.cljc
Expand Up @@ -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]
Expand Down

0 comments on commit 4775be1

Please sign in to comment.