Index: branches/pssGrails3/src/integration-test/groovy/com/lemans/search/MasterProductSearchFunctionalSpec.groovy =================================================================== diff -u -r8825 -r8883 --- branches/pssGrails3/src/integration-test/groovy/com/lemans/search/MasterProductSearchFunctionalSpec.groovy (.../MasterProductSearchFunctionalSpec.groovy) (revision 8825) +++ branches/pssGrails3/src/integration-test/groovy/com/lemans/search/MasterProductSearchFunctionalSpec.groovy (.../MasterProductSearchFunctionalSpec.groovy) (revision 8883) @@ -26,7 +26,6 @@ with(payload) { header.q == productId header.renderers[0] == 'masterProduct' - facets[0].type == 'sg' } } Index: branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrService.groovy =================================================================== diff -u -r8821 -r8883 --- branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrService.groovy (.../SolrService.groovy) (revision 8821) +++ branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrService.groovy (.../SolrService.groovy) (revision 8883) @@ -7,7 +7,8 @@ import javax.annotation.Resource import java.util.regex.Matcher -@SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterReassignment', 'ConfusingTernary', 'ConsecutiveStringConcatenation']) +@SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterReassignment', + 'ConfusingTernary', 'ConsecutiveStringConcatenation', 'ConstantIfExpression']) class SolrService { static transactional = false @@ -26,9 +27,9 @@ def productGroup = Holders.config.search.productGroup.core def inactivePart = Holders.config.search.inactivePart.core - + def masterProduct = Holders.config.search.masterProduct.core - + def searchUtils = new SearchUtils() //def searchTermLogger = LogFactory.getLog("searchTermsLogger") @@ -61,16 +62,16 @@ String queryParams = buildQuery(params, criteria.sortBys, fl, fqQueryString, format) String totalRecordsString = '"numFound":0' String solrResponse = createDisMaxCriteriaAndCallSolr(queryParams, criteria.term, criteria.sortedRelevency, core, totalRecordsString) - SortBy sortBy = populateSortBy(criteria.sortBys, params) PartSearchResponse psResponse = new PartSearchResponse() psResponse.header.sortBy = sortBy solrResponseService.processJSON(params, criteria.selectedFacetsMap, criteria.nextFacets, solrResponse, - criteria.renderers, criteria.hitlistDoc, psResponse, - criteria.domainConfigFacets, criteria.uiConfig) + criteria.renderers, criteria.sortBys, criteria.hitlistDoc, psResponse, criteria.selectedConfigFacets, + criteria.domainConfigFacets, criteria.uiConfig) + } - private Map getCriteria(Map params) { + private Map getCriteria(params) { Map selectedFacetsMap = solrRequestService.getSelectedFacets(params) Set selectedFacets = selectedFacetsMap.keySet() def term = nullToGenricSearch(params.q) @@ -82,10 +83,11 @@ List sortBys = uiConfig.sortBys ?: [] List sortedRelevency = uiConfig.relevancy.list().sort { -it.weight.toDouble() } def hitlistDoc = uiConfig.hitlistDoc ?: [] - [selectedFacetsMap: selectedFacetsMap, selectedFacets: selectedFacets, term: term, uiConfig: uiConfig, - domainConfigFacets: domainConfigFacets, selectedConfigFacets: selectedConfigFacets, - nextFacets: nextFacets, renderers: renderers, sortBys: sortBys, sortedRelevency: sortedRelevency, - hitlistDoc: hitlistDoc] + [selectedFacetsMap: selectedFacetsMap, selectedFacets: selectedFacets, + term: term, uiConfig: uiConfig, domainConfigFacets: domainConfigFacets, + selectedConfigFacets: selectedConfigFacets, + nextFacets: nextFacets, renderers: renderers, sortBys: sortBys, sortedRelevency: sortedRelevency, + hitlistDoc: hitlistDoc] } String processTerm(String term) { @@ -99,9 +101,9 @@ private String buildQuery(params, List sortBys, String fl, String fqQueryString, String format) { def pagination = solrResponseService.getPaginationQueryString(params.rows, params.offset) def sortOption = solrResponseService.getSortingQS(params.sb, sortBys) - String f2 = addOutfields(params, fl) - def queryParams = "&${fqQueryString}&wt=${format}${pagination}${sortOption}&f2=${f2}&spellcheck=true&spellcheck.collate=true" - queryParams + fl = addOutfields(params, fl) + def queryParams = "&${fqQueryString}&wt=${format}${pagination}${sortOption}&fl=${fl}&spellcheck=true&spellcheck.collate=true" + queryParams } private String addOutfields(params, String fl) { @@ -128,7 +130,7 @@ core = "${inactivePart}" break case 'fitment': - //still go to part core but do not bring back docs + //still go to part core but do not bring back docs core = "${partCore}" break case 'productGroup': @@ -142,37 +144,34 @@ break } } - core + core } private String createDisMaxCriteriaAndCallSolr(String queryParams, String term, List sortedRelevency, - String core, String totalRecordsString) { + String core, String totalRecordsString) { def solrResponse def disMaxQuery - String coreUrl = solrPrefix + "/${core}/select/" - String term2 = processTerm(term) - String queryParams2 = '' - if (term2.charAt(0) == ('-')) { - // if (false) { //IST-6626: if search term contains a '-' + term = processTerm(term) + if (false) { //IST-6626: if search term contains a '-' if (core == 'inactivePart') { disMaxQuery = createDisMaxCriteriaForInactivePunctuatedPartNumber() - queryParams2 = "q=${term2.toUpperCase()}&${disMaxQuery}&" + queryParams + queryParams = "q=${term.toUpperCase()}&${disMaxQuery}&" + queryParams } else { disMaxQuery = createDisMaxCriteriaForPunctuatedPartNumber() - queryParams2 = "q=${term2.toLowerCase()}&${disMaxQuery}&" + queryParams + queryParams = "q=${term.toLowerCase()}&${disMaxQuery}&" + queryParams } solrResponse = searchUtils.callSolr(coreUrl, queryParams) } else { //search term without '-' in it (normal way) if (core == 'inactivePart') { disMaxQuery = createDisMaxCriteriaForInactivePartNumber() - queryParams2 = "q=${term.toUpperCase()}&${disMaxQuery}&" + queryParams + queryParams = "q=${term.toUpperCase()}&${disMaxQuery}&" + queryParams } else { disMaxQuery = createDisMaxGeneralCriteria(sortedRelevency) - queryParams2 = "q=${term.toLowerCase()}&${disMaxQuery}&" + queryParams + queryParams = "q=${term.toLowerCase()}&${disMaxQuery}&" + queryParams } - solrResponse = searchUtils.callSolr(coreUrl, queryParams2) + solrResponse = searchUtils.callSolr(coreUrl, queryParams) } def numFound @@ -182,8 +181,8 @@ //IN CASE OF NO RESUTLS, SEARCH BY DISMAX_TEXT_TERM (use white space tokenizer) if (solrResponse.toString() == '0' && core != 'inactivePart') { disMaxQuery = createDisMaxTermCriteria(sortedRelevency) - queryParams2 = "q=${term.toLowerCase()}&${disMaxQuery}&" + queryParams - solrResponse = searchUtils.callSolr(coreUrl, queryParams2) + queryParams = "q=${term.toLowerCase()}&${disMaxQuery}&" + queryParams + solrResponse = searchUtils.callSolr(coreUrl, queryParams) } solrResponse } @@ -207,53 +206,53 @@ sortBys.each { sb -> sortBy.options.add(new Value(id: sb.id.toString(), name: sb.name.toString())) } - sortBy + sortBy } def createDisMaxCriteriaForPunctuatedPartNumber() { - createDisMaxQuery(['punctuatedPartNumber_text', 'vendorPunctuatedPartNumber_text', - 'oemPartNumber_text', 'oemPunctuatedPartNumber_text', 'xrefPunctuatedPartNumber_text'].join('+')) + createDisMaxQuery(['punctuatedPartNumber_text', 'vendorPunctuatedPartNumber_text', + 'oemPartNumber_text', 'oemPunctuatedPartNumber_text', 'xrefPunctuatedPartNumber_text'].join('+')) } def createDisMaxCriteriaForInactivePunctuatedPartNumber() { - createDisMaxQuery(['punctuatedPartNumber', 'vendorPunctuatedPartNumber', 'oemPunctuatedPartNumber'].join('+')) + createDisMaxQuery(['punctuatedPartNumber', 'vendorPunctuatedPartNumber', 'oemPunctuatedPartNumber'].join('+')) } def createDisMaxCriteriaForInactivePartNumber() { - createDisMaxQuery(['punctuatedPartNumber', 'vendorPunctuatedPartNumber', 'oemPunctuatedPartNumber', - 'partNumber', 'vendorPartNumber', 'oemPartNumber'].join('+')) + createDisMaxQuery(['punctuatedPartNumber', 'vendorPunctuatedPartNumber', 'oemPunctuatedPartNumber', + 'partNumber', 'vendorPartNumber', 'oemPartNumber'].join('+')) } /** * Skip certain fields as search criteria for dismax parser. These fields are added in schema - * as special search able fields. Their type is 'text_partial' + * as special search able fields. Their type is 'text_partial' * @param sortedRelevency * @return */ //IST-6626 def createDisMaxTermCriteria(sortedRelevency) { List excludeItems = ['vendorPartNumber', 'vendorPunctuatedPartNumber', 'partNumber', 'punctuatedPartNumber', - 'oemPartNumber', 'oemPunctuatedPartNumber', 'year'] + 'oemPartNumber', 'oemPunctuatedPartNumber', 'year'] def termRelevencyList = [] sortedRelevency.each { item -> - if (!excludeItems.contains(item.name)) { + if (!excludeItems.contains(item.name)) { termRelevencyList.add(item) } } def disMaxCriteria = termRelevencyList.collect { field -> - "${field.name}${field.name != 'text' ? '_text_term' : ''}" + '^' + "${field.weight}" }.join('+') - createDisMaxQuery(disMaxCriteria) + "${field.name}${field.name != 'text' ? '_text_term' : ''}" + '^' + "${field.weight}" }.join('+') + createDisMaxQuery(disMaxCriteria) } def createDisMaxGeneralCriteria(sortedRelevency) { def disMaxCriteria = sortedRelevency.collect { field -> - "${field.name}${field.name != 'text' ? '_text' : ''}" + '^' + "${field.weight}" }.join('+') - createDisMaxQuery(disMaxCriteria) + "${field.name}${field.name != 'text' ? '_text' : ''}" + '^' + "${field.weight}" }.join('+') + createDisMaxQuery(disMaxCriteria) } def createDisMaxQuery(String disMaxCriteria) { - "defType=edismax&qf=${disMaxCriteria}&pf=${disMaxCriteria}" + "defType=edismax&qf=${disMaxCriteria}&pf=${disMaxCriteria}" } def runAutoSuggestQuery(params) { @@ -283,7 +282,7 @@ def autoSuggestSelectUrl = solrPrefix + '/solrSuggest/select/' def result = searchUtils.callSolr(autoSuggestSelectUrl, queryParams) - processAutoSuggestResponse(params.dm, result) + processAutoSuggestResponse(params.dm, result) } @@ -306,7 +305,7 @@ quickSearch.catalogProductDivisionData = parseFacet(facetFields, 'pr', domain, null, null) quickSearch.catalogCategoryDivisionData = getCategoryDivisionData(facetFields, domain) - quickSearch.quickSearchResponse() + quickSearch.quickSearchResponse() } /** * parse solr response for constructing Category division for auto Suggest. @@ -323,7 +322,7 @@ ciMap.put(it.id, it.name) } def category1Data = parseFacet(facetFields, 'ct1', domain, null, ciMap) - Map ct1Map = new TreeMap() + Map ct1Map = new TreeMap() category1Data.each { def str = it.name.split('>> ') ct1Map.put(it.id, str[1]) @@ -334,12 +333,12 @@ } categoryDivisionData.addAll(category1Data) def mc = [ - compare: { a, b -> - a == (b)? 0 : Math.abs(a.count) > Math.abs(b.count) ? -1 : 1 - } - ] as Comparator + compare: { a, b -> + a == (b)? 0 : Math.abs(a.count) > Math.abs(b.count) ? -1 : 1 + } + ] as Comparator Collections.sort(categoryDivisionData, mc) - categoryDivisionData + categoryDivisionData } /** * Masks division Values to the Division Object and constructs the Solr suggest response @@ -361,7 +360,7 @@ def parsePartInfo(def responceDoc) { def partInfo = [] responceDoc.each { st -> partInfo << " ${st['partNumber']}-${st['partDescr']}" } - partInfo + partInfo } /** * This method builds the division values for all the solr Suggest division like Catalog, brand and product. @@ -409,7 +408,7 @@ Matcher matcher = exp =~ /^$dm\|(\d+)\|(\d+)\|(\d+)\|(\d+)\|(.+)$/ if (matcher.find()) { def dispName = ciMap[matcher.group(1)] + ' >> ' + ct1Map[matcher.group(2)] + ' >> ' - + ct1Map[matcher.group(3)] + ' >> ' + matcher.group(5) + + ct1Map[matcher.group(3)] + ' >> ' + matcher.group(5) value.id = matcher.group(4) value.name = dispName } @@ -418,7 +417,7 @@ Matcher matcher = exp =~ /^$dm\|(\d+)\|(\d+)\|(\d+)\|(\d+)\|(\d+)\|(.+)$/ if (matcher.find()) { def dispName = ciMap[matcher.group(1)] + ' >> ' + ct1Map[matcher.group(2)] + - ' >> ' + ct1Map[matcher.group(3)] + ' >> ' + ct1Map[matcher.group(4)] + ' >> ' + matcher.group(6) + ' >> ' + ct1Map[matcher.group(3)] + ' >> ' + ct1Map[matcher.group(4)] + ' >> ' + matcher.group(6) value.id = matcher.group(5) value.name = dispName } Index: branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrResponseService.groovy =================================================================== diff -u -r8825 -r8883 --- branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrResponseService.groovy (.../SolrResponseService.groovy) (revision 8825) +++ branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrResponseService.groovy (.../SolrResponseService.groovy) (revision 8883) @@ -1,15 +1,20 @@ package com.lemanscorp.search.solr -import com.lemanscorp.search.SearchException + import grails.converters.JSON -import org.json.JSONObject import java.util.regex.Matcher import java.util.regex.Pattern -@SuppressWarnings(['AbcMetric', 'ExplicitCallToGetAtMethod', 'NestedBlockDepth', 'ExplicitCallToMinusMethod', 'ParameterReassignment', - 'ThrowRuntimeException', 'ParameterCount', 'Instanceof', 'CyclomaticComplexity', 'LoggingSwallowsStacktrace', 'CatchException', -'UnnecessaryObjectReferences']) +import org.grails.web.json.JSONObject + +import com.lemanscorp.search.SearchException +import com.lemanscorp.search.SearchUtils + +@SuppressWarnings([ 'AbcMetric', 'CyclomaticComplexity', 'ParameterCount', 'ExplicitCallToGetAtMethod', + 'NestedBlockDepth', 'ParameterReassignment', 'UnnecessaryObjectReferences', + 'ExplicitCallToMinusMethod', 'DuplicateCaseStatement', 'InstanceOf', 'InvertedIfElse', + 'CatchException', 'UnusedMethodParameter', 'Instanceof']) class SolrResponseService { @@ -18,7 +23,7 @@ def solrService - //SearchUtils searchUtils =new SearchUtils() +// SearchUtils searchUtils =new SearchUtils() /** * @@ -33,13 +38,14 @@ * @param selectedConfigFacets - to get the display name and sequence from database config. * @return */ - PartSearchResponse processJSON(params, selectedFacetsMap, nextFacets, solrResponse, renderers, - hitlistDoc, psResponse, domainConfigFacets, uiConfig) { + PartSearchResponse processJSON(params, selectedFacetsMap, nextFacets, solrResponse, + renderers, sortBys, hitlistDoc, psResponse, selectedConfigFacets, + domainConfigFacets, uiConfig) { def solrJson = JSON.parse(solrResponse) /* Header */ - List selectedFCs = populateSelectedFacets(params, selectedFacetsMap, solrJson, domainConfigFacets) + List selectedFCs = populateSelectedFacets(params, selectedFacetsMap, solrJson, selectedConfigFacets, domainConfigFacets) Header header = psResponse.header //set original search term in response as we are sending solr query syntax in q field now. @@ -50,13 +56,13 @@ header.start = solrJson.response.start header.facets = selectedFCs //set requested page numbers - //selected start and end page + //selected start and end page // header.pageNumbers.pageStart = params.pageStart // header.pageNumbers.pageEnd = params.pageEnd header.pageNumbers.pn = params.pn - //context (could be ci or ct*) - start and end page - header.pageNumbers.contextPageStart = uiConfig?.contextPageStart - header.pageNumbers.contextPageEnd = uiConfig?.contextPageEnd + //context (could be ci or ct*) - start and end page + header.pageNumbers.contextPageStart = uiConfig?.contextPageStart + header.pageNumbers.contextPageEnd = uiConfig?.contextPageEnd //echo back the query params for search fields. Currently on search fields e.g. sf_partNumber are echoed back. params?.keySet()?.findAll { it?.startsWith('sf_') }.collect { @@ -81,13 +87,13 @@ if (item == 'collation') { collations.addAll(suggestions.getAt(i + 1)) } else if (item instanceof JSONObject) { - suggestionsList.addAll(item?.suggestion?.toArray()) + suggestionsList.addAll(item?.suggestion?.toArray()) } } def collation = solrJson.spellcheck?.collations collation.eachWithIndex { item, i -> if (item == 'collation') { - collations.addAll(collation[((i + 1))]) + collations.addAll(collation.getAt(i + 1)) } } header.spellcheck = ['collation': collations , suggestions: suggestionsList] @@ -100,28 +106,28 @@ /* Based on renderer populate hitlist & total count */ renderers.each { renderer -> switch (renderer) { - case 'part': - header.total = solrJson.response.numFound - if (params?.outfields) { - psResponse.hitlist.parts = solrJson.response?.docs - } else { - psResponse.hitlist.parts = processPartResponse(solrJson) - } - break - case 'inactivePart': - header.total = solrJson.response.numFound - if (params?.outfields) { - psResponse.hitlist.parts = solrJson.response?.docs - } else { - psResponse.hitlist.parts = processPartResponse(solrJson) - } - break - case 'fitment': - header.total = solrJson.response.numFound - //do not need hitlist for this doc type - psResponse.hitlist.fitments = [] - break - case 'product': + case 'part': + header.total = solrJson.response.numFound + if (params?.outfields) { + psResponse.hitlist.parts = solrJson.response?.docs + } else { + psResponse.hitlist.parts = processPartResponse(solrJson) + } + break + case 'inactivePart': + header.total = solrJson.response.numFound + if (params?.outfields) { + psResponse.hitlist.parts = solrJson.response?.docs + } else { + psResponse.hitlist.parts = processPartResponse(solrJson) + } + break + case 'fitment': + header.total = solrJson.response.numFound + //do not need hitlist for this doc type + psResponse.hitlist.fitments = [] + break + case 'product': //set the total properties to header for products. This will overwrite the parts total count header.total = solrJson.response.numFound //set the products @@ -131,44 +137,43 @@ } else { psResponse.hitlist.products = processProductResponse(solrJson) } - break - case 'masterProduct': + break + case 'masterProduct': header.total = solrJson.response.numFound psResponse.hitlist.type = 'mpr' if (params?.outfields) { psResponse.hitlist.masterProducts = solrJson.response?.docs } else { psResponse.hitlist.masterProducts = processProductResponse(solrJson) } - break - case 'productGroup': - //set the total properties to header for products. This will overwrite the parts total count - header.total = solrJson.response.numFound - //set the products - psResponse.hitlist.type = 'prg' - if (params?.outfields) { - psResponse.hitlist.productGroups = solrJson.response?.docs - } else { - psResponse.hitlist.productGroups = processProductGroupResponse(solrJson) - } - break + break + case 'productGroup': + //set the total properties to header for products. This will overwrite the parts total count + header.total = solrJson.response.numFound + //set the products + psResponse.hitlist.type = 'prg' + if (params?.outfields) { + psResponse.hitlist.productGroups = solrJson.response?.docs + } else { + psResponse.hitlist.productGroups = processProductGroupResponse(solrJson) + } + break case 'category': def ct = solrRequestService.getNextCategory(params) psResponse.hitlist.type = "$ct" header.total = hitlistDoc.categories.catalog.size() psResponse.hitlist.categories = processCategoryResponse(hitlistDoc) - break + break case 'catalog': psResponse.hitlist.type = 'ci' header.total = hitlistDoc.catalogs.catalog.size() psResponse.hitlist.catalogs = processCatalogResponse(hitlistDoc) - break + break - default: - break + default: + break } } - psResponse } @@ -180,87 +185,256 @@ * @param solrJson * @return */ - List populateSelectedFacets(params, selectedFacetsMap, solrJson, domainConfigFacets) { + List populateSelectedFacets(params, selectedFacetsMap, solrJson, selectedConfigFacets, domainConfigFacets) { def retFeatures = [] - def avMap = [:] + def avMap = [:] - def selectedFacets = selectedFacetsMap.keySet() + def selectedFacets = selectedFacetsMap.keySet() - def jsonFacetFields = solrJson.facet_counts.facet_fields + def jsonFacetFields = solrJson.facet_counts.facet_fields - def dm = params.dm ? params.dm : '\\d*' - def ci = selectedFacetsMap.get('ci') ? selectedFacetsMap.get('ci').join('|') : '\\d*' - def ct1 = selectedFacetsMap.get('ct1') ? selectedFacetsMap.get('ct1').join('|') : '\\d*' - def ct2 = selectedFacetsMap.get('ct2') ? selectedFacetsMap.get('ct2').join('|') : '\\d*' - //def ct3 = selectedFacetsMap.get('ct3') ? selectedFacetsMap.get('ct3').join('|') : '\\d*' - //def yrs = selectedFacetsMap.get('yr') ? selectedFacetsMap.get('yr').join('|') : null - //def mds = selectedFacetsMap.get('md') ? selectedFacetsMap.get('md').join('|') : null - //def mks = selectedFacetsMap.get('mk') ? selectedFacetsMap.get('mk').join('|') : null - //def pr = params.pr ? params.pr : null - def pns = selectedFacetsMap.get('pn') ? selectedFacetsMap.get('pn').join('|') : '\\d*' + def dm = params.dm ? params.dm : '\\d*' + def ci = selectedFacetsMap.get('ci') ? selectedFacetsMap.get('ci').join('|') : '\\d*' + def ct1 = selectedFacetsMap.get('ct1') ? selectedFacetsMap.get('ct1').join('|') : '\\d*' + def ct2 = selectedFacetsMap.get('ct2') ? selectedFacetsMap.get('ct2').join('|') : '\\d*' +// def ct3 = selectedFacetsMap.get('ct3') ? selectedFacetsMap.get('ct3').join('|') : '\\d*' +// def yrs = selectedFacetsMap.get('yr') ? selectedFacetsMap.get('yr').join('|') : null +// def mds = selectedFacetsMap.get('md') ? selectedFacetsMap.get('md').join('|') : null +// def mks = selectedFacetsMap.get('mk') ? selectedFacetsMap.get('mk').join('|') : null +// def pr = params.pr ? params.pr : null + def pns = selectedFacetsMap.get('pn') ? selectedFacetsMap.get('pn').join('|') : '\\d*' - //create patterns - //def ci_pattern = Pattern.compile(/^$dm\|($ci)\|(.+)$/) + //create patterns +// def ci_pattern = Pattern.compile(/^$dm\|($ci)\|(.+)$/) - selectedFacets.minus(['dm', 'av', 'pr']).each { selectedFacet -> + selectedFacets.minus(['dm', 'av', 'pr']).each { selectedFacet -> def exp // try { - def cnt - def facets - def selectedFacetIds - def selectedIds - Facet facet - Matcher matcher - def pattern - //def selectedFacetConfig = selectedConfigFacets.find {it.abbr == selectedFacet} - def domainFacetconfig - //create pre-compiled pattern based on the selected facet - /* Fix for AVP's */ - if (selectedFacet.startsWith('av')) { - selectedFacetIds = selectedFacet.minus('av') - selectedIds = selectedFacetsMap.get(selectedFacet).join('|') - selectedFacet = 'av' - facets = jsonFacetFields.'av_FC' - pattern = Pattern.compile(/^($selectedFacetIds)\|(.+)\|($selectedIds)\|(.+)$/) + def cnt + def facets + def selectedFacetIds + def selectedIds + Facet facet + Matcher matcher + def pattern + //def selectedFacetConfig = selectedConfigFacets.find {it.abbr == selectedFacet} + def domainFacetconfig + //create pre-compiled pattern based on the selected facet + /* Fix for AVP's */ + if (selectedFacet.startsWith('av')) { + selectedFacetIds = selectedFacet.minus('av') + selectedIds = selectedFacetsMap.get(selectedFacet).join('|') + selectedFacet = 'av' + facets = jsonFacetFields.'av_FC' + pattern = Pattern.compile(/^($selectedFacetIds)\|(.+)\|($selectedIds)\|(.+)$/) - } else { - domainFacetconfig = solrService.findDomainConfigFor(selectedFacet, domainConfigFacets) - facet = new Facet(type: "${selectedFacet}" - , name: domainFacetconfig?.displayName - , seq: domainFacetconfig?.sequence ?: 0 - , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator - , isMultiSelect: domainFacetconfig?.isMultiSelect) + } else { + domainFacetconfig = solrService.findDomainConfigFor(selectedFacet, domainConfigFacets) + facet = new Facet(type: "${selectedFacet}" + , name: domainFacetconfig?.displayName + , seq: domainFacetconfig?.sequence ?: 0 + , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator + , isMultiSelect: domainFacetconfig?.isMultiSelect) - selectedIds = selectedFacetsMap.get(selectedFacet).join('|') - facets = jsonFacetFields."${selectedFacet}_FC" - if (selectedFacet == 'ci') { - pattern = Pattern.compile(/^$dm\|($ci)\|(.+)$/) - } else if (selectedFacet == 'ct1') { - pattern = Pattern.compile(/^$dm\|($ci)\|($selectedIds)\|(.+)$/) - } else if (selectedFacet == 'ct2') { - pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($selectedIds)\|(.+)$/) - } else if (selectedFacet == 'ct3') { - pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|($selectedIds)\|(.+)$/) - } else if (selectedFacet == 'ct4') { - // this isn't entirely correct because it is possible to have selected Id's that belong to other selected facet Id's - pattern = Pattern.compile(/^($selectedFacetIds)\|(.+)\|($selectedIds)\|(.+)$/) - } else if (selectedFacet == 'pn') { - pattern = Pattern.compile(/^$ci\|($pns)$/) - } else { - pattern = Pattern.compile(/^($selectedIds)\|(.+)$/) - } + selectedIds = selectedFacetsMap.get(selectedFacet).join('|') + facets = jsonFacetFields."${selectedFacet}_FC" + if (selectedFacet == 'ci') { + pattern = Pattern.compile(/^$dm\|($ci)\|(.+)$/) + } else if (selectedFacet == 'ct1') { + pattern = Pattern.compile(/^$dm\|($ci)\|($selectedIds)\|(.+)$/) + } else if (selectedFacet == 'ct2') { + pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($selectedIds)\|(.+)$/) + } else if (selectedFacet == 'ct3') { + pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|($selectedIds)\|(.+)$/) + } else if (selectedFacet == 'ct4') { + // this isn't entirely correct because it is possible to have selected Id's that belong to other selected facet Id's + pattern = Pattern.compile(/^($selectedFacetIds)\|(.+)\|($selectedIds)\|(.+)$/) + } else if (selectedFacet == 'pn') { + pattern = Pattern.compile(/^$ci\|($pns)$/) + } else { + pattern = Pattern.compile(/^($selectedIds)\|(.+)$/) + } + } + + for (int i = 0; i < facets.length(); i = i + 2) { + exp = facets[i] + cnt = facets[i + 1] + + matcher = pattern.matcher(exp) + if (matcher.find()) { + switch (selectedFacet) { + case 'ci': + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) + break + case 'ct1': + facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) + break + case 'ct2': + facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) + break + case 'ct3': + facet.values.add(new Value(id: matcher.group(4), name: matcher.group(5), count: cnt)) + break + case 'ct4': + facet.values.add(new Value(id: matcher.group(5), name: matcher.group(6), count: cnt)) + break + case 'ci': + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(1), count: cnt)) + case 'pn': + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(1), count: cnt)) + break + case 'av': + domainFacetconfig = solrService.findDomainConfigFor(selectedFacet, domainConfigFacets) + String key = "${selectedFacet}${matcher.group(1)}" + facet = avMap.get(key) + if (!facet) { + facet = new Facet(type: key + , name: matcher.group(2) + , seq: domainFacetconfig?.sequence + , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator + , isMultiSelect: domainFacetconfig?.isMultiSelect) + avMap.put(key, facet) + } + facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) + break + default: + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) } + } + } + if (facet) { + retFeatures.add(facet) + } +// } catch (Exception exception){ +// log.error "Exception while processing the header " + exception +// exception.printStackTrace() +// throw new SearchException(exception, "Exception while processing selected header for facet ${selectedFacet} with value ${exp}") +// } + //sort the selected facets + retFeatures.sort { it.seq } + } + //nullify temp map to track avp facets + avMap = null + retFeatures + } + + List populateNextFacets(params, selectedFacetsMap, nextFacets, solrJson, domainConfigFacets) { + + //[av, ci, ct, mk, yr] + def retFeatures = [] + def avMap = [:] + def jsonFacetFields = solrJson.facet_counts.facet_fields + + def dm = params.dm ? params.dm : '\\d*' + def ci = selectedFacetsMap.get('ci') ? selectedFacetsMap.get('ci').join('|') : '\\d*' + def ct1 = selectedFacetsMap.get('ct1') ? selectedFacetsMap.get('ct1').join('|') : '\\d*' + def ct2 = selectedFacetsMap.get('ct2') ? selectedFacetsMap.get('ct2').join('|') : '\\d*' + def ct3 = selectedFacetsMap.get('ct3') ? selectedFacetsMap.get('ct3').join('|') : '\\d*' + def yrs = selectedFacetsMap.get('yr') ? selectedFacetsMap.get('yr').join('|') : null + def mds = selectedFacetsMap.get('md') ? selectedFacetsMap.get('md').join('|') : null + def mks = selectedFacetsMap.get('mk') ? selectedFacetsMap.get('mk').join('|') : null +// def pr = params.pr ? params.pr : null + def domainFacetconfig + def exp + nextFacets.each { nextFacet -> + def nextFacetAbbr = nextFacet.abbr + try { + def cnt + def facets +// def selectedIds + Pattern pattern + + if (nextFacetAbbr == 'ct') { + if (selectedFacetsMap.get('ct3')) { + facets = jsonFacetFields.'ct4_FC' + pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|($ct3)\|(\d+)\|(.+)$/) + nextFacetAbbr = 'ct4' + } else if (selectedFacetsMap.get('ct2')) { + facets = jsonFacetFields.'ct3_FC' + pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|(\d+)\|(.+)$/) + nextFacetAbbr = 'ct3' + } else if (selectedFacetsMap.get('ct1')) { + facets = jsonFacetFields.'ct2_FC' + pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|(\d+)\|(.+)$/) + nextFacetAbbr = 'ct2' + } else if (selectedFacetsMap.get('ci')) { + facets = jsonFacetFields.'ct1_FC' + pattern = Pattern.compile(/^$dm\|($ci)\|(\d+)\|(.+)$/) + nextFacetAbbr = 'ct1' + } + } else if (nextFacetAbbr == 'mk') { + if (mds && yrs) { + facets = jsonFacetFields.'mk_yr_md_FC' + pattern = Pattern.compile(/^(\d+)\|(.+)\|($yrs)\|($mds)\|(.+)$/) + } else if (yrs) { + facets = jsonFacetFields.'yr_mk_FC' + pattern = Pattern.compile(/^($yrs)\|(\d+)\|(.+)$/) + } else { + facets = jsonFacetFields.'mk_FC' + pattern = Pattern.compile(/^(\d*)\|(.*)$/) + } + } else if (nextFacetAbbr == 'yr') { + if (mks && mds) { + facets = jsonFacetFields.'mk_yr_md_FC' + pattern = Pattern.compile(/^($mks)\|(.+)\|(\d+)\|($mds)\|(.+)$/) + } else if (mks) { + facets = jsonFacetFields.'mk_yr_FC' + pattern = Pattern.compile(/^($mks)\|(\d+)\|(.+)$/) + } else { + facets = jsonFacetFields.'yr_FC' + pattern = Pattern.compile(/^(\d*)\|(.*)$/) + } + } else if (nextFacetAbbr == 'md') { + if (mks && yrs) { + facets = jsonFacetFields.'mk_yr_md_FC' + pattern = Pattern.compile(/^($mks)\|(.+)\|($yrs)\|(\d+)\|(.+)$/) + } else if (mks) { + facets = jsonFacetFields.'mk_md_FC' + pattern = Pattern.compile(/^($mks)\|(\d+)\|(.+)$/) + } else if (yrs) { + facets = jsonFacetFields.'yr_md_FC' + pattern = Pattern.compile(/^($yrs)\|(\d+)\|(.+)$/) + } else { + facets = jsonFacetFields.'md_FC' + pattern = Pattern.compile(/^(\d*)\|(.*)$/) + } + } else if (nextFacetAbbr == 'pn') { + facets = jsonFacetFields."${nextFacetAbbr}_FC" + pattern = Pattern.compile(/^$ci\|(.+)$/) + } else { + facets = jsonFacetFields."${nextFacetAbbr}_FC" + if (nextFacetAbbr == 'ci') { + pattern = Pattern.compile(/^$dm\|(\d+)\|(.+)$/) + } else if (nextFacetAbbr == 'av') { + pattern = Pattern.compile(/^(\d+)\|(.+)\|(\d+)\|(.+)$/) + } else { + pattern = Pattern.compile(/^([A-Za-z0-9-]*)\|(.*)$/) + } + } + domainFacetconfig = solrService.findDomainConfigFor(nextFacetAbbr, domainConfigFacets) + + Facet facet = new Facet(type: nextFacetAbbr + , name: domainFacetconfig?.displayName + , seq: domainFacetconfig?.sequence ?: 0 + , resultSortOrder: domainFacetconfig?.resultSortOrder + , resultListCount: domainFacetconfig?.resultListCount + , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator + , isMultiSelect: domainFacetconfig?.isMultiSelect ) + + Matcher matcher + def ftMap = [:] + //for some reason invalid combination is entered .eg. ct2 without ct1 + if (facets) { for (int i = 0; i < facets.length(); i = i + 2) { exp = facets[i] cnt = facets[i + 1] - - matcher = pattern.matcher(exp) + matcher = pattern.matcher(exp) if (matcher.find()) { - switch (selectedFacet) { + switch (nextFacetAbbr) { case 'ci': facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) break @@ -280,301 +454,134 @@ facet.values.add(new Value(id: matcher.group(1), name: matcher.group(1), count: cnt)) break case 'av': - domainFacetconfig = solrService.findDomainConfigFor(selectedFacet, domainConfigFacets) - String key = "${selectedFacet}${matcher.group(1)}" + String key = "av${matcher.group(1)}" facet = avMap.get(key) if (!facet) { - facet = new Facet(type: key - , name: matcher.group(2) - , seq: domainFacetconfig?.sequence - , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator - , isMultiSelect: domainFacetconfig?.isMultiSelect) - avMap.put(key, facet) - } - facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) - break - default: - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - } - } - } - if (facet) { - retFeatures.add(facet) - } -// } catch (Exception exception){ -// log.error "Exception while processing the header " + exception -// exception.printStackTrace() -// throw new SearchException(exception, "Exception while processing selected header for facet ${selectedFacet} with value ${exp}") -// } - //sort the selected facets - retFeatures.sort { it.seq } - - } - //nullify temp map to track avp facets - avMap = null - retFeatures - } - - List populateNextFacets(params, selectedFacetsMap, nextFacets, solrJson, domainConfigFacets) { - - //[av, ci, ct, mk, yr] - def retFeatures = [] - def avMap = [:] - def jsonFacetFields = solrJson.facet_counts.facet_fields - - def dm = params.dm ? params.dm : '\\d*' - def ci = selectedFacetsMap.get('ci') ? selectedFacetsMap.get('ci').join('|') : '\\d*' - def ct1 = selectedFacetsMap.get('ct1') ? selectedFacetsMap.get('ct1').join('|') : '\\d*' - def ct2 = selectedFacetsMap.get('ct2') ? selectedFacetsMap.get('ct2').join('|') : '\\d*' - def ct3 = selectedFacetsMap.get('ct3') ? selectedFacetsMap.get('ct3').join('|') : '\\d*' - def yrs = selectedFacetsMap.get('yr') ? selectedFacetsMap.get('yr').join('|') : null - def mds = selectedFacetsMap.get('md') ? selectedFacetsMap.get('md').join('|') : null - def mks = selectedFacetsMap.get('mk') ? selectedFacetsMap.get('mk').join('|') : null - //def pr = params.pr ? params.pr : null - def domainFacetconfig - def exp - nextFacets.each { nextFacet -> - def nextFacetAbbr = nextFacet.abbr - try { - def cnt - def facets - //def selectedIds - Pattern pattern - - if (nextFacetAbbr == 'ct') { - if (selectedFacetsMap.get('ct3')) { - facets = jsonFacetFields.'ct4_FC' - pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|($ct3)\|(\d+)\|(.+)$/) - nextFacetAbbr = 'ct4' - } else if (selectedFacetsMap.get('ct2')) { - facets = jsonFacetFields.'ct3_FC' - pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|($ct2)\|(\d+)\|(.+)$/) - nextFacetAbbr = 'ct3' - } else if (selectedFacetsMap.get('ct1')) { - facets = jsonFacetFields.'ct2_FC' - pattern = Pattern.compile(/^$dm\|($ci)\|($ct1)\|(\d+)\|(.+)$/) - nextFacetAbbr = 'ct2' - } else if (selectedFacetsMap.get('ci')) { - facets = jsonFacetFields.'ct1_FC' - pattern = Pattern.compile(/^$dm\|($ci)\|(\d+)\|(.+)$/) - nextFacetAbbr = 'ct1' - } - } else if (nextFacetAbbr == 'mk') { - if (mds && yrs) { - facets = jsonFacetFields.'mk_yr_md_FC' - pattern = Pattern.compile(/^(\d+)\|(.+)\|($yrs)\|($mds)\|(.+)$/) - } else if (yrs) { - facets = jsonFacetFields.'yr_mk_FC' - pattern = Pattern.compile(/^($yrs)\|(\d+)\|(.+)$/) - } else { - facets = jsonFacetFields.'mk_FC' - pattern = Pattern.compile(/^(\d*)\|(.*)$/) - } - } else if (nextFacetAbbr == 'yr') { - if (mks && mds) { - facets = jsonFacetFields.'mk_yr_md_FC' - pattern = Pattern.compile(/^($mks)\|(.+)\|(\d+)\|($mds)\|(.+)$/) - } else if (mks) { - facets = jsonFacetFields.'mk_yr_FC' - pattern = Pattern.compile(/^($mks)\|(\d+)\|(.+)$/) - } else { - facets = jsonFacetFields.'yr_FC' - pattern = Pattern.compile(/^(\d*)\|(.*)$/) - } - } else if (nextFacetAbbr == 'md') { - if (mks && yrs) { - facets = jsonFacetFields.'mk_yr_md_FC' - pattern = Pattern.compile(/^($mks)\|(.+)\|($yrs)\|(\d+)\|(.+)$/) - } else if (mks) { - facets = jsonFacetFields.'mk_md_FC' - pattern = Pattern.compile(/^($mks)\|(\d+)\|(.+)$/) - } else if (yrs) { - facets = jsonFacetFields.'yr_md_FC' - pattern = Pattern.compile(/^($yrs)\|(\d+)\|(.+)$/) - } else { - facets = jsonFacetFields.'md_FC' - pattern = Pattern.compile(/^(\d*)\|(.*)$/) - } - } else if (nextFacetAbbr == 'pn') { - facets = jsonFacetFields."${nextFacetAbbr}_FC" - pattern = Pattern.compile(/^$ci\|(.+)$/) - } else { - facets = jsonFacetFields."${nextFacetAbbr}_FC" - if (nextFacetAbbr == 'ci') { - pattern = Pattern.compile(/^$dm\|(\d+)\|(.+)$/) - } else if (nextFacetAbbr == 'av') { - pattern = Pattern.compile(/^(\d+)\|(.+)\|(\d+)\|(.+)$/) - } else { - pattern = Pattern.compile(/^([A-Za-z0-9-]*)\|(.*)$/) - } - } - domainFacetconfig = solrService.findDomainConfigFor(nextFacetAbbr, domainConfigFacets) - - Facet facet = new Facet(type: nextFacetAbbr - , name: domainFacetconfig?.displayName - , seq: domainFacetconfig?.sequence ?: 0 - , resultSortOrder: domainFacetconfig?.resultSortOrder - , resultListCount: domainFacetconfig?.resultListCount - , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator - , isMultiSelect: domainFacetconfig?.isMultiSelect ) - - Matcher matcher - def ftMap = [:] - //for some reason invalid combination is entered .eg. ct2 without ct1 - if (facets) { - for (int i = 0; i < facets.length(); i = i + 2) { - exp = facets[i] - cnt = facets[i + 1] - matcher = pattern.matcher(exp) - if (matcher.find()) { - switch (nextFacetAbbr) { - case 'ci': - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - break - case 'ct1': - facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) - break - case 'ct2': - facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) - break - case 'ct3': - facet.values.add(new Value(id: matcher.group(4), name: matcher.group(5), count: cnt)) - break - case 'ct4': - facet.values.add(new Value(id: matcher.group(5), name: matcher.group(6), count: cnt)) - break - case 'pn': - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(1), count: cnt)) - break - case 'av': - String key = "av${matcher.group(1)}" - facet = avMap.get(key) - if (!facet) { - domainFacetconfig = solrService.findDomainConfigFor(nextFacetAbbr, domainConfigFacets) - facet = new Facet(type: key, name: matcher.group(2) + domainFacetconfig = solrService.findDomainConfigFor(nextFacetAbbr, domainConfigFacets) + facet = new Facet(type: key, name: matcher.group(2) , seq: domainFacetconfig.sequence , resultSortOrder: domainFacetconfig.resultSortOrder , resultListCount: domainFacetconfig.resultListCount , valueBooleanOperator: domainFacetconfig?.valueBooleanOperator , isMultiSelect: domainFacetconfig?.isMultiSelect) - avMap.put(key, facet) - } - facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) - break - case 'mk': - if (mds && yrs) { - String key = matcher.group(1) + '|' + matcher.group(2) - def existingCount = ftMap.get(key) - if (existingCount) { - ftMap.put(key, existingCount + cnt) - } else { - ftMap.put(key, cnt) - } - } else if (yrs) { - //avoid duplicate makes for multiple years - if (!facet.values.find { it.id == matcher.group(2) }) { - facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) - } - } else { - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - } - break - case 'yr': - if (mks && mds) { - String key = matcher.group(3) + '|' + matcher.group(3) - def existingCount = ftMap.get(key) - if (existingCount) { - ftMap.put(key, existingCount + cnt) - } else { - ftMap.put(key, cnt) - } - } else if (mks) { - if (!facet.values.find { it.id == matcher.group(2) }) { - facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) - } - } else { - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - } - break - case 'md': - if (mks && yrs) { - String key = matcher.group(4) + '|' + matcher.group(5) - def existingCount = ftMap.get(key) - if (existingCount) { - ftMap.put(key, existingCount + cnt) - } else { - ftMap.put(key, cnt) - } - } else if (mks) { - if (!facet.values.find { it.id == matcher.group(2) }) { - facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) - } - } else if (yrs) { - if (!facet.values.find { it.id == matcher.group(2) }) { - facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) - } - } else { - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - } - break - default: - matcher = pattern.matcher(exp) - if (matcher.find()) { - facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) - } + avMap.put(key, facet) + } + facet.values.add(new Value(id: matcher.group(3), name: matcher.group(4), count: cnt)) + break + case 'mk': + if (mds && yrs) { + String key = matcher.group(1) + '|' + matcher.group(2) + def existingCount = ftMap.get(key) + if (!existingCount) { + ftMap.put(key, cnt) + } else { + ftMap.put(key, existingCount + cnt) } + } else if (yrs) { + //avoid duplicate makes for multiple years + if (!facet.values.find { it.id == matcher.group(2) } ) { + facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) + } + } else { + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) } - } + break + case 'yr': + if (mks && mds) { + String key = matcher.group(3) + '|' + matcher.group(3) + def existingCount = ftMap.get(key) + if (!existingCount) { + ftMap.put(key, cnt) + } else { + ftMap.put(key, existingCount + cnt) + } + } else if (mks) { + if (!facet.values.find { it.id == matcher.group(2) }) { + facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) + } + } else { + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) + } + break + case 'md': + if (mks && yrs) { + String key = matcher.group(4) + '|' + matcher.group(5) + def existingCount = ftMap.get(key) + if (!existingCount) { + ftMap.put(key, cnt) + } else { + ftMap.put(key, existingCount + cnt) + } + } else if (mks) { + if (!facet.values.find { it.id == matcher.group(2) } ) { + facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) + } + } else if (yrs) { + if (!facet.values.find { it.id == matcher.group(2) }) { + facet.values.add(new Value(id: matcher.group(2), name: matcher.group(3), count: cnt)) + } + } else { + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) + } + break + default: + matcher = pattern.matcher(exp) + if (matcher.find()) { + facet.values.add(new Value(id: matcher.group(1), name: matcher.group(2), count: cnt)) + } } - - ftMap.each { it -> - String key = it.key - def values = key.split('\\|') - facet.values.add(new Value(id: values[0], name: values[1], count: it.value)) } - if (facet && nextFacetAbbr != 'av') { - retFeatures.add(facet) - } - } catch (Exception exception) { - log.error 'Exception while processing next facet' + exception - throw new SearchException(exception, "Exception while processing next facet: ${nextFacetAbbr} with value: ${exp}") + } } - } - //add av facet to the facet list - def avpList = avMap.values() as List - def avFacetConfig = domainConfigFacets.find { it.abbr == 'av' } - if (avFacetConfig) { - def attrSortOrderConfig = avFacetConfig.resultSortOrder.split('\\+') - avpList.sort { it."${attrSortOrderConfig[0]}" } - if (attrSortOrderConfig[1] == 'desc') { - Collections.reverse(avpList) + ftMap.each { it -> + String key = it.key + def values = key.split('\\|') + facet.values.add(new Value(id: values[0], name: values[1], count: it.value)) } + if (facet && nextFacetAbbr != 'av') { + retFeatures.add(facet) + } + } catch (Exception exception) { + log.error 'Exception while processing next facet' + exception + throw new SearchException(exception, "Exception while processing next facet: ${nextFacetAbbr} with value: ${exp}") } - retFeatures.addAll(avpList) + } - //TODO: 80% Rule, filter selected facets and remove empty facets - //filter the facets - int partCount = solrJson.response.numFound as int - filterFacets(retFeatures, partCount, selectedFacetsMap) + //add av facet to the facet list + def avpList = avMap.values() as List + def avFacetConfig = domainConfigFacets.find { it.abbr == 'av' } + if (avFacetConfig) { + def attrSortOrderConfig = avFacetConfig.resultSortOrder.split('\\+') + avpList.sort { it."${ attrSortOrderConfig[0] }" } + if (attrSortOrderConfig[1] == 'desc') { + Collections.reverse(avpList) + } + } + retFeatures.addAll(avpList) + //TODO: 80% Rule, filter selected facets and remove empty facets + //filter the facets + int partCount = solrJson.response.numFound as int + filterFacets(retFeatures, partCount, selectedFacetsMap) - //sort the items in the facets - retFeatures.each { retFeature -> - if (retFeature?.resultSortOrder) { - def sortOrderConfig = retFeature.resultSortOrder.split('\\+') - retFeature.values.sort { it."${sortOrderConfig[0]}" } - if (sortOrderConfig[1] == 'desc') { - Collections.reverse(retFeature.values) - } + + //sort the items in the facets + retFeatures.each { retFeature -> + if (retFeature?.resultSortOrder) { + def sortOrderConfig = retFeature.resultSortOrder.split('\\+') + retFeature.values.sort { it."${ sortOrderConfig[0] }" } + if (sortOrderConfig[1] == 'desc') { + Collections.reverse(retFeature.values) } } - //sort the facets itself. - retFeatures.sort { it.seq } - - retFeatures } + //sort the facets itself. + retFeatures.sort { it.seq } + retFeatures + } + /** * Process catalog hitlist xml document * @param histlistDoc @@ -595,409 +602,399 @@ } /** - * Process category hitlist xml document - * @param histlistDoc - * @return - */ - List processCategoryResponse(histlistDoc) { - def categories = [] - histlistDoc.categories.category.each { doc -> - Category category = new Category() - category.id = doc.categoryId.text() as int - category.categoryName = doc.categoryName.text() - category.mediaUrl = doc.mediaUrl.text() - category.prefixUrl = doc.prefixUrl.text() - category.extension = doc.extension.text() + * Process category hitlist xml document + * @param histlistDoc + * @return + */ + List processCategoryResponse(histlistDoc) { + def categories = [] + histlistDoc.categories.category.each { doc -> + Category category = new Category() + category.id = doc.categoryId.text() as int + category.categoryName = doc.categoryName.text() + category.mediaUrl = doc.mediaUrl.text() + category.prefixUrl = doc.prefixUrl.text() + category.extension = doc.extension.text() - categories.add(category) - } - categories - } + categories.add(category) + } + categories + } /** - * Process the part response. - * @param partsJson - * @return - */ - List processPartResponse(partsJson) { - def parts = [] - partsJson.response.docs.each { doc -> + * Process the part response. + * @param partsJson + * @return + */ + List processPartResponse(partsJson) { + def parts = [] + partsJson.response.docs.each { doc -> - Part part = new Part() - part.id = doc.partNumber - part.partNumber = doc.partNumber - part.punctuatedPartNumber = doc.punctuatedPartNumber - part.partDescr = doc.partDescr - part.subComCodeId = doc.subComCodeId - part.subComCode = doc.subComCode - part.subComCodeDescr = doc.subComCodeDescr - part.subComCodeAlias = doc.subComCodeAlias - part.subComCodeAlias = doc.subComCodeAlias - part.brandId = doc.brandId - part.brandCode = doc.brandCode - part.brandName = doc.brandName - part.brandMediaUrl = doc.brandMediaUrl - part.brandPrefixUrl = doc.brandPrefixUrl - part.brandExtension = doc.brandExtension - part.vendorPartNumber = doc.vendorPartNumber - part.vendorPunctuatedPartNumber = doc.vendorPunctuatedPartNumber - doc.oemPartNumber?.collect { oemPN -> - part.oemPartNumbers.add(oemPN) - } - doc.oemPunctuatedPartNumber?.collect { oemPPN -> - part.oemPunctuatedPartNumbers.add(oemPPN) - } - doc.xrefPartNumber?.collect { xrefPN -> - part.xRefPartNumbers.add(xrefPN) - } - doc.xrefPunctuatedPartNumber?.collect { xrefPPN -> - part.xRefPunctuatedPartNumbers.add(xrefPPN) - } - part.uom = doc.uom - part.retailPrice = new Double((doc.retailPrice)) - part.warehouseCountry = doc.warehouseCountry - part.partStatus = doc.partStatus - part.mediaUrl = doc.mediaUrl - part.prefixUrl = doc.prefixUrl - part.extension = doc.extension + Part part = new Part() + part.id = doc.partNumber + part.partNumber = doc.partNumber + part.punctuatedPartNumber = doc.punctuatedPartNumber + part.partDescr = doc.partDescr + part.subComCodeId = doc.subComCodeId + part.subComCode = doc.subComCode + part.subComCodeDescr = doc.subComCodeDescr + part.subComCodeAlias = doc.subComCodeAlias + part.subComCodeAlias = doc.subComCodeAlias + part.brandId = doc.brandId + part.brandCode = doc.brandCode + part.brandName = doc.brandName + part.brandMediaUrl = doc.brandMediaUrl + part.brandPrefixUrl = doc.brandPrefixUrl + part.brandExtension = doc.brandExtension + part.vendorPartNumber = doc.vendorPartNumber + part.vendorPunctuatedPartNumber = doc.vendorPunctuatedPartNumber + doc.oemPartNumber?.collect { oemPN -> + part.oemPartNumbers.add(oemPN) + } + doc.oemPunctuatedPartNumber?.collect { oemPPN -> + part.oemPunctuatedPartNumbers.add(oemPPN) + } + doc.xrefPartNumber?.collect { xrefPN -> + part.xRefPartNumbers.add(xrefPN) + } + doc.xrefPunctuatedPartNumber?.collect { xrefPPN -> + part.xRefPunctuatedPartNumbers.add(xrefPPN) + } + part.uom = doc.uom + part.retailPrice = new Double((doc.retailPrice)) + part.warehouseCountry = doc.warehouseCountry + part.partStatus = doc.partStatus + part.mediaUrl = doc.mediaUrl + part.prefixUrl = doc.prefixUrl + part.extension = doc.extension - parts.add(part) - } - parts - } + parts.add(part) + } + parts + } /** - * Process the product response. - * @param productResponse - * @return - */ - List processProductResponse(prodJson) { + * Process the product response. + * @param productResponse + * @return + */ + List processProductResponse(prodJson) { - def products = [] - prodJson.response.docs.each { doc -> - Product product = new Product() + def products = [] + prodJson.response.docs.each { doc -> + Product product = new Product() - product.id = doc.productId as int - product.catalogInstanceId = doc.catalogInstanceId as int - product.catalogInstanceName = doc.catalogInstanceName - product.pageNumber = doc.pageNumber as int - product.sequence = doc.sequence as int + product.id = doc.productId as int + product.catalogInstanceId = doc.catalogInstanceId as int + product.catalogInstanceName = doc.catalogInstanceName + product.pageNumber = doc.pageNumber as int + product.sequence = doc.sequence as int - product.description = doc.description - if (doc.brandId != '') { - product.brandId = doc.brandId as int - } + product.description = doc.description + if (doc.brandId != '') { + product.brandId = doc.brandId as int + } - product.brandName = doc.brandName - product.brandCode = doc.brandCode - product.caption = doc.caption - product.productName = doc.productName - product.mediaUrl = doc.mediaUrl - product.prefixUrl = doc.prefixUrl - product.extension = doc.extension - product.brandMediaUrl = doc.brandMediaUrl - product.brandPrefixUrl = doc.brandPrefixUrl - product.brandExtension = doc.brandExtension - product.baseDealerPriceLow = doc.baseDealerPriceLow as double - product.baseDealerPriceHigh = doc.baseDealerPriceHigh as double - product.retailPriceLow = doc.retailPriceLow as double - product.retailPriceHigh = doc.retailPriceHigh as double - product.retailPriceDisplayRange = doc.retailPriceDisplayRange - product.banner = doc.banner - product.partCount = doc.partCount as int + product.brandName = doc.brandName + product.brandCode = doc.brandCode + product.caption = doc.caption + product.productName = doc.productName + product.mediaUrl = doc.mediaUrl + product.prefixUrl = doc.prefixUrl + product.extension = doc.extension + product.brandMediaUrl = doc.brandMediaUrl + product.brandPrefixUrl = doc.brandPrefixUrl + product.brandExtension = doc.brandExtension + product.baseDealerPriceLow = doc.baseDealerPriceLow as double + product.baseDealerPriceHigh = doc.baseDealerPriceHigh as double + product.retailPriceLow = doc.retailPriceLow as double + product.retailPriceHigh = doc.retailPriceHigh as double + product.retailPriceDisplayRange = doc.retailPriceDisplayRange + product.banner = doc.banner + product.partCount = doc.partCount as int - product.faqCount = doc.faqCount as int - product.tag = doc.tag - //Splits ct1, ct2, ct3 and ct4 records by pipe symbol to get categoryId and Name for 4 category level - for (int i = 1; i <= 4; i++) { - String[] categoryRecord = doc."ct$i".split('\\|') - if (categoryRecord.size() == 2) { - product."ct${i}Id" = categoryRecord[0] - product."ct${i}Name" = categoryRecord[1] - } - } + product.faqCount = doc.faqCount as int + product.tag = doc.tag + //Splits ct1, ct2, ct3 and ct4 records by pipe symbol to get categoryId and Name for 4 category level + for (int i = 1; i <= 4; i++) { + String[] categoryRecord = doc."ct$i".split('\\|') + if (categoryRecord.size() == 2) { + product."ct${i}Id" = categoryRecord[0] + product."ct${i}Name" = categoryRecord[1] + } + } - doc.uniqueId.eachWithIndex { uniqueId, index -> - MediaGroup mg = new MediaGroup() - mg.uniqueId = doc.uniqueId.getAt(index ) - mg.attributeName1 = doc.attributeName1.getAt(index ) - mg.attributeValue1 = doc.attributeValue1.getAt(index ) - mg.attributeName2 = doc.attributeName2.getAt(index ) - mg.attributeValue2 = doc.attributeValue2.getAt(index ) - mg.attributeName3 = doc.attributeName3.getAt(index ) - mg.attributeValue3 = doc.attributeValue3.getAt(index ) - mg.mediaGroupViewingAngleId = doc.mediaGroupViewingAngleId.getAt(index ) - mg.mediaGroupPrefixUrl = doc.mediaGroupPrefixUrl.getAt(index ) - mg.mediaGroupMediaUrl = doc.mediaGroupMediaUrl.getAt(index ) - mg.mediaGroupExtension = doc.mediaGroupExtension.getAt(index ) + doc.uniqueId.eachWithIndex { uniqueId, index -> + MediaGroup mg = new MediaGroup() + mg.uniqueId = doc.uniqueId.getAt(index ) + mg.attributeName1 = doc.attributeName1.getAt(index ) + mg.attributeValue1 = doc.attributeValue1.getAt(index ) + mg.attributeName2 = doc.attributeName2.getAt(index ) + mg.attributeValue2 = doc.attributeValue2.getAt(index ) + mg.attributeName3 = doc.attributeName3.getAt(index ) + mg.attributeValue3 = doc.attributeValue3.getAt(index ) + mg.mediaGroupViewingAngleId = doc.mediaGroupViewingAngleId.getAt(index ) + mg.mediaGroupPrefixUrl = doc.mediaGroupPrefixUrl.getAt(index ) + mg.mediaGroupMediaUrl = doc.mediaGroupMediaUrl.getAt(index ) + mg.mediaGroupExtension = doc.mediaGroupExtension.getAt(index ) - product.mediaGroups.add(mg) - } + product.mediaGroups.add(mg) + } - doc.productGroupId.eachWithIndex { productGroupId, index -> - ProductGroup pg = new ProductGroup() - pg.productGroupId = doc.productGroupId.getAt(index ) - pg.productGroupName = doc.productGroupName.getAt(index ) - pg.productGroupPrefixUrl = doc.productGroupPrefixUrl.getAt(index ) - pg.productGroupMediaUrl = doc.productGroupMediaUrl.getAt(index ) - pg.productGroupExtension = doc.productGroupExtension.getAt(index ) - pg.productGroupSequence = doc.productGroupSequence.getAt(index ) + doc.productGroupId.eachWithIndex { productGroupId, index -> + ProductGroup pg = new ProductGroup() + pg.productGroupId = doc.productGroupId.getAt(index ) + pg.productGroupName = doc.productGroupName.getAt(index ) + pg.productGroupPrefixUrl = doc.productGroupPrefixUrl.getAt(index ) + pg.productGroupMediaUrl = doc.productGroupMediaUrl.getAt(index ) + pg.productGroupExtension = doc.productGroupExtension.getAt(index ) + pg.productGroupSequence = doc.productGroupSequence.getAt(index ) - product.productGroups.add(pg) - } + product.productGroups.add(pg) + } - def isSub = false - def bulletKey = '' - def subBullets - Feature feature - doc.featureSequence.eachWithIndex { featureSequence, index -> + def isSub = false + def bulletKey = '' + def subBullets + Feature feature + doc.featureSequence.eachWithIndex { featureSequence, index -> - def featureType = doc.featureType.getAt(index) - def featureText = doc.feature.get(index) + def featureType = doc.featureType.getAt(index) + def featureText = doc.feature.get(index) - switch (featureType?.toUpperCase()) { - case 'SUB': - isSub = true - bulletKey = featureText as String - subBullets = [] - feature = new Feature(text: featureText, type: featureType) - product.features.add(feature) - break - case 'BULLET': - if (isSub) { - def subBullet = new SubBullet(text: featureText, type: featureType) - subBullets.add(subBullet) - feature.subBullets = subBullets - } else { - feature = new Feature(text: featureText, type: featureType) - product.features.add(feature) - } - break - case 'NOTE': - isSub = false - feature = new Feature(text: featureText, type: featureType) - product.features.add(feature) - break - } - } - products.add(product) - } - products - } + switch (featureType?.toUpperCase()) { + case 'SUB': + isSub = true + bulletKey = featureText as String + subBullets = [] + feature = new Feature(text: featureText, type: featureType) + product.features.add(feature) + break + case 'BULLET': + if (isSub) { + def subBullet = new SubBullet(text: featureText, type: featureType) + subBullets.add(subBullet) + feature.subBullets = subBullets + } else { + feature = new Feature(text: featureText, type: featureType) + product.features.add(feature) + } + break + case 'NOTE': + isSub = false + feature = new Feature(text: featureText, type: featureType) + product.features.add(feature) + break + } + } + products.add(product) + } + products + } - /** - * Process the product response. - * @param productResponse - * @return - */ - List processProductGroupResponse(prodGroupJson) { + /** + * Process the product response. + * @param productResponse + * @return + */ + List processProductGroupResponse(prodGroupJson) { - def productGroups = [] - prodGroupJson.response.docs.each { doc -> - ProductGroupNew productGroup = new ProductGroupNew() + def productGroups = [] + prodGroupJson.response.docs.each { doc -> + ProductGroupNew productGroup = new ProductGroupNew() - productGroup.id = doc.productGroupId as int - productGroup.catalogInstanceId = doc.catalogInstanceId as int - productGroup.catalogInstanceName = doc.catalogInstanceName - productGroup.pageNumber = doc.pageNumber as int - productGroup.sequence = doc.sequence as int + productGroup.id = doc.productGroupId as int + productGroup.catalogInstanceId = doc.catalogInstanceId as int + productGroup.catalogInstanceName = doc.catalogInstanceName + productGroup.pageNumber = doc.pageNumber as int + productGroup.sequence = doc.sequence as int - productGroup.description = doc.description - if (doc.brandId != '') { - productGroup.brandId = doc.brandId as int - } + productGroup.description = doc.description + if (doc.brandId != '') { + productGroup.brandId = doc.brandId as int + } - productGroup.brandName = doc.brandName - productGroup.brandCode = doc.brandCode - productGroup.caption = doc.caption - productGroup.productName = doc.productName - productGroup.productGroupName = doc.productGroupName - productGroup.productId = doc.productId as int - productGroup.mediaUrl = doc.mediaUrl - productGroup.prefixUrl = doc.prefixUrl - productGroup.extension = doc.extension - productGroup.brandMediaUrl = doc.brandMediaUrl - productGroup.brandPrefixUrl = doc.brandPrefixUrl - productGroup.brandExtension = doc.brandExtension - productGroup.baseDealerPriceLow = doc.baseDealerPriceLow as double - productGroup.baseDealerPriceHigh = doc.baseDealerPriceHigh as double - productGroup.retailPriceLow = doc.retailPriceLow as double - productGroup.retailPriceHigh = doc.retailPriceHigh as double - productGroup.retailPriceDisplayRange = doc.retailPriceDisplayRange - productGroup.partCount = doc.partCount as int - productGroup.faqCount = doc.faqCount as int - productGroup.tag = doc.tag - //Splits ct1, ct2, ct3 and ct4 records by pipe symbol to get categoryId and Name for 4 category level - for (int i = 1; i <= 4; i++) { - String[] categoryRecord = doc."ct$i".split('\\|') - if (categoryRecord.size() == 2) { - productGroup."ct${i}Id" = categoryRecord[0] - productGroup."ct${i}Name" = categoryRecord[1] - } - } - def isSub = false - def bulletKey = '' - def subBullets - Feature feature - doc.featureSequence.eachWithIndex { featureSequence, index -> + productGroup.brandName = doc.brandName + productGroup.brandCode = doc.brandCode + productGroup.caption = doc.caption + productGroup.productName = doc.productName + productGroup.productGroupName = doc.productGroupName + productGroup.productId = doc.productId as int + productGroup.mediaUrl = doc.mediaUrl + productGroup.prefixUrl = doc.prefixUrl + productGroup.extension = doc.extension + productGroup.brandMediaUrl = doc.brandMediaUrl + productGroup.brandPrefixUrl = doc.brandPrefixUrl + productGroup.brandExtension = doc.brandExtension + productGroup.baseDealerPriceLow = doc.baseDealerPriceLow as double + productGroup.baseDealerPriceHigh = doc.baseDealerPriceHigh as double + productGroup.retailPriceLow = doc.retailPriceLow as double + productGroup.retailPriceHigh = doc.retailPriceHigh as double + productGroup.retailPriceDisplayRange = doc.retailPriceDisplayRange + productGroup.partCount = doc.partCount as int + productGroup.faqCount = doc.faqCount as int + productGroup.tag = doc.tag + //Splits ct1, ct2, ct3 and ct4 records by pipe symbol to get categoryId and Name for 4 category level + for (int i = 1; i <= 4; i++) { + String[] categoryRecord = doc."ct$i".split('\\|') + if (categoryRecord.size() == 2) { + productGroup."ct${i}Id" = categoryRecord[0] + productGroup."ct${i}Name" = categoryRecord[1] + } + } + def isSub = false + def bulletKey = '' + def subBullets + Feature feature + doc.featureSequence.eachWithIndex { featureSequence, index -> - def featureType = doc.featureType.getAt(index) - def featureText = doc.feature.get(index) + def featureType = doc.featureType.getAt(index) + def featureText = doc.feature.get(index) - switch (featureType?.toUpperCase()) { - case 'SUB': - isSub = true - bulletKey = featureText as String - subBullets = [] - feature = new Feature(text: featureText, type: featureType) - productGroup.features.add(feature) - break - case 'BULLET': - if (isSub) { - def subBullet = new SubBullet(text: featureText, type: featureType) - subBullets.add(subBullet) - feature.subBullets = subBullets - } else { - feature = new Feature(text: featureText, type: featureType) - productGroup.features.add(feature) - } - break - case 'NOTE': - isSub = false - feature = new Feature(text: featureText, type: featureType) - productGroup.features.add(feature) - break - } - } - productGroups.add(productGroup) - } - productGroups - } + switch (featureType?.toUpperCase()) { + case 'SUB': + isSub = true + bulletKey = featureText as String + subBullets = [] + feature = new Feature(text: featureText, type: featureType) + productGroup.features.add(feature) + break + case 'BULLET': + if (isSub) { + def subBullet = new SubBullet(text: featureText, type: featureType) + subBullets.add(subBullet) + feature.subBullets = subBullets + } else { + feature = new Feature(text: featureText, type: featureType) + productGroup.features.add(feature) + } + break + case 'NOTE': + isSub = false + feature = new Feature(text: featureText, type: featureType) + productGroup.features.add(feature) + break + } + } + productGroups.add(productGroup) + } + productGroups + } /** - * Iterate through facets - * - set the total count on facet - * - remove the facet if not applicable. - * @param facets - * @param partCount - */ - void filterFacets(facets, partCount, selectedFacetsMap) { + * Iterate through facets + * - set the total count on facet + * - remove the facet if not applicable. + * @param facets + * @param partCount + */ + void filterFacets(facets, partCount, selectedFacetsMap) { - Iterator itr = facets.iterator() - while (itr.hasNext()) { - def facet = itr.next() + Iterator itr = facets.iterator() + while (itr.hasNext()) { + def facet = itr.next() - //set the total count on the facet - facet.count = getTotalFacetCount(facet) + //set the total count on the facet + facet.count = getTotalFacetCount(facet) - //remove the facets - if (shouldRemove(facet, partCount, selectedFacetsMap)) { - itr.remove() - } - } - } + //remove the facets + if (shouldRemove(facet, partCount, selectedFacetsMap)) { + itr.remove() + } + } + } /** - * set remove flag to true for facet with zero count - * Also apply the 80% rule on the avps - * @param facet - * @return - */ - boolean shouldRemove(facet, partCount, selectedFacetsMap) { + * set remove flag to true for facet with zero count + * Also apply the 80% rule on the avps + * @param facet + * @return + */ + boolean shouldRemove(facet, partCount, selectedFacetsMap) { - //remove facets which are already selected - /*if (selectedFacetsMap.containsKey(facet.type)) { - true - }*/ + //remove facets which are already selected + if (selectedFacetsMap.containsKey(facet.type)) { + return true + } - selectedFacetsMap.containsKey(facet.type) + //facet count zero + if (facet.count == 0) { + return true + } - //facet count zero - /*if (facet.count == 0) { - true - }*/ + //apply 80% rule + else if (facet.type.startsWith('av')) { - facet.count == 0 + //remove av facet with name as Note + if (facet.name.equalsIgnoreCase('NOTE')) { + return true + } + //remove attribute facet with only 1 value in it + // - note this is different than count - which sums up + // the part numbers for all the values for that facet + if (facet?.values?.size() == 1) { + return true + } - //apply 80% rule - if (facet.type.startsWith('av')) { + def percent = (facet.count / partCount) * 100 + if (percent < 80) { + return true + } + facet.percent = percent + } + false + } - //remove av facet with name as Note - /* if (facet.name.equalsIgnoreCase('NOTE')) { - true - }*/ - - facet.name.equalsIgnoreCase('NOTE') - //remove attribute facet with only 1 value in it - note this is different than - // count - which sums up the part numbers for all the values for that facet - /* if (facet?.values?.size() == 1) { - true - }*/ - - - facet?.values?.size() == 1 - - def percent = (facet.count / partCount) * 100 - /* if (percent < 80) { - true - }*/ - - percent < 80 - facet.percent = percent - } - false - } - /** - * sum up the count on values and set it to facet. - * Used by next facet and header facet both - * @param facet - * @return - */ - int getTotalFacetCount(facet) { - facet.values*.count.sum() ?: 0 - } + * sum up the count on values and set it to facet. + * Used by next facet and header facet both + * @param facet + * @return + */ + int getTotalFacetCount(facet) { + facet.values*.count.sum() ?: 0 + } /** - * If sorting field id is specified in params use it for sorting based on expression in sortBys . - * else default it based on the renderer - * @param sb - * @param sortBys - * @param renderer - * @return - */ - String getSortingQS(sb, sortBys) { - def sortingQs = '' - //for some renderers like ci sortBys is null - if (sortBys) { - if (sb) { - def value = sortBys.find { it.id as String == sb } - if (value) { - sortingQs = "${value.expression}" - } - } else { - def defaultSortBy = sortBys.find { it.defaultSortBy == true } - if (defaultSortBy) { - sortingQs = "${defaultSortBy.expression}" - } - } - sortingQs = '&sort=' + sortingQs - } - sortingQs - } + * If sorting field id is specified in params use it for sorting based on expression in sortBys . + * else default it based on the renderer + * @param sb + * @param sortBys + * @param renderer + * @return + */ + String getSortingQS(sb, sortBys) { + def sortingQs = '' + //for some renderers like ci sortBys is null + if (sortBys) { + if (sb) { + def value = sortBys.find { it.id as String == sb } + if (value) { + sortingQs = "${value.expression}" + } + } else { + def defaultSortBy = sortBys.find { it.defaultSortBy == true } + if (defaultSortBy) { + sortingQs = "${defaultSortBy.expression}" + } + } + sortingQs = '&sort=' + sortingQs + } + sortingQs + } - /** - * Create pagination based on rows and offset. Defaults to 10 rows - */ - String getPaginationQueryString(rows, offset) { - def pagination = '&rows=10&start=0' - if (rows) { - pagination = "&rows=${rows}" - } - if (offset) { - pagination = pagination + "&start=${offset}" - } - pagination - } + /** + * Create pagination based on rows and offset. Defaults to 10 rows + */ + String getPaginationQueryString(rows, offset) { + def pagination = '&rows=10&start=0' + if (rows) { + pagination = "&rows=${rows}" + } + if (offset) { + pagination = pagination + "&start=${offset}" + } + pagination + } } Index: branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrRequestService.groovy =================================================================== diff -u -r8821 -r8883 --- branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrRequestService.groovy (.../SolrRequestService.groovy) (revision 8821) +++ branches/pssGrails3/grails-app/services/com/lemanscorp/search/solr/SolrRequestService.groovy (.../SolrRequestService.groovy) (revision 8883) @@ -8,7 +8,9 @@ @SuppressWarnings(['AbcMetric', 'ThrowRuntimeException', 'CyclomaticComplexity', 'CatchException', 'Instanceof', - 'ExplicitCallToMinusMethod', 'UnnecessaryObjectReferences']) + 'ExplicitCallToMinusMethod', 'UnnecessaryObjectReferences', 'UnusedMethodParameter', 'InvertedIfElse', + 'UnnecessarySubstring', 'ConsecutiveStringConcatenation' ]) + class SolrRequestService extends LemansService { @@ -18,7 +20,7 @@ def facetNames = ['dm', 'ci', 'ct1', 'ct2', 'ct3', 'ct4', 'br', 'cc', 'sc', 'mk', 'md', 'yr', 'ps', 'pr', 'pn', 'dps', 'sg', 'pv', 'sv', 'pc'] - static final RIDERDOMAIN = 18..24 + static final RIDERDOMAIN = 18..24 static final int PNWDOMAIN = 4 @@ -60,140 +62,121 @@ def qualifier = createQualifier(params, selectedFacetsMap, domainConfigFacets, true, core) def qString = qualifier - //def genParams = '' +// def genParams = '' def domainFacet - if (params.pv) { - domainFacet = solrService.findDomainConfigFor('pv', domainConfigFacets) - qualifier = selectedFacetsMap.get('pv').collect { item -> - "primaryVendorId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.sv) { - domainFacet = solrService.findDomainConfigFor('sv', domainConfigFacets) - qualifier = selectedFacetsMap.get('sv').collect { item -> - "secondaryVendorId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.pc) { - domainFacet = solrService.findDomainConfigFor('pc', domainConfigFacets) - qualifier = selectedFacetsMap.get('pc').collect { item -> - "productCode:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.sg) { - domainFacet = solrService.findDomainConfigFor('sg', domainConfigFacets) - qualifier = selectedFacetsMap.get('sg').collect { item -> - "segmentId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.br) { - domainFacet = solrService.findDomainConfigFor('br', domainConfigFacets) - qualifier = selectedFacetsMap.get('br').collect { item -> - "brandId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.br || params.br_Filter) { - if (params.br_Filter) { - //added to handle APPDEV-5429 -- - qualifier = params.list('br_Filter').collect { item -> "brandId:$item" }.join(' OR ') - qString += ' AND (' + qualifier + ')' + if (params.pv) { + domainFacet = solrService.findDomainConfigFor('pv', domainConfigFacets) + qualifier = selectedFacetsMap.get('pv').collect { item -> "primaryVendorId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.sv) { + domainFacet = solrService.findDomainConfigFor('sv', domainConfigFacets) + qualifier = selectedFacetsMap.get('sv').collect { item -> "secondaryVendorId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.pc) { + domainFacet = solrService.findDomainConfigFor('pc', domainConfigFacets) + qualifier = selectedFacetsMap.get('pc').collect { item -> "productCode:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.sg) { + domainFacet = solrService.findDomainConfigFor('sg', domainConfigFacets) + qualifier = selectedFacetsMap.get('sg').collect { item -> "segmentId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.br) { + domainFacet = solrService.findDomainConfigFor('br', domainConfigFacets) + qualifier = selectedFacetsMap.get('br').collect { item -> "brandId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.br || params.br_Filter) { + if (!params.br_Filter) { + domainFacet = solrService.findDomainConfigFor('br', domainConfigFacets) + qualifier = selectedFacetsMap.get('br').collect { item -> "brandId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } else { + //added to handle APPDEV-5429 -- + qualifier = params.list('br_Filter').collect { item -> "brandId:$item" }.join(' OR ') + qString += 'AND (' + qualifier + ')' + } + } + if (params.md) { + domainFacet = solrService.findDomainConfigFor('md', domainConfigFacets) + qualifier = selectedFacetsMap.get('md').collect { item -> "modelId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.yr) { + domainFacet = solrService.findDomainConfigFor('yr', domainConfigFacets) + qualifier = selectedFacetsMap.get('yr').collect { item -> "year:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.cc) { + domainFacet = solrService.findDomainConfigFor('cc', domainConfigFacets) + qualifier = selectedFacetsMap.get('cc').collect { item -> "comCodeId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.sc) { + domainFacet = solrService.findDomainConfigFor('sc', domainConfigFacets) + qualifier = selectedFacetsMap.get('sc').collect { item -> "subComCodeId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + if (params.ps) { + domainFacet = solrService.findDomainConfigFor('ps', domainConfigFacets) + qualifier = selectedFacetsMap.get('ps').collect { item -> "partStatus:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + //dps has id with hypen in it say -9993. So need to escape it. + if (params.dps) { + domainFacet = solrService.findDomainConfigFor('dps', domainConfigFacets) + qualifier = selectedFacetsMap.get('dps').collect { item -> + "dps:${escapeQueryChars(item)}" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + //apply this only when catalog is selected + if (params.ci && (params.pn)) { + domainFacet = solrService.findDomainConfigFor('pn', domainConfigFacets) + qualifier = selectedFacetsMap.get('pn').collect { + item -> "pn_FC:${params.ci}|${ item }" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') + qString += 'AND (' + qualifier + ')' + } + //filter by field (partNumber, productId, - called by psa to search by part number + params.keySet().each { String key -> + if (key?.startsWith('sf_')) { + def vals = params.list(key)?.minus('') ?: [] + qualifier = vals.findAll { it?.trim() != '' }?.collect { item -> "${ key.minus('sf_') }:${item}" }.join(' ' + 'OR' + ' ') + if (qualifier) { + //added for PMO-1122 only when core is part search on xrefQualifier. + if (core == 'part') { + def xrefQualifer = vals.findAll { it?.trim() != '' }?.collect { item -> "xrefPartNumber:${item}" }.join(' ' + 'OR' + ' ') + qualifier += ' ' + 'OR' + ' ' + xrefQualifer + } + qString += 'AND (' + qualifier + ')' + } + } + } - } else { - domainFacet = solrService.findDomainConfigFor('br', domainConfigFacets) - qualifier = selectedFacetsMap.get('br').collect { item -> - "brandId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - } - if (params.md) { - domainFacet = solrService.findDomainConfigFor('md', domainConfigFacets) - qualifier = selectedFacetsMap.get('md').collect { item -> - "modelId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.yr) { - domainFacet = solrService.findDomainConfigFor('yr', domainConfigFacets) - qualifier = selectedFacetsMap.get('yr').collect { item -> - "year:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.cc) { - domainFacet = solrService.findDomainConfigFor('cc', domainConfigFacets) - qualifier = selectedFacetsMap.get('cc').collect { item -> - "comCodeId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND ( ' + qualifier + ')' - } - if (params.sc) { - domainFacet = solrService.findDomainConfigFor('sc', domainConfigFacets) - qualifier = selectedFacetsMap.get('sc').collect { item -> - "subComCodeId:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - if (params.ps) { - domainFacet = solrService.findDomainConfigFor('ps', domainConfigFacets) - qualifier = selectedFacetsMap.get('ps').collect { item -> - "partStatus:$item" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - //dps has id with hypen in it say -9993. So need to escape it. - if (params.dps) { - domainFacet = solrService.findDomainConfigFor('dps', domainConfigFacets) - qualifier = selectedFacetsMap.get('dps').collect { item -> - "dps:${escapeQueryChars(item)}" }.join(' ' + - domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - //apply this only when catalog is selected - if (params.ci && (params.pn)) { - domainFacet = solrService.findDomainConfigFor('pn', domainConfigFacets) - qualifier = selectedFacetsMap.get('pn').collect { item -> - "pn_FC:${params.ci}|${item}" }.join(' ' + domainFacet?.valueBooleanOperator + ' ') - qString += ' AND (' + qualifier + ')' - } - //filter by field (partNumber, productId, - called by psa to search by part number - params.keySet().each { String key -> - if (key?.startsWith('sf_')) { - //def vals = params.list(key)?.minus('')?:[] - def vals = params.list(key)?.minus('') ?: [] - qualifier = vals.findAll { it?.trim() != '' }?.collect { item -> - "${key - ('sf_')}:${item}" }.join(' OR ' ) - if (qualifier) { - //added for PMO-1122 only when core is part search on xrefQualifier. - if (core == 'part') { - def xrefQualifer = vals.findAll { it?.trim() != '' }?.collect { item -> - "xrefPartNumber:${item}" }.join(' OR ') - qualifier += ' OR ' + xrefQualifer - } - qString += ' AND (' + qualifier + ')' - } - } - } - - def str = '' + def str = '' params.keySet().each { String key -> - if (key.startsWith('av')) { - //def values = params."$key" - //def attrNameId = key.substring('av'.length()) - def attrNameId = key['av'.length()..-1] - str += ' AND (' - //str+=" AND (attributeNameId:${attrNameId} AND " - def paramValues = params.list(key) - //av_FC:191|*|5226|* OR av_FC:191|*|41531|* - paramValues.each { paramValue -> - str += "av_FC:${attrNameId}|*|${paramValue}|* OR " - } - //str = str.substring(0, str.length() -' OR '.length()) - str = str[0, str.length() - 1 - ' OR '.length()] - str += ')' - } - } - if (str.length() > 0) { - //str = str.substring(' AND '.length()) - str = str[' AND '.length()..-1] - str = '(' + str + ')' - qString += ' AND ' + str - } + if (key.startsWith('av')) { +// def values = params."$key" + def attrNameId = key.substring('av'.length()) + str += ' AND (' + //str+=" AND (attributeNameId:${attrNameId} AND " + def paramValues = params.list(key) + //av_FC:191|*|5226|* OR av_FC:191|*|41531|* + paramValues.each { paramValue -> + str += "av_FC:${attrNameId}|*|${paramValue}|* OR " + } + str = str.substring(0, str.length() - ' OR '.length()) + str += ')' + } + } + if (str.length() > 0) { + str = str.substring(' AND '.length()) + str = '(' + str + ')' + qString += ' AND ' + str + } //qString = "("+qString+")" //replace above line with below code for solr4 regex search @@ -205,16 +188,16 @@ fitmentQuery = "AND (mk_yr_md_FC:/($mks)\\|(.+)\\|($yrs)\\|($mds)\\|(.+)/)" //This should be mk_yr_md but part core do not have it } - qString = '(' + qString + ' ' + fitmentQuery + ')' + qString = '(' + qString + ' ' + fitmentQuery + ')' //filter specific rider only parts for all parts search made from riderDomains. - if (core == 'part' && (RIDERDOMAIN.contains(params.int('dm')) || params.int('dm') == PNWDOMAIN)) { + if (core == 'part' && (RIDERDOMAIN.contains(params.int('dm')) || params.int('dm') == PNWDOMAIN)) { qString += " AND (dm_ci_ct1_ct2_ct3_ct4_pr:$params.dm||||||)" } - log.debug 'qString:' + qString - qString + log.debug 'qString:' + qString + qString } //solr4 regex search /** @@ -237,7 +220,7 @@ if (itemStr == null || itemStr?.trim() == '') { itemStr = '.+' } - itemStr + itemStr } @@ -260,47 +243,47 @@ //for other fields like br,avp (which are not domain specific) use fq=(id:*) filter if (core == 'part' || core == 'inactivePart') { //TODO:add locale specific logic - qualifier = 'id:*' + qualifier = 'id:*' } else { qualifier = "${fieldName}:${params.dm}|*|*|*|*|*|*" } def domainFacet def operator - if (params.pr) { - domainFacet = solrService.findDomainConfigFor('pr', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('pr').collect { item -> - " ${fieldName}:${params.dm}|*|*|*|*|*|" + item }.join(" $operator ") - } else if (params.ct4) { - domainFacet = solrService.findDomainConfigFor('ct4', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('ct4').collect { item -> - " ${fieldName}:${params.dm}|*|*|*|*|" + item + '|*' }.join(" $operator ") - } else if (params.ct3) { - domainFacet = solrService.findDomainConfigFor('ct3', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('ct3').collect { item -> - " ${fieldName}:${params.dm}|*|*|*|" + item + '|*|*' }.join(" $operator ") - } else if (params.ct2) { - domainFacet = solrService.findDomainConfigFor('ct2', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('ct2').collect { item -> - " ${fieldName}:${params.dm}|*|*|" + item + '|*|*|*' }.join(" $operator ") - } else if (params.ct1) { - domainFacet = solrService.findDomainConfigFor('ct1', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('ct1').collect { item -> - " ${fieldName}:${params.dm}|*|" + item + '|*|*|*|*' }.join(" $operator ") - } else if (params.ci) { - domainFacet = solrService.findDomainConfigFor('ci', domainConfigFacets) - operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' - qualifier = selectedFacetsMap.get('ci').collect { item -> - " ${fieldName}:${params.dm}|" + item + '|*|*|*|*|*' }.join(" $operator ") - } - //APPDEV-1750 - surround the qualifer with ( - '(' + qualifier + ')' - } + if (params.pr) { + domainFacet = solrService.findDomainConfigFor('pr', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('pr').collect { item -> + " ${fieldName}:${params.dm}|*|*|*|*|*|" + item }.join(" $operator ") + } else if (params.ct4) { + domainFacet = solrService.findDomainConfigFor('ct4', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('ct4').collect { item -> + " ${fieldName}:${params.dm}|*|*|*|*|" + item + '|*' }.join(" $operator ") + } else if (params.ct3) { + domainFacet = solrService.findDomainConfigFor('ct3', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('ct3').collect { item -> + " ${fieldName}:${params.dm}|*|*|*|" + item + '|*|*' }.join(" $operator ") + } else if (params.ct2) { + domainFacet = solrService.findDomainConfigFor('ct2', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('ct2').collect { item -> + " ${fieldName}:${params.dm}|*|*|" + item + '|*|*|*' }.join(" $operator ") + } else if (params.ct1) { + domainFacet = solrService.findDomainConfigFor('ct1', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('ct1').collect { item -> + " ${fieldName}:${params.dm}|*|" + item + '|*|*|*|*' }.join(" $operator ") + } else if (params.ci) { + domainFacet = solrService.findDomainConfigFor('ci', domainConfigFacets) + operator = isForParts ? domainFacet?.valueBooleanOperator : ' OR ' + qualifier = selectedFacetsMap.get('ci').collect { item -> + " ${fieldName}:${params.dm}|" + item + '|*|*|*|*|*' }.join(" $operator ") + } + //APPDEV-1750 - surround the qualifer with ( + '(' + qualifier + ')' + } /** * Create xml for selected Facets to send to store procedure @@ -313,7 +296,7 @@ def writer = new StringWriter() def xml = new MarkupBuilder(writer) xml.root { - selectedFacetsMap.keySet().minus('av').each { pName -> + selectedFacetsMap.keySet().minus('av').each { pName -> selectedFacetsMap.get(pName).each { pValue -> facet(abbr: pName, valueId: pValue) } @@ -348,8 +331,8 @@ log.debug (selectedFacetsXml) def nextFacetXml - sql().query('{call spSolrConfiguration(@domainId=?, @selectedFacets=?, @docType=?, @q=?, @locale= ?)}', - [domainId, selectedFacetsXml, docType, q, locale]) { rs -> + sql().query('{call spSolrConfiguration(@domainId=?, @selectedFacets=?, @docType=?, @q=?, @locale= ?)}', + [domainId, selectedFacetsXml, docType, q, locale]) { rs -> while (rs.next()) { nextFacetXml = rs.getString(1) log.debug nextFacetXml @@ -389,8 +372,8 @@ uiConfig.contextPageEnd = page?.contextPageEnd as String } root.config.sortBys.sortBy.each { sortBy -> - sortBys.add(new Expando(id: new Integer(sortBy.id as String), name: sortBy.display as String, - expression: sortBy.expression as String, defaultSortBy: sortBy.defaultSortBy)) + sortBys.add(new Expando(id: new Integer(sortBy.id as String), name: sortBy.display as String, + expression: sortBy.expression as String, defaultSortBy: sortBy.defaultSortBy)) } //no expando @@ -412,14 +395,14 @@ } catch (Exception exception) { //log.error exception.printStackTrace() - throw new RuntimeException("Exception while calling spSolrConfiguration with parameters domainId=${domainId}, " + - "selectedFacetsXml=${selectedFacetsXml}, docType=${docType}, q=${q}. Exception message=" + exception.message) + throw new RuntimeException("Exception while calling spSolrConfiguration with parameters domainId=${domainId}, " + + "selectedFacetsXml=${selectedFacetsXml}, docType=${docType}, q=${q}. Exception message=" + exception.message) } - uiConfig + uiConfig } Object createDomainFacet(domainFacet) { - new Expando(abbr: domainFacet.abbr as String + new Expando(abbr: domainFacet.abbr as String , description: domainFacet?.descr as String , displayName: domainFacet?.displayName as String , isMultiSelect: domainFacet?.isMultiSelect as String @@ -436,25 +419,25 @@ * @param nextFacets * @return */ - String createNextCategoryFCsQs(params) { - def nextCtUrl ='' + String createNextCategoryFCsQs(params, nextFacets) { + def nextCtUrl = '' String nextCt = getNextCategory(params) nextCtUrl = "&facet.field=${nextCt}_FC" - nextCtUrl + nextCtUrl } String getNextCategory(params) { - def nextCt = 'ct1' - if (params.ct3) { - nextCt = 'ct4' - } else if (params.ct2) { - nextCt = 'ct3' - } else if (params.ct1) { - nextCt = 'ct2' - } - nextCt - } + def nextCt = 'ct1' + if (params.ct3) { + nextCt = 'ct4' + } else if (params.ct2) { + nextCt = 'ct3' + } else if (params.ct1) { + nextCt = 'ct2' + } + nextCt + } String createNextFitmentFCsQS(params) { def fitmentFacetFieldsQuery = '' @@ -505,7 +488,7 @@ def facetFieldsQuery = '&facet=true&facet.mincount=1&facet.limit=-1&facet.field=dm_ci_ct1_ct2_ct3_ct4_pr' // Request for next category facets based on previous one - String categoryFacetFieldsQuery = createNextCategoryFCsQs(params) + String categoryFacetFieldsQuery = createNextCategoryFCsQs(params, nextFacets) // Get next fitments String fitmentFacetFieldsQuery = createNextFitmentFCsQS(params) @@ -518,14 +501,14 @@ nextFacets.each { nextFacet -> def nextFacetAbbr = nextFacet.abbr if (nextFacetAbbr == 'ct' || nextFacetAbbr == 'mk' || nextFacetAbbr == 'md' || nextFacetAbbr == 'yr' ) { - return + return } facetsToRequest.add(nextFacetAbbr) } selectedFacets.each { selectedFacet -> //skip av100 like fictitious facets if ((selectedFacet.startsWith('av') && selectedFacet.length() > 2) || selectedFacet == 'dm') { - return + return } facetsToRequest.add(selectedFacet) } @@ -574,7 +557,7 @@ * @param s * @return */ - String escapeQueryChars(String s) { + String escapeQueryChars(String s) { StringBuilder sb = new StringBuilder() for (int i = 0; i < s.length(); i++) { char c = s.charAt(i) @@ -587,6 +570,6 @@ } sb.append(c) } - sb.toString() + sb.toString() } } Index: branches/pssGrails3/grails-app/controllers/com/lemanscorp/search/SearchController.groovy =================================================================== diff -u -r8821 -r8883 --- branches/pssGrails3/grails-app/controllers/com/lemanscorp/search/SearchController.groovy (.../SearchController.groovy) (revision 8821) +++ branches/pssGrails3/grails-app/controllers/com/lemanscorp/search/SearchController.groovy (.../SearchController.groovy) (revision 8883) @@ -9,7 +9,7 @@ def solrService - def index() { + def index() { redirect (action: 'usage') } @@ -44,10 +44,10 @@ def solr() { params.q = unMaskAmpersand(params.q) - def result = solrService.runQuery(params) - if (params.q != null) { + def result = solrService.runQuery(params) + if (params.q != null) { def searchTermLogger = LogFactory.getLog('searchTermsLogger') - searchTermLogger.info('X-UUID:"' + request.getHeader('X-UUID') + '" searchTerm:"' + result.header.q + '" results:"' + result.header.total + '" index:"' + result.header.renderers[0] + '"' ) + searchTermLogger.info('X-UUID:"' + request.getHeader('X-UUID') + '" searchTerm:"' + result.header.q + '" results:"' + result.header.total + '" index:"' + result.header.renderers[0] + '"' ) } withFormat { json { render result as JSON }