@tekkare/romulus 0.1.54 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -80,3 +80,32 @@ export declare function rmFilterOptionsQuery(spec: RmFilterOptionsSpec): {
|
|
|
80
80
|
};
|
|
81
81
|
/** Les options, relues dans la reponse du moteur. */
|
|
82
82
|
export declare function rmFilterOptions(response: any): RmFilterOption[];
|
|
83
|
+
/** Un champ interroge par la saisie d'un filtre. */
|
|
84
|
+
export interface RmFilterSearchField {
|
|
85
|
+
/** Champ interroge. La recherche porte sur son `.keyword`. */
|
|
86
|
+
field: string;
|
|
87
|
+
/**
|
|
88
|
+
* Chemins nested a traverser pour l'atteindre, du plus large au plus
|
|
89
|
+
* etroit (`['brand_history']`, ou `['a', 'a.b']` pour deux niveaux).
|
|
90
|
+
* Absent, le champ est a la racine du document.
|
|
91
|
+
*/
|
|
92
|
+
nested?: string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* La clause qui restreint les documents a la saisie, sur plusieurs champs a la
|
|
96
|
+
* fois. Meme regle que `rmFilterOptionsQuery`, pour un index ou le champ frere
|
|
97
|
+
* ne vit pas au meme niveau que le champ agrege : le filtre marque d'un index
|
|
98
|
+
* d'avis agrege `brand_group` a la racine et cherche la molecule dans
|
|
99
|
+
* `brand_history`, si bien que « pembro » sort KEYTRUDA. Un champ nested
|
|
100
|
+
* interroge sans son enveloppe `nested` ne repond jamais : c'est un filtre qui
|
|
101
|
+
* parait vide plutot qu'un filtre en erreur, d'ou cette enveloppe explicite.
|
|
102
|
+
*
|
|
103
|
+
* Trois facons de reconnaitre la saisie par champ : le fragment n'importe ou
|
|
104
|
+
* (`regexp`), la valeur entiere, et le debut. La derniere remonte en tete des
|
|
105
|
+
* listes ordonnees par pertinence.
|
|
106
|
+
*/
|
|
107
|
+
export declare function rmFilterSearchClause(fields: RmFilterSearchField[], input: string): {
|
|
108
|
+
bool: {
|
|
109
|
+
should: any[];
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -38,3 +38,32 @@ export function rmFilterOptions(response) {
|
|
|
38
38
|
(bucket) => Array.isArray(bucket.key) ? { label: String(bucket.key[0]), value: String(bucket.key[1]) } : { label: String(bucket.key), value: String(bucket.key) }
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
|
+
export function rmFilterSearchClause(fields, input) {
|
|
42
|
+
return {
|
|
43
|
+
bool: {
|
|
44
|
+
should: fields.map(({ field, nested }) => {
|
|
45
|
+
const clause = {
|
|
46
|
+
bool: {
|
|
47
|
+
should: [
|
|
48
|
+
{
|
|
49
|
+
regexp: {
|
|
50
|
+
[`${field}.keyword`]: {
|
|
51
|
+
value: `.*${input}.*`,
|
|
52
|
+
flags: "ALL",
|
|
53
|
+
case_insensitive: true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{ match_phrase: { [`${field}.keyword`]: input } },
|
|
58
|
+
{ prefix: { [`${field}.keyword`]: input } }
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return (nested ?? []).reduceRight(
|
|
63
|
+
(query, path) => ({ nested: { path, query } }),
|
|
64
|
+
clause
|
|
65
|
+
);
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|