Skip to content

Commit 5646a92

Browse files
committed
edit: refactor search, more uniform type handling
1 parent d0e9106 commit 5646a92

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/search.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ function buildOPS(
4949
if (!queryTerms.length) return
5050

5151
/* phrases */
52-
let phrases = queryTerms
53-
.filter((qT: term) => qT.type == 'phr')
54-
.map((phrase: any) => buildPhrase(phrase, collections, key))
55-
if (!phrases.length) {
56-
phrases = undefined
57-
} else {
58-
phrases = aql.join(phrases, opWord)
59-
}
52+
let phrases = queryTerms.filter((qT: term) => qT.type == 'phr')
53+
phrases = buildPhrases(phrases, collections, key, opWord)
6054

6155
/* tokens */
6256
let tokens = queryTerms.filter((qT: { type: string }) => qT.type === 'tok')
@@ -68,6 +62,20 @@ function buildOPS(
6862
return tokens || phrases
6963
}
7064

65+
function buildPhrases(
66+
phrases: term[],
67+
collections: collection[],
68+
key: string,
69+
opWord: string,
70+
): any {
71+
if (!phrases.length) return undefined
72+
73+
return aql.join(
74+
phrases.map((phrase: any) => buildPhrase(phrase, collections, key)),
75+
opWord,
76+
)
77+
}
78+
7179
function buildPhrase(
7280
phrase: term,
7381
collections: collection[],

0 commit comments

Comments
 (0)