9
9
10
10
/**
11
11
* @typedef {import('../../types/api').Annotation } Annotation
12
+ * @typedef {import('../util/search-filter').Facet } Facet
12
13
*/
13
14
14
15
import { quote } from './annotation-metadata' ;
@@ -26,6 +27,7 @@ import * as unicodeUtils from '../util/unicode';
26
27
* @prop {(term: any, value: any) => boolean } match
27
28
*/
28
29
30
+ /** @param {Annotation } ann */
29
31
function displayName ( ann ) {
30
32
if ( ! ann . user_info ) {
31
33
return '' ;
@@ -35,6 +37,9 @@ function displayName(ann) {
35
37
36
38
/**
37
39
* Normalize a field value or query term for comparison.
40
+ *
41
+ * @template {string|number} T
42
+ * @param {T } val
38
43
*/
39
44
function normalize ( val ) {
40
45
if ( typeof val !== 'string' ) {
@@ -53,7 +58,7 @@ function normalize(val) {
53
58
class TermFilter {
54
59
/**
55
60
* @param {string } field - Name of field to match
56
- * @param {string } term - Query term
61
+ * @param {string|number } term - Query term
57
62
* @param {Checker } checker - Functions for extracting term values from
58
63
* an annotation and checking whether they match a query term.
59
64
*/
@@ -63,6 +68,11 @@ class TermFilter {
63
68
this . checker = checker ;
64
69
}
65
70
71
+ /**
72
+ * Return true if an annotation matches this filter.
73
+ *
74
+ * @param {Annotation } ann
75
+ */
66
76
matches ( ann ) {
67
77
const checker = this . checker ;
68
78
if ( checker . autofalse && checker . autofalse ( ann ) ) {
@@ -94,6 +104,11 @@ class BinaryOpFilter {
94
104
this . filters = filters ;
95
105
}
96
106
107
+ /**
108
+ * Return true if an annotation matches this filter.
109
+ *
110
+ * @param {Annotation } ann
111
+ */
97
112
matches ( ann ) {
98
113
if ( this . operator === 'and' ) {
99
114
return this . filters . every ( filter => filter . matches ( ann ) ) ;
@@ -154,8 +169,7 @@ const fieldMatchers = {
154
169
* Filters a set of annotations.
155
170
*
156
171
* @param {Annotation[] } annotations
157
- * @param {object } filters - Faceted filter generated by
158
- * `generateFacetedFilter`.
172
+ * @param {Record<string, Facet> } filters - Faceted filter generated by `generateFacetedFilter`
159
173
* @return {string[] } IDs of matching annotations.
160
174
*/
161
175
export function filterAnnotations ( annotations , filters ) {
0 commit comments