mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
All: Search: More multi-language support, and started updating mobile app
This commit is contained in:
parent
8fdc0bf17c
commit
42a674008f
@ -797,7 +797,7 @@ class Application extends BaseApplication {
|
||||
|
||||
SearchEngine.instance().setDb(reg.db());
|
||||
SearchEngine.instance().setLogger(reg.logger());
|
||||
SearchEngine.runInBackground();
|
||||
SearchEngine.instance().scheduleSyncTables();
|
||||
|
||||
if (Setting.value('env') === 'dev') {
|
||||
AlarmService.updateAllNotifications();
|
||||
|
@ -227,8 +227,6 @@
|
||||
function setMarkers(keywords, options = null) {
|
||||
if (!options) options = {};
|
||||
|
||||
// TODO: Search engine support to mobile app (sync tables)
|
||||
// TODO: Update everywhere that uses allParsedQueryTerms to support new format
|
||||
// TODO: Add support for scriptType on mobile and CLI
|
||||
|
||||
if (!mark_) {
|
||||
|
@ -10,46 +10,23 @@ markJsUtils.markKeyword = (mark, keyword, stringUtils, extraOptions = null) => {
|
||||
|
||||
const isBasicSearch = ['ja', 'zh', 'ko'].indexOf(keyword.scriptType) >= 0;
|
||||
|
||||
|
||||
|
||||
|
||||
let value = keyword.value;
|
||||
let accuracy = keyword.accuracy ? keyword.accuracy : 'exactly';
|
||||
let accuracy = keyword.accuracy ? keyword.accuracy : { value: 'exactly', limiters: ":;.,-–—‒_(){}[]!'\"+=".split("") };
|
||||
if (isBasicSearch) accuracy = 'partially';
|
||||
if (keyword.type === 'regex') {
|
||||
accuracy = 'complementary';
|
||||
value = keyword.originalValue.substr(0, keyword.originalValue.length - 1);
|
||||
// Remove the trailing wildcard and "accuracy = complementary" will take care of
|
||||
// highlighting the relevant keywords.
|
||||
|
||||
// Known bug: it will also highlight word that contain the term as a suffix for example for "ent*", it will highlight "present"
|
||||
// which is incorrect (it should only highlight what starts with "ent") but for now will do. Mark.js doesn't have an option
|
||||
// to tweak this behaviour.
|
||||
value = keyword.value.substr(0, keyword.value.length - 1);
|
||||
}
|
||||
|
||||
mark.mark([value], Object.assign({}, {
|
||||
accuracy: accuracy,
|
||||
}, extraOptions));
|
||||
|
||||
|
||||
|
||||
|
||||
// if (keyword.type === 'regex') {
|
||||
// const b = '[' + stringUtils.pregQuote(' \t\n\r,.,+-*?!={}<>|:"\'()[]') + ']+';
|
||||
|
||||
// // The capturing groups are a hack to go around the strange behaviour of the ignoreGroups property. What we want is to
|
||||
// // exclude the first and last matches (the boundaries). What ignoreGroups does is ignore the first X groups. So
|
||||
// // we put the first boundary and the keyword inside a group, that way the first groups is ignored (ignoreGroups = 1)
|
||||
// // the second is included. And the last boundary is dropped because it's not in any group (it's important NOT to
|
||||
// // put this one in a group because otherwise it cannot be excluded).
|
||||
// let regexString = '(' + b + ')' + '(' + stringUtils.replaceRegexDiacritics(keyword.value) + ')' + b;
|
||||
// if (isBasicSearch) regexString = keyword.value;
|
||||
|
||||
// mark.markRegExp(new RegExp(regexString, 'gmi'), Object.assign({
|
||||
// acrossElements: true,
|
||||
// ignoreGroups: 1,
|
||||
// }, extraOptions));
|
||||
// } else {
|
||||
// let accuracy = keyword.accuracy ? keyword.accuracy : 'exactly';
|
||||
// if (isBasicSearch) accuracy = 'partially';
|
||||
// mark.mark([keyword.value], Object.assign({}, {
|
||||
// accuracy: accuracy,
|
||||
// }, extraOptions));
|
||||
// }
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
|
@ -298,9 +298,9 @@ class SearchEngine {
|
||||
}
|
||||
|
||||
if (term.indexOf('*') >= 0) {
|
||||
terms[col][i] = { type: 'regex', value: this.queryTermToRegex(term), scriptType: scriptType(term), originalValue: term };
|
||||
terms[col][i] = { type: 'regex', value: term, scriptType: scriptType(term), valueRegex: this.queryTermToRegex(term) };
|
||||
} else {
|
||||
terms[col][i] = { type: 'text', value: term, scriptType: scriptType(term), originalValue: term };
|
||||
terms[col][i] = { type: 'text', value: term, scriptType: scriptType(term) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,18 +374,6 @@ class SearchEngine {
|
||||
}
|
||||
}
|
||||
|
||||
static runInBackground() {
|
||||
if (this.isRunningInBackground_) return;
|
||||
|
||||
this.isRunningInBackground_ = true;
|
||||
|
||||
this.instance().syncTables();
|
||||
|
||||
setTimeout(() => {
|
||||
this.instance().syncTables();
|
||||
}, 1000 * 60 * 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = SearchEngine;
|
@ -228,7 +228,7 @@ function surroundKeywords(keywords, text, prefix, suffix) {
|
||||
|
||||
let regexString = keywords.map((k) => {
|
||||
if (k.type === 'regex') {
|
||||
return k.value;
|
||||
return k.valueRegex;
|
||||
} else {
|
||||
return pregQuote(k);
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ const generalMiddleware = store => next => async (action) => {
|
||||
|
||||
if (["NOTE_UPDATE_ONE", "NOTE_DELETE", "FOLDER_UPDATE_ONE", "FOLDER_DELETE"].indexOf(action.type) >= 0) {
|
||||
if (!await reg.syncTarget().syncStarted()) reg.scheduleSync(5 * 1000, { syncSteps: ["update_remote", "delete_remote"] });
|
||||
SearchEngine.instance().scheduleSyncTables();
|
||||
}
|
||||
|
||||
if (['EVENT_NOTE_ALARM_FIELD_CHANGE', 'NOTE_DELETE'].indexOf(action.type) >= 0) {
|
||||
@ -505,6 +506,7 @@ async function initialize(dispatch) {
|
||||
|
||||
SearchEngine.instance().setDb(reg.db());
|
||||
SearchEngine.instance().setLogger(reg.logger());
|
||||
SearchEngine.instance().scheduleSyncTables();
|
||||
|
||||
reg.scheduleSync().then(() => {
|
||||
// Wait for the first sync before updating the notifications, since synchronisation
|
||||
|
Loading…
Reference in New Issue
Block a user