Skip to content

Commit

Permalink
fix orderby with multiple labels, closes #4220
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Sep 5, 2023
1 parent f8e4a66 commit 7b662b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/search/lexer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ describe("Lexer fulltext", () => {
it("simple lexing", () => {
expect(lex("hello world").fulltextTokens.map(t => t.token))
.toEqual(["hello", "world"]);

expect(lex("hello, world").fulltextTokens.map(t => t.token))
.toEqual(["hello", "world"]);
});

it("use quotes to keep words together", () => {
Expand Down Expand Up @@ -147,6 +150,11 @@ describe("Lexer expression", () => {
expect(lex(`# not(#capital) and note.noteId != "root"`).expressionTokens.map(t => t.token))
.toEqual(["#", "not", "(", "#capital", ")", "and", "note", ".", "noteid", "!=", "root"]);
});

it("order by multiple labels", () => {
expect(lex(`# orderby #a,#b`).expressionTokens.map(t => t.token))
.toEqual(["#", "orderby", "#a", ",", "#b"]);
});
});

describe("Lexer invalid queries and edge cases", () => {
Expand Down
6 changes: 5 additions & 1 deletion src/services/search/services/lex.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function lex(str) {
let currentWord = '';

function isSymbolAnOperator(chr) {
return ['=', '*', '>', '<', '!', "-", "+", '%'].includes(chr);
return ['=', '*', '>', '<', '!', "-", "+", '%', ','].includes(chr);
}

function isPreviousSymbolAnOperator() {
Expand Down Expand Up @@ -128,6 +128,10 @@ function lex(str) {
}
}

if (chr === ',') {
continue;
}

currentWord += chr;
}

Expand Down

0 comments on commit 7b662b0

Please sign in to comment.