Changeset 28063 for gs3-extensions/solr

Show
Ignore:
Timestamp:
15.08.2013 14:22:11 (6 years ago)
Author:
kjdon
Message:

adding in comments and sorting search results

Files:
1 modified

Legend:

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

    r25931 r28063  
    4747public class SolrQueryWrapper extends SharedSoleneQuery 
    4848{ 
     49  public static String SORT_ASCENDING = "asc"; 
     50  public static String SORT_DESCENDING = "desc"; 
     51  public static String SORT_BY_RANK = "score"; 
     52  public static String SORT_BY_INDEX_ORDER = "_docid_"; 
     53 
    4954    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.SolrQueryWrapper.class.getName()); 
    5055    protected int max_docs = 100; 
     56  protected String sort_order = SORT_DESCENDING; 
    5157    protected ArrayList<String> _facets = new ArrayList<String>(); 
    5258    protected ArrayList<String> _facetQueries = new ArrayList<String>(); 
     
    6874        this.solr_core = solr_core; 
    6975    } 
    70  
     76   
     77  public void setSortOrder(String order) 
     78  { 
     79    this.sort_order = order; 
     80  } 
    7181    public void addFacet(String facet) 
    7282    { 
     
    190200        ModifiableSolrParams solrParams = new ModifiableSolrParams(); 
    191201        solrParams.set("q", query_string); 
     202        // sort param, like "score desc" or "byORG asc" 
     203        solrParams.set("sort", this.sort_field+" "+this.sort_order); 
     204        // which result to start from 
    192205        solrParams.set("start", start_results); 
     206        // how many results per "page" 
    193207        solrParams.set("rows", (end_results - start_results) + 1); 
     208        // which fields to return for each document 
    194209        solrParams.set("fl", "docOID score"); 
     210        // turn on the termsComponent 
    195211        solrParams.set("terms", true); 
     212        // which field to get the terms from 
    196213        solrParams.set("terms.fl", "ZZ"); 
    197214 
    198215        if (_facets.size() > 0) 
    199216        { 
     217          // enable facet counts in the query response 
    200218            solrParams.set("facet", "true"); 
    201219            for (int i = 0; i < _facets.size(); i++) 
    202220            { 
     221              // add this field as a facet 
    203222                solrParams.add("facet.field", _facets.get(i)); 
    204223            }