Initial commit
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
const { EDITOR_MAX_HITS } = require('../../../../../config/settings')
|
||||
|
||||
module.exports = function (dictionaryId, filters, searchFieldFilters) {
|
||||
const queryDsl = {
|
||||
_source: ['id', 'isValid', 'isPublished', 'term'],
|
||||
fields: ['foreignEntries.terms'],
|
||||
script_fields: {
|
||||
commentActivityIndicator: {
|
||||
script: {
|
||||
source: `
|
||||
if (!doc.containsKey('timeMostRecentComment') || doc['timeMostRecentComment'].empty) return "";
|
||||
|
||||
ZonedDateTime mostRecentCommentTime = doc['timeMostRecentComment'].value;
|
||||
|
||||
long nowMilli = params['now'];
|
||||
Instant nowInstant = Instant.ofEpochMilli(nowMilli);
|
||||
ZonedDateTime now = ZonedDateTime.ofInstant(nowInstant, ZoneId.of('Z'));
|
||||
|
||||
long ageInDays = ChronoUnit.DAYS.between(mostRecentCommentTime, now);
|
||||
|
||||
if (ageInDays < 7) {
|
||||
return "T"
|
||||
} else if (ageInDays < 30) {
|
||||
return "M"
|
||||
} else if (ageInDays < 365) {
|
||||
return "L"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
`,
|
||||
params: {
|
||||
now: Date.now()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
size: EDITOR_MAX_HITS,
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
term: {
|
||||
'dictionary.id': dictionaryId
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
sort: ['term.sort', 'homonymSort']
|
||||
}
|
||||
|
||||
if (searchFieldFilters) queryDsl.query.bool.filter.push(searchFieldFilters)
|
||||
|
||||
if (filters) {
|
||||
if (filters.isValid !== undefined) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
term: {
|
||||
isValid: filters.isValid
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (filters.isPublished !== undefined) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
term: {
|
||||
isPublished: filters.isPublished
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (filters.hasComments !== undefined) {
|
||||
if (filters.hasComments === true) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
exists: {
|
||||
field: 'timeMostRecentComment'
|
||||
}
|
||||
})
|
||||
} else {
|
||||
queryDsl.query.bool.filter.push({
|
||||
bool: {
|
||||
must_not: {
|
||||
exists: {
|
||||
field: 'timeMostRecentComment'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.isComplete !== undefined) {
|
||||
if (filters.isComplete === true) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
term: {
|
||||
status: 'complete'
|
||||
}
|
||||
})
|
||||
} else {
|
||||
queryDsl.query.bool.filter.push({
|
||||
bool: {
|
||||
must_not: {
|
||||
term: {
|
||||
status: 'complete'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.isTerminologyReviewed !== undefined) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
term: {
|
||||
isTerminologyReviewed: filters.isTerminologyReviewed
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (filters.isLanguageReviewed !== undefined) {
|
||||
queryDsl.query.bool.filter.push({
|
||||
term: {
|
||||
isLanguageReviewed: filters.isLanguageReviewed
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return queryDsl
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
const { fieldMap } = require('../..')
|
||||
const generateQuery = require('./all')
|
||||
|
||||
module.exports = function (dictionaryId, searchField, filters) {
|
||||
const searchFieldFilters = generateSearchFieldFilters(searchField)
|
||||
|
||||
const queryDsl = generateQuery(dictionaryId, filters, searchFieldFilters)
|
||||
|
||||
return queryDsl
|
||||
}
|
||||
|
||||
function generateSearchFieldFilters(searchField) {
|
||||
const mappedName = fieldMap[searchField]
|
||||
|
||||
if (mappedName) {
|
||||
if (mappedName.startsWith('foreignEntries')) {
|
||||
return {
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
exists: {
|
||||
field: mappedName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
exists: {
|
||||
field: mappedName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
dis_max: {
|
||||
queries: [
|
||||
{
|
||||
exists: {
|
||||
field: 'term'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'synonyms'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'label'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'definition'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'other'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'domainLabels'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'links'
|
||||
}
|
||||
},
|
||||
{
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
dis_max: {
|
||||
queries: [
|
||||
{
|
||||
exists: {
|
||||
field: 'foreignEntries.terms'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'foreignEntries.synonyms'
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: 'foreignEntries.definition'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
const { fieldMap } = require('../..')
|
||||
const generateQuery = require('./all')
|
||||
|
||||
module.exports = function (dictionaryId, searchField, searchString, filters) {
|
||||
const searchFieldFilters = generateSearchFieldFilters(
|
||||
searchField,
|
||||
searchString
|
||||
)
|
||||
|
||||
const queryDsl = generateQuery(dictionaryId, filters, searchFieldFilters)
|
||||
|
||||
return queryDsl
|
||||
}
|
||||
|
||||
function generateSearchFieldFilters(searchField, searchString) {
|
||||
const mappedName = fieldMap[searchField]
|
||||
|
||||
if (mappedName) {
|
||||
if (mappedName.startsWith('foreignEntries')) {
|
||||
return {
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
match_phrase: {
|
||||
[mappedName]: searchString
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
match_phrase: {
|
||||
[mappedName]: searchString
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
dis_max: {
|
||||
queries: [
|
||||
{
|
||||
multi_match: {
|
||||
query: searchString,
|
||||
type: 'phrase',
|
||||
fields: [
|
||||
'term',
|
||||
'synonyms',
|
||||
'label',
|
||||
'definition',
|
||||
'other',
|
||||
'domainLabels',
|
||||
'links'
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
multi_match: {
|
||||
query: searchString,
|
||||
type: 'phrase',
|
||||
fields: [
|
||||
'foreignEntries.terms',
|
||||
'foreignEntries.synonyms',
|
||||
'foreignEntries.definition'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
const { fieldMap, queryForField } = require('../..')
|
||||
const generateQuery = require('./all')
|
||||
|
||||
const whitespace = /\s+/
|
||||
|
||||
module.exports = function (dictionaryId, searchField, searchString, filters) {
|
||||
const searchFieldFilters = generateSearchFieldFilters(
|
||||
searchField,
|
||||
searchString
|
||||
)
|
||||
|
||||
const queryDsl = generateQuery(dictionaryId, filters, searchFieldFilters)
|
||||
|
||||
return queryDsl
|
||||
}
|
||||
|
||||
function generateSearchFieldFilters(searchField, searchString) {
|
||||
const searchTokens = searchString.split(whitespace)
|
||||
|
||||
const mappedName = fieldMap[searchField]
|
||||
|
||||
if (mappedName) {
|
||||
if (mappedName.startsWith('foreignEntries')) {
|
||||
return {
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: queryForField(mappedName, searchTokens)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queryForField(mappedName, searchTokens)
|
||||
}
|
||||
|
||||
return {
|
||||
dis_max: {
|
||||
queries: [
|
||||
queryForField('term', searchTokens),
|
||||
queryForField('synonyms', searchTokens),
|
||||
queryForField('label', searchTokens),
|
||||
queryForField('definition', searchTokens),
|
||||
queryForField('other', searchTokens),
|
||||
queryForField('domainLabels', searchTokens),
|
||||
queryForField('links', searchTokens),
|
||||
{
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
dis_max: {
|
||||
queries: [
|
||||
queryForField('foreignEntries.terms', searchTokens),
|
||||
queryForField('foreignEntries.synonyms', searchTokens),
|
||||
queryForField('foreignEntries.definition', searchTokens)
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
const { fieldMap } = require('../..')
|
||||
const generateQuery = require('./all')
|
||||
|
||||
module.exports = function (dictionaryId, searchField, searchString, filters) {
|
||||
const searchFieldFilters = generateSearchFieldFilters(
|
||||
searchField,
|
||||
searchString
|
||||
)
|
||||
|
||||
const queryDsl = generateQuery(dictionaryId, filters, searchFieldFilters)
|
||||
|
||||
return queryDsl
|
||||
}
|
||||
|
||||
function generateSearchFieldFilters(searchField, searchString) {
|
||||
const mappedName = fieldMap[searchField]
|
||||
|
||||
if (mappedName) {
|
||||
if (mappedName.startsWith('foreignEntries')) {
|
||||
return {
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
match: {
|
||||
[mappedName]: {
|
||||
query: searchString,
|
||||
operator: 'and'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
match: {
|
||||
[mappedName]: {
|
||||
query: searchString,
|
||||
operator: 'and'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
dis_max: {
|
||||
queries: [
|
||||
{
|
||||
multi_match: {
|
||||
query: searchString,
|
||||
operator: 'and',
|
||||
fields: [
|
||||
'term',
|
||||
'synonyms',
|
||||
'label',
|
||||
'definition',
|
||||
'other',
|
||||
'domainLabels',
|
||||
'links'
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
nested: {
|
||||
path: 'foreignEntries',
|
||||
query: {
|
||||
multi_match: {
|
||||
query: searchString,
|
||||
operator: 'and',
|
||||
fields: [
|
||||
'foreignEntries.terms',
|
||||
'foreignEntries.synonyms',
|
||||
'foreignEntries.definition'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user