Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#744 #34

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@
package au.org.ala.profile

import au.org.ala.profile.util.ProfileSortOption
import au.org.ala.profile.util.SearchOptions
import au.org.ala.web.AuthService
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 +16,8 @@ class SearchServiceSpec extends BaseIntegrationSpec {
SearchService service
@Autowired
Datastore datastore
@Autowired
ElasticSearchService elasticSearchService

Closure doWithSpring () {
System.println("Test")
Expand Down Expand Up @@ -1754,4 +1758,80 @@ class SearchServiceSpec extends BaseIntegrationSpec {
result.size() == 1
result[0].childCount == 1
}

def "buildTextSearch should include partial single matches from certain collection when the logged in user is an ALA admin"() {
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: "kingdom", classification: [new Classification(rank: "kingdom", name: "Plantae")])

service.userService.userInRole("ROLE_ADMIN") >> true
service.userService.getCurrentUserDetails() >> [userId: "1234"]

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)


Map params = [
indices: Profile,
types: Profile,
score: true,
from : 0,
size : 20
]

when:
Map qMap = service.buildTextSearch("dilan", options)
def result = elasticSearchService.search(params, qMap.query, null)

then:
result.searchResults.find { it.toString().contains(profile1.scientificName) } != null
}

def "buildTextSearch should include partial multiple matches from certain collection when the logged in user is an ALA admin"() {
given:

String term = "BURDAL TOTEM"
service.userService.userInRole("ROLE_ADMIN") >> true
service.userService.getCurrentUserDetails() >> [userId: "1234"]

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)


Map params = [
indices: Profile,
types: Profile,
score: true,
from : 0,
size : 20
]

when:
Map qMap = service.buildTextSearch(term, options)
def result = elasticSearchService.search(params, qMap.query, null)

then:
boolean isFind = false

for (r in result.searchResults) {
List texts = r.attributes.text
for (text in texts) {
isFind = text.contains(term) || isFind
}
}

result.searchResults.size() > 0 && isFind
}
}
Loading