Skip to content

Commit

Permalink
feat(search): The aliases are now searchable.
Browse files Browse the repository at this point in the history
  • Loading branch information
panwarabhishek345 committed Nov 3, 2019
1 parent 424ff43 commit a992e0f
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/server/helpers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ export function autocomplete(orm, query, collection) {
}
else {
queryBody = {
match: {
'defaultAlias.name.autocomplete': {
minimum_should_match: '80%',
query
}
multi_match: {
fields: ['aliasSet.aliases.name.autocomplete', 'defaultAlias.name.autocomplete'],
minimum_should_match: '80%',
query
}
};
}
Expand Down Expand Up @@ -215,6 +214,24 @@ export async function generateIndex(orm) {
mappings: {
_default_: {
properties: {
'aliasSet.aliases': {
properties: {
name: {
fields: {
autocomplete: {
analyzer: 'edge',
type: 'text'
},
search: {
analyzer: 'trigrams',
type: 'text'
}
},
type: 'text'
}
},
type: 'object'
},
defaultAlias: {
properties: {
name: {
Expand Down Expand Up @@ -289,7 +306,8 @@ export async function generateIndex(orm) {
const baseRelations = [
'annotation',
'disambiguation',
'defaultAlias'
'defaultAlias',
'aliasSet.aliases'
];

const entityBehaviors = [
Expand Down Expand Up @@ -393,19 +411,17 @@ export function searchByName(orm, name, collection, size, from) {
query: {
bool: {
must: {
match: {
'defaultAlias.name.search': {
minimum_should_match: '75%',
query: name
}
multi_match: {
fields: ['aliasSet.aliases.name.search', 'defaultAlias.name.search'],
minimum_should_match: '75%',
query: name
}
},
should: {
match: {
'defaultAlias.name': {
boost: 1.3, // eslint-disable-line max-len,no-magic-numbers
query: name
}
multi_match: {
boost: 1.3, // eslint-disable-line max-len,no-magic-numbers
fields: ['aliasSet.aliases.name.search', 'defaultAlias.name.search'],
query: name
}
}
}
Expand Down

0 comments on commit a992e0f

Please sign in to comment.