|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
1 | 2 | import uniqBy from 'lodash.uniqby' |
2 | 3 |
|
3 | 4 | import { OrganizationField, findOrgById, queryOrgs } from '@crowd/data-access-layer' |
@@ -205,55 +206,46 @@ export async function getOrganizationMergeSuggestions( |
205 | 206 | // Query 2: Fuzzy matching - find similar values with typos/variations (verified only) |
206 | 207 | matches: uniqBy(fuzzyIdentities, 'value'), |
207 | 208 | builder: ({ value }) => ({ |
208 | | - bool: { |
209 | | - should: [ |
210 | | - { |
211 | | - match: { |
212 | | - [`nested_identities.string_value`]: { |
213 | | - query: value, |
214 | | - prefix_length: 1, |
215 | | - fuzziness: 'auto', |
216 | | - }, |
217 | | - }, |
218 | | - }, |
219 | | - ], |
220 | | - minimum_should_match: 1, |
221 | | - filter: [{ term: { [`nested_identities.bool_verified`]: true } }], |
| 209 | + match: { |
| 210 | + [`nested_identities.string_value`]: { |
| 211 | + query: value, |
| 212 | + prefix_length: 1, |
| 213 | + fuzziness: 'auto', |
| 214 | + }, |
222 | 215 | }, |
223 | 216 | }), |
| 217 | + filter: [{ term: { [`nested_identities.bool_verified`]: true } }], |
224 | 218 | }, |
225 | 219 | { |
226 | 220 | // Query 3: Prefix matching - find values that start with our prefix (verified only) |
227 | 221 | matches: uniqBy(prefixIdentities, 'value'), |
228 | 222 | builder: ({ value }) => ({ |
229 | | - bool: { |
230 | | - should: [ |
231 | | - { |
232 | | - prefix: { |
233 | | - [`nested_identities.string_value`]: { |
234 | | - value, |
235 | | - }, |
236 | | - }, |
237 | | - }, |
238 | | - ], |
239 | | - minimum_should_match: 1, |
240 | | - filter: [{ term: { [`nested_identities.bool_verified`]: true } }], |
| 223 | + prefix: { |
| 224 | + [`nested_identities.string_value`]: { |
| 225 | + value, |
| 226 | + }, |
241 | 227 | }, |
242 | 228 | }), |
| 229 | + filter: [{ term: { [`nested_identities.bool_verified`]: true } }], |
243 | 230 | }, |
244 | 231 | ] |
245 | 232 |
|
246 | | - for (const { matches, builder } of clauseBuilders) { |
| 233 | + for (const clauseBuilder of clauseBuilders) { |
| 234 | + const { matches, builder, filter } = clauseBuilder |
247 | 235 | if (matches.length > 0) { |
248 | 236 | const chunks = chunkArray(matches, CHUNK_SIZE) |
249 | 237 | for (const chunk of chunks) { |
250 | 238 | const shouldClauses = chunk.map(builder) |
251 | | - identitiesShould.push({ |
| 239 | + const chunkQuery: any = { |
252 | 240 | bool: { |
253 | 241 | should: shouldClauses, |
254 | 242 | minimum_should_match: 1, |
255 | 243 | }, |
256 | | - }) |
| 244 | + } |
| 245 | + if (filter) { |
| 246 | + chunkQuery.bool.filter = filter |
| 247 | + } |
| 248 | + identitiesShould.push(chunkQuery) |
257 | 249 | } |
258 | 250 | } |
259 | 251 | } |
|
0 commit comments