diff --git a/grails-app/domain/au/org/ala/profile/Attribute.groovy b/grails-app/domain/au/org/ala/profile/Attribute.groovy index 1e5360a..eddec6c 100644 --- a/grails-app/domain/au/org/ala/profile/Attribute.groovy +++ b/grails-app/domain/au/org/ala/profile/Attribute.groovy @@ -14,8 +14,7 @@ class Attribute implements Comparable { root = false only = ["text", "title"] title component: true - text index: "false" - } + } String uuid Term title diff --git a/grails-app/services/au/org/ala/profile/SearchService.groovy b/grails-app/services/au/org/ala/profile/SearchService.groovy index e39bd8a..5d03c5f 100644 --- a/grails-app/services/au/org/ala/profile/SearchService.groovy +++ b/grails-app/services/au/org/ala/profile/SearchService.groovy @@ -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 @@ -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] } diff --git a/src/integration-test/groovy/au/org/ala/profile/SearchServiceSpec.groovy b/src/integration-test/groovy/au/org/ala/profile/SearchServiceSpec.groovy index 69efc82..c4560e9 100644 --- a/src/integration-test/groovy/au/org/ala/profile/SearchServiceSpec.groovy +++ b/src/integration-test/groovy/au/org/ala/profile/SearchServiceSpec.groovy @@ -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 @@ -14,6 +15,8 @@ class SearchServiceSpec extends BaseIntegrationSpec { SearchService service @Autowired Datastore datastore + @Autowired + ElasticSearchService elasticSearchService Closure doWithSpring () { System.println("Test") @@ -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 + } }