Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit aa9150a

Browse files
Revert "Update keyword search to be a substring search instead of exact match. Also search on first name, last name and handle"
This reverts commit c6b8f06.
1 parent c6b8f06 commit aa9150a

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

src/common/es-helper.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,11 @@ function setUserAttributesFiltersToEsQuery (filterClause, attributes) {
597597
}
598598
}
599599
],
600-
should: attribute.value.map(val => {
601-
return {
602-
query_string: {
603-
default_field: `${[USER_ATTRIBUTE.esDocumentValueStringQuery]}`,
604-
query: `*${val.replace(/ +/g, ' ').split(' ').join('* AND *')}*`
605-
}
600+
should: attribute.value.map(val => ({
601+
term: {
602+
[USER_ATTRIBUTE.esDocumentValueQuery]: val
606603
}
607-
}),
604+
})),
608605
minimum_should_match: 1
609606
}
610607
}
@@ -643,13 +640,6 @@ async function searchSkills (keyword) {
643640
async function setUserSearchClausesToEsQuery (boolClause, keyword) {
644641
const skillIds = await searchSkills(keyword)
645642

646-
boolClause.should.push({
647-
query_string: {
648-
fields: ['firstName', 'lastName', 'handle'],
649-
query: `*${keyword.replace(/ +/g, ' ').split(' ').join('* AND *')}*`
650-
}
651-
})
652-
653643
boolClause.should.push({
654644
nested: {
655645
path: USER_ATTRIBUTE.esDocumentPath,
@@ -793,27 +783,21 @@ async function resolveUserFilterFromDb (filter, { handle }, organizationId) {
793783
}
794784
})
795785

796-
if (typeof filter.values !== 'object') {
797-
filter.values = [filter.values]
798-
}
799-
800-
for (const value of filter.values) {
801-
if (value === 'true' || value === 'false') {
786+
if (typeof filter.values === 'object') {
787+
for (const value of filter.values) {
802788
esQueryClause.bool.should.push({
803789
term: {
804790
[filter.esDocumentValueQuery]: value
805791
}
806792
})
807-
} else {
808-
esQueryClause.bool.should.push({
809-
query_string: {
810-
default_field: `${filter.esDocumentValueQuery}`,
811-
query: `*${value.replace(/ +/g, ' ').split(' ').join('* AND *')}*`
812-
}
813-
})
814793
}
794+
} else {
795+
esQueryClause.bool.should.push({
796+
term: {
797+
[filter.esDocumentValueQuery]: filter.values
798+
}
799+
})
815800
}
816-
817801
esQueryClause.bool.minimum_should_match = 1
818802

819803
return {
@@ -831,18 +815,10 @@ async function resolveUserFilterFromDb (filter, { handle }, organizationId) {
831815
}
832816

833817
const model = filter.model
834-
835-
let filterValuesQuery = `${filter.queryField} like '%${filter.values[0]}%'`
836-
const nFilterValues = filter.values.length
837-
for (let i = 1; i < nFilterValues; i++) {
838-
filterValuesQuery = `${filterValuesQuery} OR ${filter.queryField} like '%${filter.values[i]}%'`
839-
}
840-
841818
// TODO Use the service method instead of raw query
842819
const dbQueries = [
843-
filterValuesQuery
820+
`${filter.queryField} in (${filter.values.map(f => `'${f}'`).join(',')})`
844821
]
845-
846822
const results = await DBHelper.find(model, dbQueries)
847823
if (results.length > 0) {
848824
for (const { id } of results) {

0 commit comments

Comments
 (0)