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

Hotfix the advanced search

parent 1282fbb2
No related branches found
No related tags found
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;
public class UserBriefDto {
@NotNull
@Field(name = "id", type = FieldType.Keyword)
@Schema(example = "1ffc7b0e-9aeb-4e8b-b8f1-68f3936155b4")
private UUID id;
@NotNull
@Field(name = "username", type = FieldType.Keyword)
@Schema(example = "jcarberry", description = "Only contains lowercase characters")
private String username;
......@@ -32,17 +34,21 @@ public class UserBriefDto {
private String name;
@JsonProperty("qualified_name")
@Field(name = "qualified_name", type = FieldType.Keyword)
@Schema(example = "Josiah Carberry — @jcarberry")
private String qualifiedName;
@Field(name = "orcid", type = FieldType.Keyword)
@Schema(example = "0000-0002-1825-0097")
private String orcid;
@JsonProperty("given_name")
@Field(name = "firstname", type = FieldType.Keyword)
@Schema(example = "Josiah")
private String firstname;
@JsonProperty("family_name")
@Field(name = "lastname", type = FieldType.Keyword)
@Schema(example = "Carberry")
private String lastname;
......
......@@ -89,8 +89,12 @@ public class UserServiceImpl implements UserService {
entity.setLastname(data.getLastname());
entity.setAffiliation(data.getAffiliation());
entity.setOrcid(data.getOrcid());
/* create at metadata database */
final User user = userRepository.save(entity);
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;
}
......
......@@ -28,6 +28,9 @@
},
"username": {
"type": "keyword"
},
"qualified_name": {
"type": "keyword"
}
}
},
......
......@@ -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"]
index = searchable_indices
field_list = [
"table.name",
"identifier.titles.title",
"identifier.descriptions.description",
"identifier.publisher",
"identifier.creators.*.firstname",
"identifier.creators.*.lastname",
"identifier.creators.*.creator_name",
"column.column_type",
"column.is_null_allowed",
"column.is_primary_key",
"unit.uri",
"unit.name",
"unit.description",
"concept.uri",
"concept.name",
"concept.description",
"funders",
"title",
"description",
"creator.username",
"author",
"name",
"uri",
"database.*",
"internal_name",
"is_public",
]
# field_list = [
# "id",
# "internal_name",
# "table.name",
# "database.is_public",
# "database.container.image.name",
# "database.container.image.version",
# "table.description",
# "identifier.titles.title",
# "identifier.descriptions.description",
# "identifier.publisher",
# "identifier.creators.*.firstname",
# "identifier.creators.*.lastname",
# "identifier.creators.*.creator_name",
# "column.column_type",
# "column.is_null_allowed",
# "column.is_primary_key",
# "unit.uri",
# "unit.name",
# "unit.description",
# "concept.uri",
# "concept.name",
# "concept.description",
# "funders",
# "title",
# "description",
# "creator.username",
# "author",
# "name",
# "uri",
# "database.*",
# "internal_name",
# "is_public",
# ]
queries = []
if search_term is not None:
logging.debug('query has search_term present')
......@@ -193,13 +199,18 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
logging.debug("search for specific index: %s", value)
index = value
continue
if key in field_list:
if re.match(f"{key}\\.", key):
# if key in field_list:
if re.match(f"{index}\.", key):
new_field = key[key.index(".") + 1:len(key)]
logging.debug(
f"field name {key} starts with index name {index}: flattened field name to {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.info(f"add match-query for range ),{t2}]")
musts.append({
......@@ -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.info(f"add match-query for range [{t1},(")
musts.append({
......@@ -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.info(f"add match-query for range [{t1},{t2}]")
musts.append({
......@@ -237,45 +248,49 @@ def general_search(search_term=None, t1=None, t2=None, fieldValuePairs=None):
}
})
else:
precision = "90%"
if key in ["attributes.orcid", "creators.name_identifier"]:
precision = "100%"
logging.debug(f"key {key} needs precision of 100%")
musts.append({
"match": {
key: {"query": value, "minimum_should_match": "90%"}
key: {"query": value, "minimum_should_match": precision}
}
})
specific_query = {"bool": {"must": musts}}
queries.append(specific_query)
body = {
"query": {"bool": {"must": queries}},
"_source": [
"_class",
"id",
"table_id",
"database_id",
"name",
"identifier.*",
"column_type",
"description",
"titles",
"descriptions",
"funders",
"licenses",
"creators",
"visibility",
"title",
"type",
"uri",
"username",
"is_public",
"created",
"_score",
"concept",
"unit",
"author",
"docID",
"creator.*",
"owner.*",
"details.*",
],
"query": {"bool": {"must": queries}}
# "_source": [
# "_class",
# "id",
# "table_id",
# "database_id",
# "name",
# "identifier.*",
# "column_type",
# "description",
# "titles",
# "descriptions",
# "funders",
# "licenses",
# "creators",
# "visibility",
# "title",
# "type",
# "uri",
# "username",
# "is_public",
# "created",
# "_score",
# "concept",
# "unit",
# "author",
# "docID",
# "creator.*",
# "owner.*",
# "details.*",
# ],
}
logging.debug('search index: %s', index)
logging.debug('search body: %s', body)
......
......@@ -2,6 +2,7 @@
<div>
<v-card flat tile>
<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-col cols="3">
<v-select
......@@ -116,10 +117,17 @@
</v-col>
</v-row>
<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
</v-btn>
</v-row>
</v-form>
</v-card-text>
</v-card>
</div>
......@@ -133,6 +141,7 @@ import SemanticMapper from '@/api/semantic.mapper'
export default {
data () {
return {
valid: false,
loading: false,
loadingFields: false,
showAdvancedSearch: false,
......@@ -212,6 +221,9 @@ export default {
})
},
methods: {
submit () {
this.$refs.form.validate()
},
/* Removes all advanced search fields when switching the type */
resetAdvancedSearchFields () {
Object.keys(this.advancedSearchData)
......@@ -251,14 +263,14 @@ export default {
dynamicFieldsMap () {
// Defines a mapping to narrow down the fields rendered for the advanced search
return {
database: ['created', 'description', 'is_public'],
table: ['created', 'description', 'is_public'],
database: ['is_public'],
table: ['description', 'is_public'],
column: ['column_type', 'is_primary_key', 'is_null_allowed'],
user: ['firstname', 'lastname', 'username'],
user: ['firstname', 'lastname', 'username', 'attributes.properties.orcid'],
identifier: [
'creators.properties.creator_name', 'creators.properties.name_identifier',
'descriptions.properties.description', 'doi', 'funders.properties.funder_identifier',
'publication_year', 'titles.properties.title', 'visibility'
'publication_year', 'titles.properties.title'
],
view: ['is_public', 'query'],
concept: ['uri'],
......
......@@ -218,6 +218,8 @@ export default {
return null
} else if (this.isView(item)) {
return item.query
} else if (this.isUser(item)) {
return item.name
}
return null
},
......@@ -264,6 +266,11 @@ export default {
tags.push({ text: 'Unit' })
} else if (this.isConcept(item)) {
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
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment