Changeset 32110

Show
Ignore:
Timestamp:
24.01.2018 20:46:30 (5 weeks ago)
Author:
ak19
Message:

Forgot to commit bugfix. The bug was that when searching a solr collection, if you switch on a facet containing an apostrophe (try searching solr-demo for query term farm and then selecting the facet with apostrophe), there are 0 search results displayed for that facet despite the facet listing a positive number of matching docs for it. 1. Greenstone3SearchHandler.java and facet-scripts.js contain the fix. 2. GS2SolrSearch.java and SolrQueryWrapper?.java just contain further debug statements, some commented out.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java

    r32105 r32110  
    330330            else if (name.equals("facetQueries") && value.length() > 0) 
    331331            { 
     332                //logger.info("@@@ SOLR FACET VALUE FOUND: " + value); 
    332333                this.solr_src.addFacetQuery(value); 
    333334            } 
     
    410411                hldocOID = null; 
    411412            } 
     413            //logger.info("@@@@ Query is now: " + query); 
    412414            SharedSoleneQueryResult sqr = this.solr_src.runQuery(query); 
    413415 
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/util/SolrQueryWrapper.java

    r32105 r32110  
    297297                for (String currentQueryElement : queryElems) 
    298298                { 
     299                    //logger.info("@@@@ currentQueryElement " + currentQueryElement); 
     300                     
    299301                    String decodedQueryElement = null; 
    300302                    try 
     
    400402            { 
    401403              // add this field as a facet 
    402               solrQuery.addFacetField(_facets.get(i)); // solrParams.add("facet.field", _facets.get(i)); 
    403             } 
    404         } 
    405  
     404                solrQuery.addFacetField(_facets.get(i)); // solrParams.add("facet.field", _facets.get(i)); 
     405            } 
     406            //for(int i = 0; i < _facetQueries.size(); i++) { 
     407            //    logger.info("@@@@ facet query i: " + _facetQueries.get(i)); 
     408            //} 
     409        } 
     410                 
     411 
     412        // Some debugging        
     413        logger.info("@@@@ solrQuery: " + solrQuery);         
     414        try { 
     415            // https://stackoverflow.com/questions/2632175/decoding-uri-query-string-in-java 
     416            String displayQueryString = URLDecoder.decode(solrQuery.toString().replace("+", " "), "UTF-8"); 
     417            logger.info("@@@@ solrQuery URL decoded: " + displayQueryString); 
     418        } catch(Exception uee) { // UnsupportedEncodingException 
     419            logger.info("Got debug exception " + uee.getMessage()); 
     420        } 
     421 
     422         
    406423        // the solrserver will now 
    407424        // get the individual terms that make up the query, then request solr to return the totaltermfreq for each term 
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/solrserver/Greenstone3SearchHandler.java

    r29991 r32110  
    7777public class Greenstone3SearchHandler extends SearchHandler 
    7878{ 
    79     // IMPORTANT NOTE: Logging doesn't work in this class either with log4j or slf4j,  
     79    // IMPORTANT NOTES: 1. Logging doesn't work in this class either with log4j or slf4j,  
    8080    // but System.err goes to catalina.out. 
     81    // 2. To compile this class, "ant compile" in ext/solr is insufficient. The class file produced 
     82    // isn't copied into tomcat. Need to do "ant compile-gs3-solrserver". 
    8183 
    8284    //protected static Logger log = LoggerFactory.getLogger(Greenstone3SearchHandler.class); 
     
    157159 
    158160    if(query_string == null || query_string.equals("")) { 
    159         log.error("@@@@@@@@@ " + this.getClass() + " - QUERY STRING EMPTY"); 
     161        //log.error("@@@@@@@@@ " + this.getClass() + " - QUERY STRING EMPTY"); // logging won't work 
     162        System.err.println("@@@@@@@@@ " + this.getClass() + " - QUERY STRING EMPTY"); 
    160163    } 
    161164    else { 
     
    234237 
    235238        // totaltermfreq(TI, 'farming')  
    236         // termfreq(TI, 'farming')       
     239        // termfreq(TI, 'farming') 
     240        //System.err.println("@@@@ SOLR FACET queryTerm: " + queryTerm); 
    237241        solrParams.addField("totaltermfreq(" + field + ",'" + queryTerm + "')"); 
    238242        solrParams.addField("termfreq(" + field + ",'" + queryTerm + "')"); 
     243 
     244        // handle the special case of apostrophes in facet query terms 
     245        // (facet_scripts.js does the other half of handling them) 
     246        query_string = query_string.replace("%27", "'"); 
     247        solrParams.set("q", query_string); 
     248         
     249        System.err.println("@@@@ SOLR FACET query_string: " + query_string); 
    239250        } 
    240251    } 
  • main/trunk/greenstone3/web/interfaces/default/js/facet-scripts.js

    r30771 r32110  
    2828        for(var i = 0; i < counts.length; i++) 
    2929        { 
    30             countsStringBuffer += "\"" + encodeURI(counts[i]) + "\""; 
     30            // escape any apostrophes in facet query terms 
     31            // (ext/solr's Greenstone3SearchHandler does the other half of handling them) 
     32            countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\""; 
    3133            if(i < counts.length - 1) 
    3234            { 
     
    3941     
    4042    console.log("STRING IS " + countsString) 
    41      
     43     
    4244    $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea") 
    4345        .done(function(response)