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 6 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,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,77 @@ 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")])
Profile result = save new Profile(scientificName: "Dilany", fullName: "Dilany", opus: opus1, rank: "species")

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("dilan")) != null
result.find { it.contains(profile1.scientificName) } != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not think result, profile1 or opus1 is needed. remove them.

}

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: "name1", opus: opus1, rank: "species", classification: [new Classification(rank: "kingdom", name: "Plantae")])
Vocab vocab1 = save new Vocab(uuid:"1234-5678-0000",name:"vocab1",strict:false)
Term term1 = save new Term(uuid:"4ddb6096-0bf1-4c94-8bfb-86b99e79c08e",name:"test",groupBy:null,dataType:"text",unit:null,constraintListVocab:null,order:-1,required:false,summary:false,containsName:false,id:220,verison:null,vocab:vocab1)

List attributes = new ArrayList()
Attribute attribute1 = new Attribute()
attribute1.title = term1
attribute1.text = "<p>Lives in low rocky hills, cliffs and gorges. The Rangers often find them on the night cameras.</p>"
attribute1.profile = profile1
attributes.add(attribute1)

Attribute attribute2 = new Attribute()
attribute2.title = term1
attribute2.text = "<p>BURDAL TOTEM - Ask Burdal Elders for more cultural knowledge</p>"
attribute2.profile = profile1
attributes.add(attribute2)

Profile result = save new Profile(scientificName: "Salt Water Crocodile", fullName: "Salt Water Crocodile", opus: opus1, rank: "species", attributes: attributes)

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:
boolean isFind = false

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

qMap.findAll(it -> it.toString().contains(searchItem)) != null
result && isFind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here result, profile, attributes are not needed. remove them. Only testing on qMap is needed.

}
}
Loading