當前位置: 首頁>>代碼示例>>Java>>正文


Java SortField.STRING屬性代碼示例

本文整理匯總了Java中org.apache.lucene.search.SortField.STRING屬性的典型用法代碼示例。如果您正苦於以下問題:Java SortField.STRING屬性的具體用法?Java SortField.STRING怎麽用?Java SortField.STRING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.lucene.search.SortField的用法示例。


在下文中一共展示了SortField.STRING屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractCategories

public List<String> extractCategories() {

        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
                em );

        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(
                Categories.class ).get();
        org.apache.lucene.search.Query query = queryBuilder.all().createQuery();

        FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
                                                                                 Categories.class );
        fullTextQuery.setProjection( FullTextQuery.ID , "category" );
        Sort sort = new Sort( new SortField( "category" , SortField.STRING ) );
        fullTextQuery.setSort( sort );

        //fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
        List<String> results = fullTextQuery.getResultList();

        return results;
    }
 
開發者ID:juliocnsouzadev,項目名稱:omg_mongodb,代碼行數:20,代碼來源:EShopBean.java

示例2: selectAll

public Result selectAll(Query query, String sortPrefix){
  try {
    BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
    Searcher searcher = new IndexSearcher(indexPath);
    Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix))
      hits = searcher.search(query);
    else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(query, new Sort(
          new SortField(sortPrefix, sortType)));
    }
    
    int n = hits.length();
    int[] retVal = new int[n];
    List<String> invs = new ArrayList<String>();
    Field[] tmp = null;
    
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
      tmp = hits.doc(i).getFields("IN");
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
          invs.add(tmp[j].stringValue());
        } 
      }
    }
    searcher.close();
    Result result = new Result();
    result.setRecords(retVal);
    result.setInvs(invs);
    return result;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:40,代碼來源:Retriever.java

示例3: select

public int[] select(Query query, Filter filter, String sortPrefix){
  try {
    BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
    Searcher searcher = new IndexSearcher(indexPath);
    Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix)){
       hits = searcher.search(query,filter);
    } else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(query,filter, new Sort(
          new SortField(sortPrefix, sortType)));
 }
    int n = hits.length();
    int[] retVal = new int[n];
  
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
    }
    searcher.close();
    return retVal;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:28,代碼來源:Retriever.java

示例4: sortType

public int sortType( String field ) {
    Class<?> tp = fieldType( field );
    if ( tp.isAssignableFrom( String.class ) )
        return SortField.STRING;
    if ( tp.isAssignableFrom( Integer.class ) )
        return SortField.INT;
    if ( tp.isAssignableFrom( Float.class ) )
        return SortField.FLOAT;
    else
        return SortField.STRING;
}
 
開發者ID:webdsl,項目名稱:webdsl,代碼行數:11,代碼來源:AbstractEntitySearcher.java

示例5: getSorter

/**
 * Takes a search request and prepares a Lucene Sort object, or null if no
 * sorting is required.
 */
private Sort getSorter(Search request)
{
	com.tle.common.searching.SortField[] sortfields = request.getSortFields();
	if( sortfields != null )
	{
		SortField[] convFields = new SortField[sortfields.length];
		int i = 0;
		for( com.tle.common.searching.SortField sortfield : sortfields )
		{
			FieldComparatorSource fieldComparatorSource = null;
			int type = SortField.STRING;
			switch( sortfield.getType() )
			{
				case INT:
					type = SortField.INT;
					break;
				case LONG:
					type = SortField.LONG;
					break;
				case SCORE:
					type = SortField.SCORE;
					break;
				case CUSTOM:
					type = SortField.CUSTOM;
					fieldComparatorSource = sortfield.getFieldComparatorSource();
				default:
					// Stays STRING
					break;
			}
			// @formatter:off
			SortField sortField = fieldComparatorSource != null
				? new SortField(sortfield.getField(), fieldComparatorSource, request.isSortReversed())
					: new SortField(sortfield.getField(), type, sortfield.isReverse() ^ request.isSortReversed());
			// @formatter:on
			convFields[i++] = sortField;
		}
		return new Sort(convFields);
	}
	return new Sort(new SortField(null, SortField.SCORE, false));
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:44,代碼來源:ItemIndex.java

示例6: selectAll1

public Result selectAll1(String query, String sortPrefix)throws ParseException{
  try {
  	WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
  	Searcher searcher = new IndexSearcher(indexPath);
      BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
      QueryParser p = new QueryParser("KW", sa);
      p.setDefaultOperator(QueryParser.Operator.AND); //default operator je AND a ne OR kao sto je inace inicijalno
      Query q = p.parse(query);
      Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix))
      hits = searcher.search(q);
    else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(q, new Sort(
          new SortField(sortPrefix, sortType)));
    }
    
    int n = hits.length();
    int[] retVal = new int[n];
    List<String> invs = new ArrayList<String>();
    Field[] tmp = null;
    
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
      tmp = hits.doc(i).getFields("IN");
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
          invs.add(tmp[j].stringValue());
        } 
      }
    }
    searcher.close();
    Result result = new Result();
    result.setRecords(retVal);
    result.setInvs(invs);
    return result;
  } catch (Exception ex) {
  	if (ex instanceof ParseException )
  		throw (ParseException)ex;
    log.fatal(ex);
    return null;
  }
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:46,代碼來源:Retriever.java

示例7: processSort

/**
 * 處理排序
 * 
 * @param inquiry
 * @param fullTextQuery
 */
protected void processSort(Inquiry inquiry, FullTextQuery fullTextQuery) {
	// 排序
	Sort sort = inquiry.getSort();
	// 排序欄位選項
	List<Sort> sorts = inquiry.getSorts();
	if (sort == null || StringHelper.isBlank(sort.getId())) {
		// 若目前排序欄位為null,則取排序欄位選項第一個
		if (CollectionHelper.notEmpty(sorts)) {
			sort = sorts.get(0);
		}
	}
	//
	if (sort != null && StringHelper.notBlank(sort.getId())) {
		// 排序方向
		Order order = inquiry.getOrder();
		if (order == null || order.getId() == null) {
			order = sort.getOrder();
			if (order == null || order.getId() == null) {
				// 排序方向選項
				List<Order> orders = inquiry.getOrders();
				// 若目前排序方向為null,則取排序方向選項第一個
				if (CollectionHelper.notEmpty(orders)) {
					order = orders.get(0);
				}
			}
		}
		//
		if (order != null && order.getId() != null) {
			// 不是自然方向
			if (order.getId() != OrderType.NATURAL) {
				// 升冪
				boolean reverse = (OrderType.ASC != order.getId());
				// false:升序, true:降序
				SortField sortField = new SortField(sort.getId(), SortField.STRING, reverse);
				//
				org.apache.lucene.search.Sort luceneSort = new org.apache.lucene.search.Sort();
				luceneSort.setSort(sortField);
				//
				fullTextQuery.setSort(luceneSort);
			}
		}
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:49,代碼來源:CommonDaoSupporter.java

示例8: defineOrder

public <T> void defineOrder(RestSearchKey key, FullTextQuery fullTextQuery) {

		String[] orderBy = key.getOrders();

		SortField[] sortFields = new SortField[orderBy.length];

		Sort sort = new Sort();

		for(int i = 0; i < orderBy.length; i++) {

			sortFields[i] = key.isDesc() ? new SortField(orderBy[i], SortField.STRING, false) : new SortField(orderBy[i], SortField.STRING, true);
		}		

		sort.setSort(sortFields);

		fullTextQuery.setSort(sort);
	}
 
開發者ID:mcraken,項目名稱:spring-scaffy,代碼行數:17,代碼來源:HibernateSearchBuilder.java


注:本文中的org.apache.lucene.search.SortField.STRING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。