Skip to content

Commit

Permalink
Fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Jan 3, 2022
1 parent 65bf624 commit 456e8f7
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 26 deletions.
6 changes: 3 additions & 3 deletions daux_libraries/search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion daux_libraries/search.min.js.map

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion src/js/search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,25 @@ export default class Search extends preact.Component {
return { warnings, counter, results, start };
}

const found = this.props.onSearch(this.state.search);
const found = Object.values(
this.props
.onSearch(this.state.search)
.reduce((acc, fieldResult) => {
// FlexSearch returns results per field
// We de-duplicate them here and have a single array of results
fieldResult.result.forEach(result => {
if (!acc.hasOwnProperty(result.id)) {
acc[result.id] = {
url: result.id,
title: result.doc.title,
text: result.doc.text
};
}
});

return acc;
}, {})
);

counter = found.length;

Expand Down
14 changes: 9 additions & 5 deletions src/js/search/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as preact from "preact";
import FlexSearch from "flexsearch";
import { Document } from "flexsearch";

import Search from "./Search";

Expand Down Expand Up @@ -54,10 +54,12 @@ class SearchEngine {
this.loadingPromise = new Promise(resolve => {
window.load_search_index = data => resolve(data);
}).then(json => {
this.searchIndex = new FlexSearch({
this.searchIndex = new Document({
doc: {
id: "url",
field: ["title", "text", "tags"]
tag: "tags",
field: ["title", "text"],
store: ["title", "text"]
}
});

Expand All @@ -71,7 +73,7 @@ class SearchEngine {
);
}

this.searchIndex.add(pages);
pages.forEach(page => this.searchIndex.add(page));
});
}

Expand Down Expand Up @@ -133,7 +135,9 @@ class SearchEngine {

preact.render(
<Search
onSearch={term => this.searchIndex.search(term)}
onSearch={term =>
this.searchIndex.search(term, { enrich: true })
}
onClose={this.handleClose}
onTitleChange={title => {
document.title = `${title} ${originalTitle}`;
Expand Down
4 changes: 2 additions & 2 deletions src/js/theme_daux/code_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function enableToggler(toggleCodeSection, codeBlocks) {
}

if (hidden) {
setCodeBlockStyle(codeBlocks, !!hidden);
toggleCodeBlockBtnSet.checked = !hidden;
setCodeBlockStyle(codeBlocks, true);
toggleCodeBlockBtnSet.checked = false;
}
} catch (e) {
// local storage operations can fail with the file:// protocol
Expand Down
4 changes: 2 additions & 2 deletions themes/daux/css/theme-blue.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/daux/css/theme-blue.min.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions themes/daux/css/theme-green.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/daux/css/theme-green.min.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions themes/daux/css/theme-navy.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/daux/css/theme-navy.min.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions themes/daux/css/theme-red.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/daux/css/theme-red.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/daux/js/daux.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 456e8f7

Please sign in to comment.