Skip to content
Snippets Groups Projects
Verified Commit 3af625c4 authored by Martin Weise's avatar Martin Weise
Browse files

Hotfix the advanced search

parent 1282fbb2
Branches
Tags
3 merge requests!231CI: Remove build for log-service,!228Better error message handling in the frontend,!223Release of version 1.4.0
...@@ -21,10 +21,12 @@ import java.util.UUID; ...@@ -21,10 +21,12 @@ import java.util.UUID;
public class UserBriefDto { public class UserBriefDto {
@NotNull @NotNull
@Field(name = "id", type = FieldType.Keyword)
@Schema(example = "1ffc7b0e-9aeb-4e8b-b8f1-68f3936155b4") @Schema(example = "1ffc7b0e-9aeb-4e8b-b8f1-68f3936155b4")
private UUID id; private UUID id;
@NotNull @NotNull
@Field(name = "username", type = FieldType.Keyword)
@Schema(example = "jcarberry", description = "Only contains lowercase characters") @Schema(example = "jcarberry", description = "Only contains lowercase characters")
private String username; private String username;
...@@ -32,17 +34,21 @@ public class UserBriefDto { ...@@ -32,17 +34,21 @@ public class UserBriefDto {
private String name; private String name;
@JsonProperty("qualified_name") @JsonProperty("qualified_name")
@Field(name = "qualified_name", type = FieldType.Keyword)
@Schema(example = "Josiah Carberry — @jcarberry") @Schema(example = "Josiah Carberry — @jcarberry")
private String qualifiedName; private String qualifiedName;
@Field(name = "orcid", type = FieldType.Keyword)
@Schema(example = "0000-0002-1825-0097") @Schema(example = "0000-0002-1825-0097")
private String orcid; private String orcid;
@JsonProperty("given_name") @JsonProperty("given_name")
@Field(name = "firstname", type = FieldType.Keyword)
@Schema(example = "Josiah") @Schema(example = "Josiah")
private String firstname; private String firstname;
@JsonProperty("family_name") @JsonProperty("family_name")
@Field(name = "lastname", type = FieldType.Keyword)
@Schema(example = "Carberry") @Schema(example = "Carberry")
private String lastname; private String lastname;
......
...@@ -89,8 +89,12 @@ public class UserServiceImpl implements UserService { ...@@ -89,8 +89,12 @@ public class UserServiceImpl implements UserService {
entity.setLastname(data.getLastname()); entity.setLastname(data.getLastname());
entity.setAffiliation(data.getAffiliation()); entity.setAffiliation(data.getAffiliation());
entity.setOrcid(data.getOrcid()); entity.setOrcid(data.getOrcid());
/* create at metadata database */
final User user = userRepository.save(entity); final User user = userRepository.save(entity);
log.info("Updated user data for user with id {}", user.getId()); log.info("Updated user data for user with id {}", user.getId());
/* save in open search database */
userIdxRepository.save(userMapper.userToUserDto(user));
log.info("Created user with id {} in open search database", user.getId());
return user; return user;
} }
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
}, },
"username": { "username": {
"type": "keyword" "type": "keyword"
},
"qualified_name": {
"type": "keyword"
} }
} }
}, },
......
...@@ -125,34 +125,40 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): ...@@ -125,34 +125,40 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
""" """
searchable_indices = ["database", "user", "table", "column", "identifier", "view", "concept", "unit"] searchable_indices = ["database", "user", "table", "column", "identifier", "view", "concept", "unit"]
index = searchable_indices index = searchable_indices
field_list = [ # field_list = [
"table.name", # "id",
"identifier.titles.title", # "internal_name",
"identifier.descriptions.description", # "table.name",
"identifier.publisher", # "database.is_public",
"identifier.creators.*.firstname", # "database.container.image.name",
"identifier.creators.*.lastname", # "database.container.image.version",
"identifier.creators.*.creator_name", # "table.description",
"column.column_type", # "identifier.titles.title",
"column.is_null_allowed", # "identifier.descriptions.description",
"column.is_primary_key", # "identifier.publisher",
"unit.uri", # "identifier.creators.*.firstname",
"unit.name", # "identifier.creators.*.lastname",
"unit.description", # "identifier.creators.*.creator_name",
"concept.uri", # "column.column_type",
"concept.name", # "column.is_null_allowed",
"concept.description", # "column.is_primary_key",
"funders", # "unit.uri",
"title", # "unit.name",
"description", # "unit.description",
"creator.username", # "concept.uri",
"author", # "concept.name",
"name", # "concept.description",
"uri", # "funders",
"database.*", # "title",
"internal_name", # "description",
"is_public", # "creator.username",
] # "author",
# "name",
# "uri",
# "database.*",
# "internal_name",
# "is_public",
# ]
queries = [] queries = []
if search_term is not None: if search_term is not None:
logging.debug('query has search_term present') logging.debug('query has search_term present')
...@@ -193,13 +199,18 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): ...@@ -193,13 +199,18 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
logging.debug("search for specific index: %s", value) logging.debug("search for specific index: %s", value)
index = value index = value
continue continue
if key in field_list: # if key in field_list:
if re.match(f"{key}\\.", key): if re.match(f"{index}\.", key):
new_field = key[key.index(".") + 1:len(key)] new_field = key[key.index(".") + 1:len(key)]
logging.debug( logging.debug(
f"field name {key} starts with index name {index}: flattened field name to {new_field}") f"field name {key} starts with index name {index}: flattened field name to {new_field}")
key = new_field key = new_field
if is_range_open_end and re.match(f"unit\\.", key): if re.match(".*properties\..*", key):
new_field = key.replace("properties.", "")
logging.debug(
f"field name {key} contains properties keyword: flattened field name to {new_field}")
key = new_field
if is_range_open_end and re.match(f"unit\.", key):
logging.debug(f"omit key={key} because query type=open end range and key is somewhat unit") logging.debug(f"omit key={key} because query type=open end range and key is somewhat unit")
logging.info(f"add match-query for range ),{t2}]") logging.info(f"add match-query for range ),{t2}]")
musts.append({ musts.append({
...@@ -209,7 +220,7 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): ...@@ -209,7 +220,7 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
} }
} }
}) })
elif is_range_open_begin and re.match(f"unit\\.", key): elif is_range_open_begin and re.match(f"unit\.", key):
logging.debug(f"omit key={key} because query type=open begin range and key is somewhat unit") logging.debug(f"omit key={key} because query type=open begin range and key is somewhat unit")
logging.info(f"add match-query for range [{t1},(") logging.info(f"add match-query for range [{t1},(")
musts.append({ musts.append({
...@@ -219,7 +230,7 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): ...@@ -219,7 +230,7 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
} }
} }
}) })
elif is_range_query and re.match(f"unit\\.", key): elif is_range_query and re.match(f"unit\.", key):
logging.debug(f"omit key={key} because query type=full range and key is somewhat unit") logging.debug(f"omit key={key} because query type=full range and key is somewhat unit")
logging.info(f"add match-query for range [{t1},{t2}]") logging.info(f"add match-query for range [{t1},{t2}]")
musts.append({ musts.append({
...@@ -237,45 +248,49 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None): ...@@ -237,45 +248,49 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
} }
}) })
else: else:
precision = "90%"
if key in ["attributes.orcid", "creators.name_identifier"]:
precision = "100%"
logging.debug(f"key {key} needs precision of 100%")
musts.append({ musts.append({
"match": { "match": {
key: {"query": value, "minimum_should_match": "90%"} key: {"query": value, "minimum_should_match": precision}
} }
}) })
specific_query = {"bool": {"must": musts}} specific_query = {"bool": {"must": musts}}
queries.append(specific_query) queries.append(specific_query)
body = { body = {
"query": {"bool": {"must": queries}}, "query": {"bool": {"must": queries}}
"_source": [ # "_source": [
"_class", # "_class",
"id", # "id",
"table_id", # "table_id",
"database_id", # "database_id",
"name", # "name",
"identifier.*", # "identifier.*",
"column_type", # "column_type",
"description", # "description",
"titles", # "titles",
"descriptions", # "descriptions",
"funders", # "funders",
"licenses", # "licenses",
"creators", # "creators",
"visibility", # "visibility",
"title", # "title",
"type", # "type",
"uri", # "uri",
"username", # "username",
"is_public", # "is_public",
"created", # "created",
"_score", # "_score",
"concept", # "concept",
"unit", # "unit",
"author", # "author",
"docID", # "docID",
"creator.*", # "creator.*",
"owner.*", # "owner.*",
"details.*", # "details.*",
], # ],
} }
logging.debug('search index: %s', index) logging.debug('search index: %s', index)
logging.debug('search body: %s', body) logging.debug('search body: %s', body)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<div> <div>
<v-card flat tile> <v-card flat tile>
<v-card-text class="pt-0 pl-4 pb-6 pr-4"> <v-card-text class="pt-0 pl-4 pb-6 pr-4">
<v-form ref="form" v-model="valid" autocomplete="off" @submit.prevent="submit">
<v-row dense> <v-row dense>
<v-col cols="3"> <v-col cols="3">
<v-select <v-select
...@@ -116,10 +117,17 @@ ...@@ -116,10 +117,17 @@
</v-col> </v-col>
</v-row> </v-row>
<v-row dense> <v-row dense>
<v-btn class="mr-2" color="primary" :loading="loading" small @click="advancedSearch"> <v-btn
type="submit"
class="mr-2"
color="primary"
:loading="loading"
small
@click="advancedSearch">
Search Search
</v-btn> </v-btn>
</v-row> </v-row>
</v-form>
</v-card-text> </v-card-text>
</v-card> </v-card>
</div> </div>
...@@ -133,6 +141,7 @@ import SemanticMapper from '@/api/semantic.mapper' ...@@ -133,6 +141,7 @@ import SemanticMapper from '@/api/semantic.mapper'
export default { export default {
data () { data () {
return { return {
valid: false,
loading: false, loading: false,
loadingFields: false, loadingFields: false,
showAdvancedSearch: false, showAdvancedSearch: false,
...@@ -212,6 +221,9 @@ export default { ...@@ -212,6 +221,9 @@ export default {
}) })
}, },
methods: { methods: {
submit () {
this.$refs.form.validate()
},
/* Removes all advanced search fields when switching the type */ /* Removes all advanced search fields when switching the type */
resetAdvancedSearchFields () { resetAdvancedSearchFields () {
Object.keys(this.advancedSearchData) Object.keys(this.advancedSearchData)
...@@ -251,14 +263,14 @@ export default { ...@@ -251,14 +263,14 @@ export default {
dynamicFieldsMap () { dynamicFieldsMap () {
// Defines a mapping to narrow down the fields rendered for the advanced search // Defines a mapping to narrow down the fields rendered for the advanced search
return { return {
database: ['created', 'description', 'is_public'], database: ['is_public'],
table: ['created', 'description', 'is_public'], table: ['description', 'is_public'],
column: ['column_type', 'is_primary_key', 'is_null_allowed'], column: ['column_type', 'is_primary_key', 'is_null_allowed'],
user: ['firstname', 'lastname', 'username'], user: ['firstname', 'lastname', 'username', 'attributes.properties.orcid'],
identifier: [ identifier: [
'creators.properties.creator_name', 'creators.properties.name_identifier', 'creators.properties.creator_name', 'creators.properties.name_identifier',
'descriptions.properties.description', 'doi', 'funders.properties.funder_identifier', 'descriptions.properties.description', 'doi', 'funders.properties.funder_identifier',
'publication_year', 'titles.properties.title', 'visibility' 'publication_year', 'titles.properties.title'
], ],
view: ['is_public', 'query'], view: ['is_public', 'query'],
concept: ['uri'], concept: ['uri'],
......
...@@ -218,6 +218,8 @@ export default { ...@@ -218,6 +218,8 @@ export default {
return null return null
} else if (this.isView(item)) { } else if (this.isView(item)) {
return item.query return item.query
} else if (this.isUser(item)) {
return item.name
} }
return null return null
}, },
...@@ -264,6 +266,11 @@ export default { ...@@ -264,6 +266,11 @@ export default {
tags.push({ text: 'Unit' }) tags.push({ text: 'Unit' })
} else if (this.isConcept(item)) { } else if (this.isConcept(item)) {
tags.push({ text: 'Concept' }) tags.push({ text: 'Concept' })
} else if (this.isUser(item)) {
tags.push({ text: 'User' })
if ('orcid' in item.attributes && item.attributes.orcid) {
tags.push({ text: 'ORCID', color: 'green' })
}
} }
return tags return tags
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment