From 612242ecba2d848d464c2bd102077408d232623e Mon Sep 17 00:00:00 2001 From: Dave Martin Date: Wed, 2 Aug 2017 11:13:45 +0100 Subject: [PATCH] removed hardcoded Australia filter... and added indexing of occurrence counts to enable boosting by popular taxa --- grails-app/conf/Config.groovy | 4 ++++ .../au/org/ala/bie/ImportService.groovy | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/grails-app/conf/Config.groovy b/grails-app/conf/Config.groovy index 39a40abd..5aef99c8 100755 --- a/grails-app/conf/Config.groovy +++ b/grails-app/conf/Config.groovy @@ -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" diff --git a/grails-app/services/au/org/ala/bie/ImportService.groovy b/grails-app/services/au/org/ala/bie/ImportService.groovy index e3561ee2..a616eaa7 100644 --- a/grails-app/services/au/org/ala/bie/ImportService.groovy +++ b/grails-app/services/au/org/ala/bie/ImportService.groovy @@ -611,7 +611,7 @@ class ImportService { log.debug "totalDocs = ${totalDocs} || totalPages = ${totalPages}" log("Processing " + String.format("%,d", totalDocs) + " taxa (via ${paramsMap.q})...
") // 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 { @@ -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 @@ -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 { @@ -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) @@ -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 ) + } } } }