Skip to content

Commit

Permalink
removed hardcoded Australia filter...
Browse files Browse the repository at this point in the history
and added indexing of occurrence counts to enable boosting by popular
taxa
  • Loading branch information
djtfmartin committed Aug 2, 2017
1 parent 991fa20 commit 612242e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ additionalResultFields = ""
//toggle for the population of occurrence counts
occurrenceCounts.enabled = true

//Filter query used to get taxa counts - default for Australia was "country:Australia+OR+cl21:*&fq=geospatial_kosher:true"
// filter on Aust. terristrial and IMCRA marine areas
occurrenceCounts.filterQuery = "&fq=geospatial_kosher:true"

// SOLR additional params
solr {
qf = "exact_text^200+doc_name^100+text"
Expand Down
20 changes: 14 additions & 6 deletions grails-app/services/au/org/ala/bie/ImportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class ImportService {
log.debug "totalDocs = ${totalDocs} || totalPages = ${totalPages}"
log("Processing " + String.format("%,d", totalDocs) + " taxa (via ${paramsMap.q})...<br>") // send to browser

def promiseList = new PromiseList() // for biocaceh queries
def promiseList = new PromiseList() // for biocache queries
Queue commitQueue = new ConcurrentLinkedQueue() // queue to put docs to be indexes
ExecutorService executor = Executors.newSingleThreadExecutor() // consumer of queue - single blocking thread
executor.execute {
Expand All @@ -632,7 +632,7 @@ class ImportService {

// iterate over the result set
resultsDocs.each { doc ->
if (nationalSpeciesDatasets.contains(doc.datasetID)) {
if (nationalSpeciesDatasets && nationalSpeciesDatasets.contains(doc.datasetID)) {
taxaLocatedInHubCountry.add(doc) // in national list so _assume_ it is located in host/hub county
} else {
taxaToSearchOccurrences.add(doc) // search occurrence records to determine if it is located in host/hub county
Expand Down Expand Up @@ -684,6 +684,9 @@ class ImportService {
updateDoc["idxtype"] = ["set": doc.idxtype] // required field
updateDoc["guid"] = ["set": doc.guid] // required field
updateDoc["locatedInHubCountry"] = ["set": true]
if(doc.containsKey("occurrenceCount")){
updateDoc["occurrenceCount"] = ["set": doc["occurrenceCount"]]
}
commitQueue.offer(updateDoc) // throw it on the queue
totalDocumentsUpdated++
} else {
Expand Down Expand Up @@ -753,8 +756,7 @@ class ImportService {
def guidSubset = guids.subList(start,end)
def guidParamList = guidSubset.collect { String guid -> guid.encodeAsURL() } // URL encode guids
def query = "taxon_concept_lsid:\"" + guidParamList.join("\"+OR+taxon_concept_lsid:\"") + "\""
def filterQuery = "country:Australia+OR+cl21:*&fq=geospatial_kosher:true" // filter on Aust. terristrial and IMCRA marine areas
// def postBody = [ q: query, rows: 0, facet: true, "facet.field": "taxon_concept_lsid", "facet.mincount": 1, wt: "json" ] // will be url-encoded
def filterQuery = grailsApplication.config.occurrenceCounts.filterQuery

try {
// def json = searchService.doPostWithParamsExc(grailsApplication.config.biocache.solr.url + "/select", postBody)
Expand All @@ -765,10 +767,16 @@ class ImportService {
JSONObject jsonObj = JSON.parse(queryResponse)

if (jsonObj.containsKey("facet_counts")) {
jsonObj?.facet_counts?.facet_fields?.taxon_concept_lsid?.eachWithIndex { val, idx ->

def facetCounts = jsonObj?.facet_counts?.facet_fields?.taxon_concept_lsid
facetCounts.eachWithIndex { val, idx ->
// facets results are a list with key, value, key, value, etc
if (idx % 2 == 0) {
docsWithRecs.add(docs.find { it.guid == val } )
def docWithRecs = docs.find { it.guid == val }
docWithRecs["occurrenceCount"] = facetCounts[idx + 1] //add the count
if(docWithRecs){
docsWithRecs.add(docWithRecs )
}
}
}
}
Expand Down

0 comments on commit 612242e

Please sign in to comment.