Skip to content

Commit

Permalink
Merge pull request #34 from AtlasOfLivingAustralia/feature/#744
Browse files Browse the repository at this point in the history
Feature/#744
  • Loading branch information
schoicsiro authored Sep 12, 2023
2 parents d55c368 + ad81ace commit 4b0aec1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 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
6 changes: 3 additions & 3 deletions grails-app/services/au/org/ala/profile/SearchService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class SearchService extends BaseDataAccessService {
* A text search will look for the term(s) in any indexed field
*
*/
private static Map buildTextSearch(String term, SearchOptions options) {
static Map buildTextSearch(String term, SearchOptions options) {
Operator operator = AND
if (!options.matchAll) {
operator = OR
Expand All @@ -273,8 +273,8 @@ class SearchService extends BaseDataAccessService {
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(matchQuery("text", term).operator(operator)), 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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package au.org.ala.profile

import au.org.ala.profile.util.ProfileSortOption
import au.org.ala.web.AuthService
import au.org.ala.profile.util.SearchOptions
import grails.gorm.transactions.Rollback
import grails.plugins.elasticsearch.ElasticSearchService
import grails.testing.mixin.integration.Integration
import org.grails.datastore.mapping.core.Datastore
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -14,6 +15,8 @@ class SearchServiceSpec extends BaseIntegrationSpec {
SearchService service
@Autowired
Datastore datastore
@Autowired
ElasticSearchService elasticSearchService

Closure doWithSpring () {
System.println("Test")
Expand Down Expand Up @@ -1754,4 +1757,48 @@ class SearchServiceSpec extends BaseIntegrationSpec {
result.size() == 1
result[0].childCount == 1
}
def "buildTextSearch should include partial single matches from certain collection"() {
given:
Opus opus1 = save new Opus(glossary: new Glossary(), dataResourceUid: "dr1", title: "title1")
Profile profile1 = save new Profile(scientificName: "Dilany", fullName: "name1", opus: opus1, rank: "species", classification: [new Classification(rank: "kingdom", name: "Plantae")])
SearchOptions options = new SearchOptions()
options.setNameOnly(false)
options.setMatchAll(true)
options.setIncludeArchived(false)
options.setSearchAla(true)
options.setSearchNsl(true)
options.setIncludeNameAttributes(false)
options.setHideStubs(true)
when:
Map qMap = service.buildTextSearch("dilan", options)
then:
qMap.findAll(it -> it.toString().contains(profile1.scientificName)) != null
}
def "buildTextSearch should include partial multiple matches from certain collection"() {
given:
String searchItem = "BURDAL TOTEM"
Opus opus1 = save new Opus(glossary: new Glossary(), dataResourceUid: "dr1", title: "title1")
Profile profile1 = save new Profile(scientificName: "Salt Water Crocodile", fullName: searchItem, opus: opus1, rank: "species", classification: [new Classification(rank: "kingdom", name: "Plantae")])
SearchOptions options = new SearchOptions()
options.setNameOnly(false)
options.setMatchAll(true)
options.setIncludeArchived(false)
options.setSearchAla(true)
options.setSearchNsl(true)
options.setIncludeNameAttributes(false)
options.setHideStubs(true)
when:
Map qMap = service.buildTextSearch(searchItem, options)
then:
qMap.findAll(it -> it.toString().contains(profile1.toString())) != null
}
}

0 comments on commit 4b0aec1

Please sign in to comment.