Skip to content

Commit 314219e

Browse files
committed
Only show search results that match all keywords
1 parent 16944fe commit 314219e

File tree

5 files changed

+57
-13
lines changed

5 files changed

+57
-13
lines changed

docs/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<link rel="stylesheet" href="css/theme.css?v=2.6.1">
1515
<link rel="icon" type="image/png" href="favicon.png">
1616
<script>
17-
var BUILD_TS = 1658204395;
17+
var BUILD_TS = 1658205717;
1818
</script>
1919
<script async src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
2020
<script type="text/x-mathjax-config">
@@ -26,8 +26,8 @@
2626
</script>
2727
<script src="js/BigInteger.min.js?v=2.6.1" type="text/javascript"></script>
2828
<script src="js/sha1.js?v=2.6.1" type="text/javascript"></script>
29-
<script src="js/data.js?ts=1658204395" type="text/javascript"></script>
30-
<script src="search/bkt_index.js?ts=1658204395" type="text/javascript"></script>
29+
<script src="js/data.js?ts=1658205717" type="text/javascript"></script>
30+
<script src="search/bkt_index.js?ts=1658205717" type="text/javascript"></script>
3131
<script src="js/ral.js?v=2.6.1" type="text/javascript"></script>
3232
<script src="js/main.js?v=2.6.1" type="text/javascript"></script>
3333
<script src="js/nav.js?v=2.6.1" type="text/javascript"></script>

docs/js/content_search.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ class ContentSearch {
203203
await take_a_break();
204204
if(abortSignal.aborted) return;
205205

206+
// Filter out matches that did not succeed in matching ALL keywords
207+
var filtered_match_list = [];
208+
for(var midx=0; midx<match_list.length; midx++){
209+
var kw_set = new Set(keywords);
210+
if(difference(kw_set, match_list[midx].get_matched_keywords()).size == 0){
211+
filtered_match_list.push(match_list[midx]);
212+
}
213+
}
214+
match_list = filtered_match_list;
215+
206216
// Sort results by match score
207217
match_list.sort((a, b) => {
208218
return a.compare_rank_to(b);
@@ -294,17 +304,17 @@ class ContentSearch {
294304

295305
static #shorten_text_first(text){
296306
var L = this.#PREVIEW_MAX_RUN_LENGTH;
297-
return "..." + text.slice(text.length - L, text.length);
307+
return "\u22ef" + text.slice(text.length - L, text.length);
298308
}
299309

300310
static #shorten_text_middle(text){
301311
var L = this.#PREVIEW_MAX_RUN_LENGTH;
302-
return text.slice(0, L/2) + "..." + text.slice(text.length - L/2, text.length);
312+
return text.slice(0, L/2) + "\u22ef \u22ef" + text.slice(text.length - L/2, text.length);
303313
}
304314

305315
static #shorten_text_last(text){
306316
var L = this.#PREVIEW_MAX_RUN_LENGTH;
307-
return text.slice(0, L) + "...";
317+
return text.slice(0, L) + "\u22ef";
308318
}
309319
}
310320

@@ -332,12 +342,16 @@ class ContentSearchMatch {
332342
return String([this.page_id, this.field_name]);
333343
}
334344

345+
get_matched_keywords(){
346+
return new Set([...this.full_match_keywords, ...this.partial_match_keywords]);
347+
}
348+
335349
compare_rank_to(other){
336350
// +1: other has higher rank than this
337351
// -1: other has lower rank than this
338352
// 0: Other is the same rank
339-
var this_merged_keywords = new Set([...this.full_match_keywords, ...this.partial_match_keywords]);
340-
var other_merged_keywords = new Set([...other.full_match_keywords, ...other.partial_match_keywords]);
353+
var this_merged_keywords = this.get_matched_keywords();
354+
var other_merged_keywords = other.get_matched_keywords();
341355

342356
// Total number of matching keywords is most important
343357
if(this_merged_keywords.size < other_merged_keywords.size) return 1;

docs/js/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ async function take_a_break(){
352352
await new Promise(r => setTimeout(r, 1));
353353
}
354354

355+
function difference(setA, setB) {
356+
const _difference = new Set(setA);
357+
for (const elem of setB) {
358+
_difference.delete(elem);
359+
}
360+
return _difference;
361+
}
362+
355363
//==============================================================================
356364
// Compatibility Workarounds
357365
//==============================================================================

src/peakrdl_html/static/js/content_search.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ class ContentSearch {
203203
await take_a_break();
204204
if(abortSignal.aborted) return;
205205

206+
// Filter out matches that did not succeed in matching ALL keywords
207+
var filtered_match_list = [];
208+
for(var midx=0; midx<match_list.length; midx++){
209+
var kw_set = new Set(keywords);
210+
if(difference(kw_set, match_list[midx].get_matched_keywords()).size == 0){
211+
filtered_match_list.push(match_list[midx]);
212+
}
213+
}
214+
match_list = filtered_match_list;
215+
206216
// Sort results by match score
207217
match_list.sort((a, b) => {
208218
return a.compare_rank_to(b);
@@ -294,17 +304,17 @@ class ContentSearch {
294304

295305
static #shorten_text_first(text){
296306
var L = this.#PREVIEW_MAX_RUN_LENGTH;
297-
return "..." + text.slice(text.length - L, text.length);
307+
return "\u22ef" + text.slice(text.length - L, text.length);
298308
}
299309

300310
static #shorten_text_middle(text){
301311
var L = this.#PREVIEW_MAX_RUN_LENGTH;
302-
return text.slice(0, L/2) + "..." + text.slice(text.length - L/2, text.length);
312+
return text.slice(0, L/2) + "\u22ef \u22ef" + text.slice(text.length - L/2, text.length);
303313
}
304314

305315
static #shorten_text_last(text){
306316
var L = this.#PREVIEW_MAX_RUN_LENGTH;
307-
return text.slice(0, L) + "...";
317+
return text.slice(0, L) + "\u22ef";
308318
}
309319
}
310320

@@ -332,12 +342,16 @@ class ContentSearchMatch {
332342
return String([this.page_id, this.field_name]);
333343
}
334344

345+
get_matched_keywords(){
346+
return new Set([...this.full_match_keywords, ...this.partial_match_keywords]);
347+
}
348+
335349
compare_rank_to(other){
336350
// +1: other has higher rank than this
337351
// -1: other has lower rank than this
338352
// 0: Other is the same rank
339-
var this_merged_keywords = new Set([...this.full_match_keywords, ...this.partial_match_keywords]);
340-
var other_merged_keywords = new Set([...other.full_match_keywords, ...other.partial_match_keywords]);
353+
var this_merged_keywords = this.get_matched_keywords();
354+
var other_merged_keywords = other.get_matched_keywords();
341355

342356
// Total number of matching keywords is most important
343357
if(this_merged_keywords.size < other_merged_keywords.size) return 1;

src/peakrdl_html/static/js/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ async function take_a_break(){
352352
await new Promise(r => setTimeout(r, 1));
353353
}
354354

355+
function difference(setA, setB) {
356+
const _difference = new Set(setA);
357+
for (const elem of setB) {
358+
_difference.delete(elem);
359+
}
360+
return _difference;
361+
}
362+
355363
//==============================================================================
356364
// Compatibility Workarounds
357365
//==============================================================================

0 commit comments

Comments
 (0)