Ignore:
Timestamp:
2013-08-13T13:33:08+12:00 (11 years ago)
Author:
kjdon
Message:

changes for sorting search results. setReverseSort now takes a boolean param, otherwise can never unset it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/indexers/lucene-gs/src/org/greenstone/LuceneWrapper3/GS2LuceneQuery.java

    r27086 r28031  
    5959public class GS2LuceneQuery extends SharedSoleneQuery
    6060{
     61  public static String SORT_RANK = "rank";
     62  public static String SORT_NATURAL = "natural";
     63
    6164    protected String full_indexdir="";
    6265
     66  protected int sort_type = SortField.SCORE;
    6367  protected boolean reverse_sort = false;
    6468    protected Sort sorter=new Sort();
     
    98102        Directory full_indexdir_dir = FSDirectory.open(new File(full_indexdir));
    99103            searcher = new IndexSearcher(full_indexdir_dir,true);
     104        // need to set this to get it to compute ranks when sorting by fields
     105        ((IndexSearcher)searcher).setDefaultFieldSortScoring(true,true);
    100106            reader = ((IndexSearcher) searcher).getIndexReader();
    101107       
     108       
     109        this.sorter = new Sort(new SortField(this.sort_field, this.sort_type, this.reverse_sort));
    102110    }
    103111    catch (IOException exception) {
     
    114122
    115123    public void setSortField(String sort_field) {
    116     super.setSortField(sort_field);
    117 
    118     if (sort_field == null) {
    119         this.sorter = new Sort();
    120     } else {
    121       this.sorter = new Sort(new SortField(sort_field,SortField.STRING, this.reverse_sort)); // **** can do better than this?!?
    122     }
    123     }
    124   public void setReverseSort() {
    125     this.reverse_sort = true;
    126     if (this.sort_field != null) {
    127       this.sorter = new Sort(new SortField(this.sort_field, SortField.STRING, this.reverse_sort));
    128     }
     124      if (sort_field.equals(SORT_RANK)) {
     125    this.sort_field = null;
     126    this.sort_type = SortField.SCORE;
     127      } else if (sort_field.equals(SORT_NATURAL)) {
     128    this.sort_field = null;
     129    this.sort_type = SortField.DOC;
     130      } else {
     131    this.sort_field  = sort_field;
     132    this.sort_type = SortField.STRING; // for now. numeric??
     133      }
     134    }
     135  public void setReverseSort(boolean reverse) {
     136    this.reverse_sort = reverse;
    129137  }
    130138  public boolean getReverseSort() {
     
    528536        }
    529537        else if (args[i].equals("-reverse_sort")) {
    530           queryer.setReverseSort();
     538          queryer.setReverseSort(true);
    531539        }
    532540        else if (args[i].equals("-filter")) {
Note: See TracChangeset for help on using the changeset viewer.