Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public List<List<String>> toListOfLists() {

public String buildIndexScript() {
return "window.znaiSearchData = " + JsonUtils.serialize(toListOfLists()) + "\n" +
ResourceUtils.textContent("lunrjs/indexCreation.js");
ResourceUtils.textContent("flexsearchjs/indexCreation.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void addHighWithSpaceSeparator(String part) {
}

private String replaceCommonSeparatorsWithSpace(String text) {
return text.replaceAll("[.,();:\\-+=\\\\/\"'!?\\[\\]{}]", " ");
return text.replaceAll("[.,();:\\-+=\\\\/\"'!?\\[\\]{}~]", " ");
}

private SearchText createSearchText(SearchScore score, List<String> parts) {
Expand Down
18 changes: 18 additions & 0 deletions znai-core/src/main/resources/flexsearchjs/indexCreation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2025 znai maintainers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

window.znaiSearchIdx = window.createLocalSearchIndex();
window.populateLocalSearchIndexWithData(window.znaiSearchIdx, window.znaiSearchData);
59 changes: 0 additions & 59 deletions znai-core/src/main/resources/lunrjs/indexCreation.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add: Migrate from [lunrjs](https://github.com/olivernn/lunr.js) to [flexsearchjs](https://github.com/nextapps-de/flexsearch) for local search
49 changes: 38 additions & 11 deletions znai-reactjs/package-lock.json

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

2 changes: 1 addition & 1 deletion znai-reactjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"diff": "^4.0.2",
"echarts": "^5.3.2",
"feather-icons": "^4.28.0",
"flexsearch": "^0.8.167",
"katex": "0.16.21",
"lunr": "2.3.9",
"mark.js": "github:julmot/mark.js",
"mermaid": "^8.9.2",
"normalize.css": "^8.0.1",
Expand Down
80 changes: 0 additions & 80 deletions znai-reactjs/src/doc-elements/search/QueryResult.js

This file was deleted.

36 changes: 36 additions & 0 deletions znai-reactjs/src/doc-elements/search/QueryResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 znai maintainers
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { SearchResult } from "./flexSearch";

export default class QueryResult {
private readonly queryResultsById: Record<string, SearchResult>;
constructor(queryResults: SearchResult[]) {
this.queryResultsById = queryResults.reduce((acc, searchResult) => {
acc[searchResult.id] = searchResult;
return acc;
}, {} as Record<string, SearchResult>);
}

getIds() {
return Object.keys(this.queryResultsById);
}

getSnippetsToHighlight(id: string) {
return this.queryResultsById[id].termsToHighlight;
}
}
11 changes: 11 additions & 0 deletions znai-reactjs/src/doc-elements/search/Search.demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {getSearchPromise} from "./searchPromise"
import SearchPopup from "./SearchPopup"
import {elementsLibrary} from '../DefaultElementsLibrary'

import { setDocMeta } from "../../structure/docMeta.js";

import './testData'

const buttonStyle = {
Expand All @@ -31,6 +33,15 @@ const buttonStyle = {
class SearchDemo extends React.Component {
state = {isOpen: true}

componentDidMount() {
setDocMeta({
id: "preview",
title: "Your Product",
type: "Guide",
previewEnabled: true,
});
}

render() {
const { isOpen } = this.state

Expand Down
Loading