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


Java SortField.Type方法代码示例

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


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

示例1: randomOfType

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private Object randomOfType(SortField.Type type) {
    switch (type) {
    case CUSTOM:
        throw new UnsupportedOperationException();
    case DOC:
        return between(0, IndexWriter.MAX_DOCS);
    case DOUBLE:
        return randomDouble();
    case FLOAT:
        return randomFloat();
    case INT:
        return randomInt();
    case LONG:
        return randomLong();
    case REWRITEABLE:
        throw new UnsupportedOperationException();
    case SCORE:
        return randomFloat();
    case STRING:
        return new BytesRef(randomAsciiOfLength(5));
    case STRING_VAL:
        return new BytesRef(randomAsciiOfLength(5));
    default:
        throw new UnsupportedOperationException("Unkown SortField.Type: " + type);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:InternalTopHitsTests.java

示例2: missingValue

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
/** Calculates the missing Values as in {@link org.elasticsearch.index.fielddata.IndexFieldData}
 * The results in the {@link org.apache.lucene.search.ScoreDoc} contains this missingValues instead of nulls. Because we
 * need nulls in the result, it's necessary to check if a value is a missingValue.
 */
public static Object missingValue(boolean reverseFlag, Boolean nullFirst, SortField.Type type) {
    boolean min = reverseFlag ^ (nullFirst != null ? nullFirst : reverseFlag);
    switch (type) {
        case INT:
        case LONG:
            return min ? Long.MIN_VALUE : Long.MAX_VALUE;
        case FLOAT:
            return min ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
        case DOUBLE:
            return min ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
        case STRING:
        case STRING_VAL:
            return min ? null : MAX_TERM;
        default:
            throw new UnsupportedOperationException("Unsupported reduced type: " + type);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:LuceneMissingValue.java

示例3: getInstance

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
@Override
public MergePolicy getInstance(Map<String, String> params) throws IOException {
  String field = params.get(SORT_FIELD);
  SortField.Type sortFieldType = SortField.Type.DOC;
  if (params.containsKey(SORT_FIELD_TYPE)) {
    sortFieldType = SortField.Type.valueOf(params.get(SORT_FIELD_TYPE).toUpperCase());
  }

  if (sortFieldType == SortField.Type.DOC) {
    throw new IOException(
        "Relying on internal lucene DocIDs is not guaranteed to work, this is only an implementation detail.");
  }

  boolean desc = true;
  if (params.containsKey(SORT_DESC)) {
    try {
      desc = Boolean.valueOf(params.get(SORT_DESC));
    } catch (Exception e) {
      desc = true;
    }
  }
  SortField sortField = new SortField(field, sortFieldType, desc);
  Sort sort = new Sort(sortField);
  return new SortingMergePolicyDecorator(new TieredMergePolicy(), sort);
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:26,代码来源:SortingMergePolicyFactory.java

示例4: sortNumeric

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
/**
 * Sort the results of a numeric range query if the query in this context
 * is a {@link NumericRangeQuery}, see {@link #numericRange(String, Number, Number)},
 * Otherwise an {@link IllegalStateException} will be thrown.
 *
 * @param key the key to sort on.
 * @param reversed if the sort order should be reversed or not. {@code true}
 * for lowest first (ascending), {@code false} for highest first (descending)
 * @return a QueryContext with sorting by numeric value.
 */
public QueryContext sortNumeric( String key, boolean reversed )
{
    if ( !( queryOrQueryObject instanceof NumericRangeQuery ) )
    {
        throw new IllegalStateException( "Not a numeric range query" );
    }

    Number number = ((NumericRangeQuery)queryOrQueryObject).getMin();
    number = number != null ? number : ((NumericRangeQuery)queryOrQueryObject).getMax();
    SortField.Type fieldType = SortField.Type.INT;
    if ( number instanceof Long )
    {
        fieldType = SortField.Type.LONG;
    }
    else if ( number instanceof Float )
    {
        fieldType = SortField.Type.FLOAT;
    }
    else if ( number instanceof Double )
    {
        fieldType = SortField.Type.DOUBLE;
    }
    sort( new Sort( new SortedNumericSortField( key, fieldType, reversed ) ) );
    return this;
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:36,代码来源:QueryContext.java

示例5: readSortField

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
public static SortField readSortField(StreamInput in) throws IOException {
    String field = null;
    if (in.readBoolean()) {
        field = in.readString();
    }
    SortField.Type sortType = readSortType(in);
    Object missingValue = readMissingValue(in);
    boolean reverse = in.readBoolean();
    SortField sortField = new SortField(field, sortType, reverse);
    if (missingValue != null) {
        sortField.setMissingValue(missingValue);
    }
    return sortField;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:Lucene.java

示例6: randomSortFields

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private SortField[] randomSortFields() {
    SortField[] sortFields = new SortField[between(1, 5)];
    Set<String> usedSortFields = new HashSet<>();
    for (int i = 0; i < sortFields.length; i++) {
        String sortField = randomValueOtherThanMany(usedSortFields::contains, () -> randomAsciiOfLength(5));
        usedSortFields.add(sortField);
        SortField.Type type = randomValueOtherThanMany(t -> t == SortField.Type.CUSTOM || t == SortField.Type.REWRITEABLE,
                () -> randomFrom(SortField.Type.values()));
        sortFields[i] = new SortField(sortField, type);
    }
    return sortFields;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:InternalTopHitsTests.java

示例7: SortedNumericSortField

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
/**
 * Creates a sort, possibly in reverse, specifying how the sort value from 
 * the document's set is selected.
 * @param field Name of field to sort by.  Must not be null.
 * @param type Type of values
 * @param reverse True if natural order should be reversed.
 * @param selector custom selector type for choosing the sort value from the set.
 */
public SortedNumericSortField(String field, SortField.Type type, boolean reverse, SortedNumericSelector.Type selector) {
  super(field, SortField.Type.CUSTOM, reverse);
  if (selector == null) {
    throw new NullPointerException();
  }
  if (type == null) {
    throw new NullPointerException();
  }
  this.selector = selector;
  this.type = type;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SortedNumericSortField.java

示例8: toLuceneSort

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private Sort toLuceneSort(List<SearchFieldSorting> orderings) {
  if (orderings.isEmpty()) {
    return new Sort();
  }

  SortField[] sortFields = new SortField[orderings.size()];
  int i = 0;
  for(SearchFieldSorting ordering: orderings) {
    final SortField.Type fieldType;
    switch(ordering.getType()) {
    case STRING:
      fieldType = SortField.Type.STRING;
      break;
    case LONG:
      fieldType = SortField.Type.LONG;
      break;
    case DOUBLE:
      fieldType = SortField.Type.DOUBLE;
      break;
    case INTEGER:
      fieldType = SortField.Type.INT;
      break;
    default:
      throw new AssertionError("Unknown field type: " + ordering.getType());
    }
    sortFields[i++] = new SortField(ordering.getField(), fieldType, ordering.getOrder() != SortOrder.ASCENDING);
  }

  return new Sort(sortFields);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:31,代码来源:CoreIndexedStoreImpl.java

示例9: getSort

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
/**
 * Converts the Tripod Sort clauses to a Lucene Sort instance.
 *
 * @param sorts the Tripod Sorts
 * @return the Lucene Sort matching the given Tripod Sorts,
 *              or the Lucene Sort for relevance order if no sorts are specified
 */
public static Sort getSort(final List<com.bbende.tripod.api.query.Sort> sorts,
                           final SortTypeFactory sortTypeFactory) {
    if (sorts == null || sorts.isEmpty()) {
        return Sort.RELEVANCE;
    } else {
        List<SortField> luceneSorts = new ArrayList<>();
        for (com.bbende.tripod.api.query.Sort sort : sorts) {
            boolean reverse = (sort.getSortOrder() == SortOrder.DESC);
            SortField.Type sortType =  sortTypeFactory.getSortType(sort.getField());
            luceneSorts.add(new SortField(sort.getField().getName(), sortType, reverse));
        }
        return new Sort(luceneSorts.toArray(new SortField[luceneSorts.size()]));
    }
}
 
开发者ID:bbende,项目名称:tripod,代码行数:22,代码来源:LuceneServiceUtil.java

示例10: setMissingValuesOrder

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private void setMissingValuesOrder(SortField sf, SortField.Type type, boolean desc) {
    switch (type) {
        case STRING:
            sf.setMissingValue(desc ? SortField.STRING_FIRST : SortField.STRING_LAST);
            break;
        case FLOAT:
            sf.setMissingValue(Float.MIN_VALUE);
            break;
        case INT:
            sf.setMissingValue(Integer.MIN_VALUE);
            break;
        default:
            throw new IllegalArgumentException("Unexpected sort type: " + type);
    }
}
 
开发者ID:epam,项目名称:NGB,代码行数:16,代码来源:FeatureIndexDao.java

示例11: determineSortType

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private SortField.Type determineSortType(InfoItem item) {
    switch (item.getType()) {
        case Integer:
            return SortField.Type.INT;
        case Float:
            return SortField.Type.FLOAT;
        default:
            return SortField.Type.STRING;
    }
}
 
开发者ID:epam,项目名称:NGB,代码行数:11,代码来源:FeatureIndexDao.java

示例12: ShardFieldSortedHitQueue

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
public ShardFieldSortedHitQueue(SortField[] fields, int size, IndexSearcher searcher) {
  super(size);
  final int n = fields.length;
  //noinspection unchecked
  comparators = new Comparator[n];
  this.fields = new SortField[n];
  for (int i = 0; i < n; ++i) {

    // keep track of the named fields
    SortField.Type type = fields[i].getType();
    if (type!=SortField.Type.SCORE && type!=SortField.Type.DOC) {
      fieldNames.add(fields[i].getField());
    }

    String fieldname = fields[i].getField();
    comparators[i] = getCachedComparator(fields[i], searcher);

   if (fields[i].getType() == SortField.Type.STRING) {
      this.fields[i] = new SortField(fieldname, SortField.Type.STRING,
          fields[i].getReverse());
    } else {
      this.fields[i] = new SortField(fieldname, fields[i].getType(),
          fields[i].getReverse());
    }

    //System.out.println("%%%%%%%%%%%%%%%%%% got "+fields[i].getType() +"   for "+ fieldname +"  fields[i].getReverse(): "+fields[i].getReverse());
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:ShardDoc.java

示例13: getCachedComparator

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
Comparator<ShardDoc> getCachedComparator(SortField sortField, IndexSearcher searcher) {
  SortField.Type type = sortField.getType();
  if (type == SortField.Type.SCORE) {
    return comparatorScore();
  } else if (type == SortField.Type.REWRITEABLE) {
    try {
      sortField = sortField.rewrite(searcher);
    } catch (IOException e) {
      throw new SolrException(SERVER_ERROR, "Exception rewriting sort field " + sortField, e);
    }
  }
  return comparatorFieldComparator(sortField);
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:ShardDoc.java

示例14: create

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
  if(params == null) {
    // should not happen; implies setParams was not called
    throw new IllegalStateException("Value of params not set");
  }
  
  String field = (String) params.get(FIELD);
  String payloadField = (String) params.get(PAYLOAD_FIELD);
  String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
  Set<SortField> sortFields = new HashSet<>();
  
  if (field == null) {
    throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
  }
  
  if (weightExpression == null) {
    throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
  }
  
  for(int i = 0; i < params.size(); i++) {
    if (params.getName(i).equals(SORT_FIELD)) {
      String sortFieldName = (String) params.getVal(i);

      SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);
      
      if (sortFieldType == null) {
        throw new IllegalArgumentException(sortFieldName + " could not be mapped to any appropriate type"
            + " [long, int, float, double]");
      }
      
      SortField sortField = new SortField(sortFieldName, sortFieldType);
      sortFields.add(sortField);
    }
  }
 
  return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
      sortFields), payloadField);
}
 
开发者ID:europeana,项目名称:search,代码行数:40,代码来源:DocumentExpressionDictionaryFactory.java

示例15: getSortFieldType

import org.apache.lucene.search.SortField; //导入方法依赖的package包/类
private SortField.Type getSortFieldType(SolrCore core, String sortFieldName) {
  SortField.Type type = null;
  String fieldTypeName = core.getLatestSchema().getField(sortFieldName).getType().getTypeName();
  FieldType ft = core.getLatestSchema().getFieldTypes().get(fieldTypeName);
  if (ft instanceof FloatField || ft instanceof TrieFloatField) {
    type = SortField.Type.FLOAT;
  } else if (ft instanceof IntField || ft instanceof TrieIntField) {
    type = SortField.Type.INT;
  } else if (ft instanceof LongField || ft instanceof TrieLongField) {
    type = SortField.Type.LONG;
  } else if (ft instanceof DoubleField || ft instanceof TrieDoubleField) {
    type = SortField.Type.DOUBLE;
  }
  return type;
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:DocumentExpressionDictionaryFactory.java


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