Skip to content

Commit 397db3c

Browse files
committed
Hackily ensure single word search string contains wildcards
Triggers fuzzy matching instead of whole-word search
1 parent 3911054 commit 397db3c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

qwc2.yml.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ theme:
3737
include_homepage_in_sidebar: true
3838
extra_css:
3939
- css/custom.css
40+
extra_javascript:
41+
- js/extend-search.js
4042
markdown_extensions:
4143
- toc:
4244
permalink: true

src/js/extend-search.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const params = new URLSearchParams(window.location.search);
2+
const q = params.get('q');
3+
4+
// Ensure single word query is pre- and postfixed with '*' (wildcard char)
5+
if (q) {
6+
const words = q.split(/\s+/);
7+
if (words.length === 1) {
8+
const word = words[0];
9+
if (!word.startsWith('*') || !word.endsWith('*')) {
10+
words[0] = `*${word.replace(/^\*/, "").replace(/\*$/, "")}*`;
11+
params.set('q', words.join(' '));
12+
window.location.href = `${window.location.pathname}?${params.toString()}`;
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)