本文整理汇总了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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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));
}
示例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;
}
}
示例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);
}
}
}
}
示例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);
}