Package org.solbase

Source Code of org.solbase.SolbaseStringField

package org.solbase;

import org.apache.lucene.search.FieldComparatorSource;
import org.apache.lucene.search.SortField;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.EmbeddedSortField;
import org.apache.solr.schema.StrField;
import org.apache.solr.search.MissingStringLastComparatorSource;

public class SolbaseStringField extends StrField {

  protected SortField getStringSort(SchemaField field, boolean reverse) {
    return getStringSortField(field.getName(), reverse, field.sortMissingLast(), field.sortMissingFirst());
  }

  private SortField getStringSortField(String fieldName, boolean reverse, boolean nullLast, boolean nullFirst) {
    if (nullLast) {
      if (!reverse)
        return new EmbeddedSortField(fieldName, nullStringLastComparatorSource);
      else
        return new EmbeddedSortField(fieldName, SortField.STRING, true);
    } else if (nullFirst) {
      if (reverse)
        return new EmbeddedSortField(fieldName, nullStringLastComparatorSource, true);
      else
        return new EmbeddedSortField(fieldName, SortField.STRING, false);
    } else {
      return new EmbeddedSortField(fieldName, SortField.STRING, reverse);
    }
  }
 
  static final FieldComparatorSource nullStringLastComparatorSource = new MissingStringLastComparatorSource(null);
}
TOP

Related Classes of org.solbase.SolbaseStringField

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.