Demo entry 6354031

TEST

   

Submitted by anonymous on Apr 04, 2017 at 16:25
Language: Java. Code size: 5.6 kB.

public virtual override void runKeyWordSearch() {
    keywordSearchResults = null;
    Map<ID,Double> listingPopularity;
    listingResults1 = null;
    if (keywords != null && keywords.length() > 0) {
        List<Listing__c> listingResults;
        
        Long m1 = System.currentTimeMillis();
        String queryStr;
        String baseQueryStr;
        try {
            
            // Record type clause for base query
            String recTypeClause = '';
            recTypeClause = 'AND (RecordType.Name = \'' + Listing.getRecordType(objType) + '\')' ;
            
            String processedKw;
            Boolean isSpecialKeyword = isSpecialKeyword(keywords);
            
            processedKw = !isSpecialKeyword ? processKeywords() : keywords;
            
            baseQueryStr = 'SELECT id,AllPopularity30Day__c FROM Listing__c WHERE Public__c = true AND Status__c != \'Inactive\' AND Marketplace__c = \'' + curExchange.getId() + '\' AND PublishLocation__c = \'' + Listing.APPEXCHANGE  +'\' ' + recTypeClause;
            
            String withinSuggestionsClause = '';
            if (suggestionList != null && suggestionList.size() > 0) {
                for(ID listingID : suggestionList) {
                    withinSuggestionsClause = withinSuggestionsClause == '' ? ' AND id IN (' : withinSuggestionsClause + ',';
                    withinSuggestionsClause += '\'' + listingID + '\' ';
                }
                withinSuggestionsClause += ')';
            }
            
            String clause = (filters != null) ? filters.getWhereClause(null,false) : '';
            
            if (clause != null && clause.length() > 0) {
                baseQueryStr  += ' AND ' + clause;
            }
            listingResults1 = new Map<ID,Double>();
            listingPopularity = new Map<ID,Double>();
            
            String keywordClause;
            
            keywordClause = 'AND (' + makeKeyWordClause(isSpecialKeyword,'Name',processedKw) + ') ' + withinSuggestionsClause;

            keywordSearch(baseQueryStr,keywordClause,listingResults1,listingPopularity,curExchange.getSearchListingNameWeighting());
            
            keywordClause = 'AND (' + makeKeyWordClause(isSpecialKeyword,'Publisher__r.Name',processedKw) + ') ' + withinSuggestionsClause;

            keywordSearch(baseQueryStr,keywordClause,listingResults1,listingPopularity,curExchange.getSearchListingPubNameWeighting());
            
            keywordClause = 'AND (' + makeKeyWordClause(isSpecialKeyword,'ShortDescription__c',processedKw) + ' OR ' + makeKeyWordClause(isSpecialKeyword,'SearchBlurb__c',processedKw) + ') ' + withinSuggestionsClause;

            keywordSearch(baseQueryStr,keywordClause,listingResults1,listingPopularity,curExchange.getSearchListingShortDescWeighting());
            
            keywordClause = 'AND (' + makeKeyWordClause(isSpecialKeyword,'Feature1__c',processedKw) + ' OR ' +
                makeKeyWordClause(isSpecialKeyword,'Feature2__c',processedKw) + ' OR ' +
                makeKeyWordClause(isSpecialKeyword,'Feature3__c',processedKw) + ') '  + withinSuggestionsClause;

            keywordSearch(baseQueryStr,keywordClause,listingResults1,listingPopularity,curExchange.getSearchListingFeatureWeighting());
            
            String recTypeClause2 = '';
            recTypeClause2 = 'AND (Listing__r.RecordType.Name = \'' + Listing.getRecordType(objType) + '\')' ;
            
            String soslQueryStr = 'FIND \'' + keywords + '\' IN ALL FIELDS RETURNING ListingExtension__c(id,Listing__r.AllPopularity30Day__c WHERE Listing__r.Public__c = true AND Listing__r.Status__c != \'Inactive\' AND Listing__r.Marketplace__c = \'' + curExchange.getId() + '\' AND Listing__r.PublishLocation__c = \'' + Listing.APPEXCHANGE  +'\'' + recTypeClause2;
            String soslClause = (filters != null) ? filters.getWhereClause('Listing__r',false) : '';
            System.debug('soslClause ' + soslClause);
            if (soslClause != null && soslClause.length() > 0) {
                soslQueryStr  += ' AND ' + soslClause;
            }
            System.debug('soslQueryStr ' + soslQueryStr);
            soslQueryStr  +=  ' ) ';
            
            List<List <sObject>> soslResults = search.query(soslQueryStr);
            if (soslResults != null && soslResults.size() > 0) {
                if (soslResults[0] != null) {
                    for(ListingExtension__c l : (List<ListingExtension__c>)soslResults[0]) {
                        Double i = listingResults1.get(l.Listing__c);
                        if (i == null) i = 0;
                        listingResults1.put(l.Listing__c,i+curExchange.getSearchListingLongDescWeighting());
                        listingPopularity.put(l.Listing__c,l.Listing__r.AllPopularity30Day__c);
                    }
                }
            }
            
            
            if (listingResults1 != null) {
                keywordSearchResults = sort(listingResults1,listingPopularity);
            }
            Long m2 = System.currentTimeMillis();
            System.debug('New Search Time - ' + (m2-m1));
        }
        catch(Exception e) {
            AppExchangeLog.logGack(AppExchangeLog.SEARCH_CATEGORY,AppExchangeLog.STI_SOSL_QUERY,e,'Search Query:' + baseQueryStr + '###' + queryStr + '***keywords=' + keywords);
            error = true;
        }
    }
    else if (withinSuggestions){
        keywordSearchResults = suggestionList;
    }
    
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).