mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Mobile: Added button to fix search engine index
This commit is contained in:
parent
ffc311d7bd
commit
4d92187327
@ -1,5 +1,5 @@
|
||||
const React = require('react'); const Component = React.Component;
|
||||
const { Platform, TouchableOpacity, Linking, View, Switch, StyleSheet, Text, Button, ScrollView, TextInput } = require('react-native');
|
||||
const { Platform, TouchableOpacity, Linking, View, Switch, StyleSheet, Text, Button, ScrollView, TextInput, Alert } = require('react-native');
|
||||
const { connect } = require('react-redux');
|
||||
const { ScreenHeader } = require('lib/components/screen-header.js');
|
||||
const { _, setLocale } = require('lib/locale.js');
|
||||
@ -14,6 +14,7 @@ const NavService = require('lib/services/NavService.js');
|
||||
const VersionInfo = require('react-native-version-info').default;
|
||||
const { ReportService } = require('lib/services/report.js');
|
||||
const { time } = require('lib/time-utils');
|
||||
const SearchEngine = require('lib/services/SearchEngine');
|
||||
const RNFS = require('react-native-fs');
|
||||
|
||||
import Slider from '@react-native-community/slider';
|
||||
@ -78,6 +79,12 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
||||
this.setState({ creatingReport: false });
|
||||
}
|
||||
|
||||
this.fixSearchEngineIndexButtonPress_ = async () => {
|
||||
this.setState({ fixingSearchIndex: true });
|
||||
await SearchEngine.instance().rebuildIndex();
|
||||
this.setState({ fixingSearchIndex: false });
|
||||
}
|
||||
|
||||
this.logButtonPress_ = () => {
|
||||
NavService.go('Log');
|
||||
}
|
||||
@ -191,6 +198,15 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
||||
renderButton(key, title, clickHandler, options = null) {
|
||||
if (!options) options = {};
|
||||
|
||||
let descriptionComp = null;
|
||||
if (options.description) {
|
||||
descriptionComp = (
|
||||
<View style={{flex:1, marginTop: 10}}>
|
||||
<Text style={this.styles().descriptionText}>{options.description}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View key={key} style={this.styles().settingContainer}>
|
||||
<View style={{flex:1, flexDirection: 'column'}}>
|
||||
@ -198,6 +214,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
||||
<Button title={title} onPress={clickHandler} disabled={!!options.disabled}/>
|
||||
</View>
|
||||
{ options.statusComp }
|
||||
{ descriptionComp }
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@ -338,6 +355,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
||||
settingComps.push(this.renderButton('status_button', _('Sync Status'), this.syncStatusButtonPress_));
|
||||
settingComps.push(this.renderButton('log_button', _('Log'), this.logButtonPress_));
|
||||
settingComps.push(this.renderButton('export_report_button', this.state.creatingReport ? _('Creating report...') : _('Export Debug Report'), this.exportDebugButtonPress_, { disabled: this.state.creatingReport }));
|
||||
settingComps.push(this.renderButton('fix_search_engine_index', this.state.fixingSearchIndex ? _('Fixing search index...') : _('Fix search index'), this.fixSearchEngineIndexButtonPress_, { disabled: this.state.fixingSearchIndex, description: _('Use this to rebuild the search index if there is a problem with search. It may take some times depending on the number of notes.') }));
|
||||
|
||||
settingComps.push(this.renderHeader('moreInfo', _('More information')));
|
||||
|
||||
|
@ -7,6 +7,7 @@ const BaseModel = require('lib/BaseModel.js');
|
||||
const ItemChangeUtils = require('lib/services/ItemChangeUtils');
|
||||
const { pregQuote, scriptType } = require('lib/string-utils.js');
|
||||
const removeDiacritics = require('diacritics').remove;
|
||||
const { sprintf } = require('sprintf-js');
|
||||
|
||||
class SearchEngine {
|
||||
|
||||
@ -91,6 +92,12 @@ class SearchEngine {
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
async rebuildIndex() {
|
||||
Setting.setValue('searchEngine.lastProcessedChangeId', 0)
|
||||
Setting.setValue('searchEngine.initialIndexingDone', false);
|
||||
return this.syncTables();
|
||||
}
|
||||
|
||||
async syncTables() {
|
||||
if (this.isIndexing_) return;
|
||||
|
||||
@ -109,6 +116,11 @@ class SearchEngine {
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
const report = {
|
||||
inserted: 0,
|
||||
deleted: 0,
|
||||
};
|
||||
|
||||
let lastChangeId = Setting.value('searchEngine.lastProcessedChangeId');
|
||||
|
||||
try {
|
||||
@ -122,6 +134,8 @@ class SearchEngine {
|
||||
LIMIT 100
|
||||
`, [BaseModel.TYPE_NOTE, lastChangeId]);
|
||||
|
||||
const maxRow = await ItemChange.db().selectOne('SELECT max(id) FROM item_changes');
|
||||
|
||||
if (!changes.length) break;
|
||||
|
||||
const noteIds = changes.map(a => a.item_id);
|
||||
@ -137,9 +151,11 @@ class SearchEngine {
|
||||
if (note) {
|
||||
const n = this.normalizeNote_(note);
|
||||
queries.push({ sql: 'INSERT INTO notes_normalized(id, title, body) VALUES (?, ?, ?)', params: [change.item_id, n.title, n.body] });
|
||||
report.inserted++;
|
||||
}
|
||||
} else if (change.type === ItemChange.TYPE_DELETE) {
|
||||
queries.push({ sql: 'DELETE FROM notes_normalized WHERE id = ?', params: [change.item_id] });
|
||||
report.deleted++;
|
||||
} else {
|
||||
throw new Error('Invalid change type: ' + change.type);
|
||||
}
|
||||
@ -157,7 +173,7 @@ class SearchEngine {
|
||||
|
||||
await ItemChangeUtils.deleteProcessedChanges();
|
||||
|
||||
this.logger().info('SearchEngine: Updated FTS table in ' + (Date.now() - startTime) + 'ms');
|
||||
this.logger().info(sprintf('SearchEngine: Updated FTS table in %dms. Inserted: %d. Deleted: %d', Date.now() - startTime, report.inserted, report.deleted));
|
||||
|
||||
this.isIndexing_ = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user