Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circulars: Implement query_string method with fallback #2930

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@
const queryObj = query
? feature('CIRCULARS_LUCENE')
? {
simple_query_string: {
query_string: {
query,
fields: ['submitter', 'subject', 'body'],
lenient: true,
},
}
: {
Expand All @@ -183,14 +184,7 @@
}
: undefined

const {
body: {
hits: {
total: { value: totalItems },
hits,
},
},
} = await client.search({
const searchBody = {

Check warning on line 187 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L187

Added line #L187 was not covered by tests
index: 'circulars',
body: {
query: {
Expand All @@ -213,7 +207,33 @@
size: limit,
track_total_hits: true,
},
})
}

let searchResult
try {
searchResult = await client.search(searchBody)

Check warning on line 214 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L213-L214

Added lines #L213 - L214 were not covered by tests
} catch (error) {
console.error(

Check warning on line 216 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L216

Added line #L216 was not covered by tests
'Search with queryObj failed, falling back to multi_match',
error
)
searchBody.body.query.bool.must = {

Check warning on line 220 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L220

Added line #L220 was not covered by tests
multi_match: {
query: query ?? '',
fields: ['submitter', 'subject', 'body'],
},
}
searchResult = await client.search(searchBody)

Check warning on line 226 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L226

Added line #L226 was not covered by tests
}

const {
body: {
hits: {
total: { value: totalItems },
hits,
},
},
} = searchResult

Check warning on line 236 in app/routes/circulars/circulars.server.ts

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars/circulars.server.ts#L236

Added line #L236 was not covered by tests

const items = hits.map(
({
Expand Down
Loading