1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-31 00:07:48 +02:00

All: Resolves #1198: In search results, give more weight to more recent notes and less to completed to-dos

This commit is contained in:
Laurent Cozic
2019-02-24 12:00:06 +00:00
parent 6b3fe6b2cb
commit 179005dd6c
2 changed files with 57 additions and 1 deletions

View File

@@ -111,6 +111,58 @@ describe('services_SearchEngine', function() {
expect(rows[4].id).toBe(n5.id);
}));
it('should order search results by relevance (last updated first)', asyncTest(async () => {
let rows;
const n1 = await Note.save({ title: "abcd" });
await sleep(0.1);
const n2 = await Note.save({ title: "abcd" });
await sleep(0.1);
const n3 = await Note.save({ title: "abcd" });
await sleep(0.1);
await engine.syncTables();
rows = await engine.search('abcd');
expect(rows[0].id).toBe(n3.id);
expect(rows[1].id).toBe(n2.id);
expect(rows[2].id).toBe(n1.id);
await Note.save({ id: n1.id, title: "abcd" });
await engine.syncTables();
rows = await engine.search('abcd');
expect(rows[0].id).toBe(n1.id);
expect(rows[1].id).toBe(n3.id);
expect(rows[2].id).toBe(n2.id);
}));
it('should order search results by relevance (completed to-dos last)', asyncTest(async () => {
let rows;
const n1 = await Note.save({ title: "abcd", is_todo: 1 });
await sleep(0.1);
const n2 = await Note.save({ title: "abcd", is_todo: 1 });
await sleep(0.1);
const n3 = await Note.save({ title: "abcd", is_todo: 1 });
await sleep(0.1);
await engine.syncTables();
rows = await engine.search('abcd');
expect(rows[0].id).toBe(n3.id);
expect(rows[1].id).toBe(n2.id);
expect(rows[2].id).toBe(n1.id);
await Note.save({ id: n3.id, todo_completed: Date.now() });
await engine.syncTables();
rows = await engine.search('abcd');
expect(rows[0].id).toBe(n2.id);
expect(rows[1].id).toBe(n1.id);
expect(rows[2].id).toBe(n3.id);
}));
it('should supports various query types', asyncTest(async () => {
let rows;

View File

@@ -214,6 +214,10 @@ class SearchEngine {
rows.sort((a, b) => {
if (a.weight < b.weight) return +1;
if (a.weight > b.weight) return -1;
if (a.is_todo && a.todo_completed) return +1;
if (b.is_todo && b.todo_completed) return -1;
if (a.user_updated_time < b.user_updated_time) return +1;
if (a.user_updated_time > b.user_updated_time) return -1;
return 0;
});
}
@@ -364,7 +368,7 @@ class SearchEngine {
return this.basicSearch(query);
} else {
const parsedQuery = this.parseQuery(query);
const sql = 'SELECT id, title, offsets(notes_fts) AS offsets FROM notes_fts WHERE notes_fts MATCH ?'
const sql = 'SELECT notes_fts.id, notes_fts.title, offsets(notes_fts) AS offsets, notes.user_updated_time, notes.is_todo, notes.todo_completed FROM notes_fts LEFT JOIN notes ON notes_fts.id = notes.id WHERE notes_fts MATCH ?'
try {
const rows = await this.db().selectAll(sql, [query]);
this.orderResults_(rows, parsedQuery);