当前位置: 首页>>代码示例>>Java>>正文


Java SortField.getField方法代码示例

本文整理汇总了Java中org.apache.lucene.search.SortField.getField方法的典型用法代码示例。如果您正苦于以下问题:Java SortField.getField方法的具体用法?Java SortField.getField怎么用?Java SortField.getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.SortField的用法示例。


在下文中一共展示了SortField.getField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getValueSource

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
@Override
public ValueSource getValueSource(String name) {
  Object o = map.get(name);
  if (o == null) {
    throw new IllegalArgumentException("Invalid reference '" + name + "'");
  } else if (o instanceof Expression) {
    return ((Expression)o).getValueSource(this);
  } else if (o instanceof ValueSource) {
    return ((ValueSource)o);
  }
  SortField field = (SortField) o;
  switch(field.getType()) {
    case INT:
      return new IntFieldSource(field.getField(), (IntParser) field.getParser());
    case LONG:
      return new LongFieldSource(field.getField(), (LongParser) field.getParser());
    case FLOAT:
      return new FloatFieldSource(field.getField(), (FloatParser) field.getParser());
    case DOUBLE:
      return new DoubleFieldSource(field.getField(), (DoubleParser) field.getParser());
    case SCORE:
      return getScoreValueSource();
    default:
      throw new UnsupportedOperationException(); 
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:SimpleBindings.java

示例2: writeSortField

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
public static void writeSortField(StreamOutput out, SortField sortField) throws IOException {
    if (sortField.getClass() == GEO_DISTANCE_SORT_TYPE_CLASS) {
        // for geo sorting, we replace the SortField with a SortField that assumes a double field.
        // this works since the SortField is only used for merging top docs
        SortField newSortField = new SortField(sortField.getField(), SortField.Type.DOUBLE);
        newSortField.setMissingValue(sortField.getMissingValue());
        sortField = newSortField;
    }
    if (sortField.getClass() != SortField.class) {
        throw new IllegalArgumentException("Cannot serialize SortField impl [" + sortField + "]");
    }
    if (sortField.getField() == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeString(sortField.getField());
    }
    if (sortField.getComparatorSource() != null) {
        IndexFieldData.XFieldComparatorSource comparatorSource = (IndexFieldData.XFieldComparatorSource) sortField.getComparatorSource();
        writeSortType(out, comparatorSource.reducedType());
        writeMissingValue(out, comparatorSource.missingValue(sortField.getReverse()));
    } else {
        writeSortType(out, sortField.getType());
        writeMissingValue(out, sortField.getMissingValue());
    }
    out.writeBoolean(sortField.getReverse());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:Lucene.java

示例3: ShardComparator

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
public ShardComparator(SortField sortField) {
  this.sortField = sortField;
  this.fieldName = sortField.getField();
  int fieldNum = 0;
  for (int i=0; i<fieldNames.size(); i++) {
    if (fieldNames.get(i).equals(fieldName)) {
      fieldNum = i;
      break;
    }
  }
  this.fieldNum = fieldNum;
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:ShardDoc.java

示例4: getSortDoc

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private SortDoc getSortDoc(SolrIndexSearcher searcher, SortField[] sortFields) throws IOException {
  SortValue[] sortValues = new SortValue[sortFields.length];
  IndexSchema schema = searcher.getSchema();
  for(int i=0; i<sortFields.length; ++i) {
    SortField sf = sortFields[i];
    String field = sf.getField();
    boolean reverse = sf.getReverse();
    SchemaField schemaField = schema.getField(field);
    FieldType ft = schemaField.getType();

    if(!schemaField.hasDocValues()) {
      throw new IOException(field+" must have DocValues to use this feature.");
    }

    if(ft instanceof TrieIntField) {
      if(reverse) {
        sortValues[i] = new IntValue(field, new IntDesc());
      } else {
        sortValues[i] = new IntValue(field, new IntAsc());
      }
    } else if(ft instanceof TrieFloatField) {
      if(reverse) {
        sortValues[i] = new FloatValue(field, new FloatDesc());
      } else {
        sortValues[i] = new FloatValue(field, new FloatAsc());
      }
    } else if(ft instanceof TrieDoubleField) {
      if(reverse) {
        sortValues[i] = new DoubleValue(field, new DoubleDesc());
      } else {
        sortValues[i] = new DoubleValue(field, new DoubleAsc());
      }
    } else if(ft instanceof TrieLongField) {
      if(reverse) {
        sortValues[i] = new LongValue(field, new LongDesc());
      } else {
        sortValues[i] = new LongValue(field, new LongAsc());
      }
    } else if(ft instanceof StrField) {
      AtomicReader reader = searcher.getAtomicReader();
      SortedDocValues vals =  reader.getSortedDocValues(field);
      if(reverse) {
        sortValues[i] = new StringValue(vals, field, new IntDesc());
      } else {
        sortValues[i] = new StringValue(vals, field, new IntAsc());
      }
    } else {
      throw new IOException("Sort fields must be one of the following types: int,float,long,double,string");
    }
  }

  if(sortValues.length == 1) {
    return new SingleValueSortDoc(sortValues[0]);
  } else if(sortValues.length == 2) {
    return new DoubleValueSortDoc(sortValues[0], sortValues[1]);
  } else if(sortValues.length == 3) {
    return new TripleValueSortDoc(sortValues[0], sortValues[1], sortValues[2]);
  } else if(sortValues.length == 4) {
    return new QuadValueSortDoc(sortValues[0], sortValues[1], sortValues[2], sortValues[3]);
  } else {
    throw new IOException("A max of 4 sorts can be specified");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:SortingResponseWriter.java


注:本文中的org.apache.lucene.search.SortField.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。