-
Notifications
You must be signed in to change notification settings - Fork 0
Scc 5348, 5353, 5354 #731
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
Scc 5348, 5353, 5354 #731
Changes from 9 commits
7692acf
5de3424
13cb77c
9c20994
ea6e8ae
512e3ba
c995262
ddecbc0
af45de7
9a98a67
8735fa3
68aa991
7fed80b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,18 +341,27 @@ function matchTermWithFields (fields, term, type) { | |
| } | ||
| } | ||
|
|
||
| function convertSingleDateToRange (date) { | ||
| const dateReg = /^(\d{4})(?:[-/](\d{2}))?(?:[-/](\d{2}))?$/ | ||
| const match = date.match(dateReg) | ||
| let rangeEnd | ||
| function nextDate (dateString) { | ||
| const dateRegex = /^(\d{4})(?:[-/](\d{2}))?(?:[-/](\d{2}))?$/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this method is responsible for validating dates. is there a specific case here that you're trying to account for? maybe you can pass the string into new Date() without regex crunching?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the about all of the ES date range shenaningans, but i think some comments would help to describe the transformations you're making
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how to do this without some regex, because it isn't just about getting the date but detecting how specific the date that the user entered is (i.e. whether they specified day, month, or only year). I've added some comments to hopefully clarify |
||
| const match = dateString.match(dateRegex) | ||
|
|
||
| const year = parseInt(match[1], 10) | ||
| const month = match[2] ? parseInt(match[2], 10) - 1 : 0 | ||
| const day = match[3] ? parseInt(match[3], 10) : 1 | ||
| const d = new Date(Date.UTC(year, month, day)) | ||
|
|
||
| if (match[3]) { | ||
| rangeEnd = { lte: `${match[1]}-${match[2]}-${match[3]}T23:59:59` } | ||
| } else if (match[2] && match[2] !== '12') { | ||
| rangeEnd = { lt: `${match[1]}-${parseInt(match[2], 10) + 1}` } | ||
| d.setUTCDate(d.getUTCDate() + 1) | ||
| } else if (match[2]) { | ||
| d.setUTCMonth(d.getUTCMonth() + 1) | ||
| } else { | ||
| rangeEnd = { lt: `${parseInt(match[1], 10) + 1}` } | ||
| d.setUTCFullYear(d.getUTCFullYear() + 1) | ||
| } | ||
| return Object.assign({ gte: date, relation: 'within' }, rangeEnd) | ||
| return d.toISOString().split('T')[0] | ||
| } | ||
|
|
||
| function convertSingleDateToRange (date) { | ||
| return { gte: date, relation: 'within', lt: nextDate(date) } | ||
| } | ||
|
|
||
| function rangeQueryForDates ({ relation, queryTerms }) { | ||
|
|
@@ -362,19 +371,19 @@ function rangeQueryForDates ({ relation, queryTerms }) { | |
| range = { lt: queryTerms[0] } | ||
| break | ||
| case '>': | ||
| range = { gt: queryTerms[0] } | ||
| range = { gte: nextDate(queryTerms[0]) } | ||
| break | ||
| case '>=': | ||
| range = { gte: queryTerms[0] } | ||
| break | ||
| case '<=': | ||
| range = { lte: queryTerms[0] } | ||
| range = { lt: nextDate(queryTerms[0]) } | ||
| break | ||
| case 'encloses': | ||
| range = { gt: queryTerms[0], lt: queryTerms[1] } | ||
| range = { gte: queryTerms[0], lte: queryTerms[0], relation: 'contains' } | ||
| break | ||
| case 'within': | ||
| range = { gte: queryTerms[0], lte: queryTerms[1] } | ||
| range = { gte: queryTerms[0], lt: nextDate(queryTerms[1]) } | ||
| break | ||
| default: | ||
| range = convertSingleDateToRange(queryTerms[0]) | ||
|
|
@@ -428,6 +437,21 @@ function dateQueries ({ fields, relation, terms, term }) { | |
| } | ||
| } | ||
|
|
||
| if (relation === 'encloses') { | ||
| query = { | ||
| bool: { | ||
| must: [ | ||
| query, | ||
| { | ||
| terms: { | ||
| 'dates.tag': ['c', 'd', 'i', 'k', 'm', 'q', 'u'] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per Sean |
||
|
|
||
| return { | ||
| nested: { | ||
| path: 'dates', | ||
|
|
@@ -447,12 +471,20 @@ function prefixQuery (field, term) { | |
| function multiMatch (fields, term, type) { | ||
| if (!fields || !fields.length) return [] | ||
|
|
||
| const query = { | ||
| query: term, | ||
| fields, | ||
| type | ||
| } | ||
|
|
||
| if (term.includes('*')) { | ||
| return [{ | ||
| query_string: query | ||
| }] | ||
| } | ||
|
|
||
| return [{ | ||
| multi_match: { | ||
| query: term, | ||
| fields, | ||
| type | ||
| } | ||
| multi_match: query | ||
| }] | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be updated to
*.keywordLowercasedStrippedonce the new es index is popuated. i can add it to my ticket to update discovery APIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK will leave this for now so as not to break the existing searches but once ready we can update to
*keywordLowercasedStripped. Is it all theexact_fieldsforseries?