Skip to content

Commit

Permalink
#744 remove attributes.text index false and change attribute.text ins…
Browse files Browse the repository at this point in the history
…tead of text
  • Loading branch information
schoicsiro committed Sep 7, 2023
1 parent 4360d9c commit c8ff449
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
3 changes: 1 addition & 2 deletions grails-app/domain/au/org/ala/profile/Attribute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class Attribute implements Comparable<Attribute> {
root = false
only = ["text", "title"]
title component: true
text index: "false"
}
}

String uuid
Term title
Expand Down
32 changes: 8 additions & 24 deletions grails-app/services/au/org/ala/profile/SearchService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,12 @@ class SearchService extends BaseDataAccessService {
query
}

private static QueryBuilder getNameAttributeQuery(String term, List<String> termList) {
private static QueryBuilder getNameAttributeQuery(String term) {
List<Term> nameTerms = Term.findAllByContainsName(true)
// a name attribute is one where the attribute title contains the word 'name'
QueryBuilder query = boolQuery()
query.must(nestedQuery("attributes.title", boolQuery().must(termsQuery("attributes.title.uuid", nameTerms*.uuid)), ScoreMode.Avg))
for (termItem in termList) {
query.must(wildcardQuery("text", termItem))
}
query
}

private static QueryBuilder getWildcardQuery(String fieldName, List<String> termList) {
QueryBuilder query = boolQuery()
for (termItem in termList) {
query.must(wildcardQuery(fieldName, ASTERISK+termItem+ASTERISK).boost(4))
}
query
boolQuery()
.must(nestedQuery("attributes.title", boolQuery().must(termsQuery("attributes.title.uuid", nameTerms*.uuid)), ScoreMode.Avg))
.must(matchQuery("text", term).operator(AND))
}

private static QueryBuilder buildFilter(String[] accessibleCollections, boolean includeArchived = false, Map<String, List<String>> filterLists = [:]) {
Expand Down Expand Up @@ -270,12 +259,7 @@ class SearchService extends BaseDataAccessService {
operator = OR
}

def termList = new ArrayList<String>()
if (term) {
termList = Arrays.asList(term.split())
}

QueryBuilder attributesWithNames = getNameAttributeQuery(term, termList)
QueryBuilder attributesWithNames = getNameAttributeQuery(term)

QueryBuilder query = boolQuery()
if (options.includeArchived) {
Expand All @@ -287,11 +271,11 @@ class SearchService extends BaseDataAccessService {
query.mustNot(termQuery("profileStatus", Profile.STATUS_EMPTY))
}

query.must(getWildcardQuery("scientificName", termList))
query.should(matchQuery("scientificName", term).boost(4))
query.should(nestedQuery("matchedName", boolQuery().must(matchQuery("matchedName.scientificName", term).operator(AND)), ScoreMode.Avg))
query.should(nestedQuery("attributes", attributesWithNames, ScoreMode.Avg).boost(3)) // score name-related attributes higher
query.should(nestedQuery("attributes", boolQuery().must(getWildcardQuery("text", termList)), ScoreMode.Avg))
query.should(nestedQuery("attributes", boolQuery().must(matchPhrasePrefixQuery("text", term)), ScoreMode.Avg))
query.should(nestedQuery("attributes", boolQuery().must(matchQuery("attributes.text", term).operator(operator)), ScoreMode.Avg))
query.should(nestedQuery("attributes", boolQuery().must(matchPhrasePrefixQuery("attributes.text", term)), ScoreMode.Avg))
[query: query]
}

Expand Down

0 comments on commit c8ff449

Please sign in to comment.