mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
parent
fa83d48141
commit
f0f6590312
@ -340,6 +340,8 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
} else { // Note TITLE or BODY
|
} else { // Note TITLE or BODY
|
||||||
listType = BaseModel.TYPE_NOTE;
|
listType = BaseModel.TYPE_NOTE;
|
||||||
searchQuery = gotoAnythingStyleQuery(this.state.query);
|
searchQuery = gotoAnythingStyleQuery(this.state.query);
|
||||||
|
// SearchEngine returns the title normalized, that is why we need to
|
||||||
|
// override this field below with the original title
|
||||||
results = (await SearchEngine.instance().search(searchQuery)) as any[];
|
results = (await SearchEngine.instance().search(searchQuery)) as any[];
|
||||||
|
|
||||||
resultsInBody = !!results.find((row: any) => row.fields.includes('body'));
|
resultsInBody = !!results.find((row: any) => row.fields.includes('body'));
|
||||||
@ -348,10 +350,12 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
const resources = await Resource.resourceOcrTextsByIds(resourceIds);
|
const resources = await Resource.resourceOcrTextsByIds(resourceIds);
|
||||||
|
|
||||||
if (!resultsInBody || this.state.query.length <= 1) {
|
if (!resultsInBody || this.state.query.length <= 1) {
|
||||||
|
const notes = await Note.byIds(results.map((result: any) => result.id), { fields: ['id', 'title'] });
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
const row = results[i];
|
const row = results[i];
|
||||||
const path = Folder.folderPathString(this.props.folders, row.parent_id);
|
const path = Folder.folderPathString(this.props.folders, row.parent_id);
|
||||||
results[i] = { ...row, path: path };
|
const originalNote = notes.find(note => note.id === row.id);
|
||||||
|
results[i] = { ...row, path: path, title: originalNote.title };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const limit = 20;
|
const limit = 20;
|
||||||
@ -364,13 +368,14 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
results = results.filter((row: any) => !row.is_todo || !row.todo_completed);
|
results = results.filter((row: any) => !row.is_todo || !row.todo_completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notes = await Note.byIds(results.map((result: any) => result.id).slice(0, limit), { fields: ['id', 'body', 'markup_language', 'is_todo', 'todo_completed'] });
|
const notes = await Note.byIds(results.map((result: any) => result.id).slice(0, limit), { fields: ['id', 'body', 'markup_language', 'is_todo', 'todo_completed', 'title'] });
|
||||||
// Can't make any sense of this code so...
|
// Can't make any sense of this code so...
|
||||||
const notesById = notes.reduce((obj, { id, body, markup_language }) => ((obj[[id] as any] = { id, body, markup_language }), obj), {});
|
const notesById = notes.reduce((obj, { id, body, markup_language, title }) => ((obj[[id] as any] = { id, body, markup_language, title }), obj), {});
|
||||||
|
|
||||||
// Filter out search results that are associated with non-existing notes.
|
// Filter out search results that are associated with non-existing notes.
|
||||||
// https://github.com/laurent22/joplin/issues/5417
|
// https://github.com/laurent22/joplin/issues/5417
|
||||||
results = results.filter(r => !!notesById[r.id]);
|
results = results.filter(r => !!notesById[r.id])
|
||||||
|
.map(r => ({ ...r, title: notesById[r.id].title }));
|
||||||
|
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
const row = results[i];
|
const row = results[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user