本文整理汇总了Java中org.apache.lucene.search.SortField.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于org.apache.lucene.search.SortField包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToSort
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
Sort convertToSort(JsonArray sortKeys) {
if (sortKeys == null || sortKeys.size() == 0)
return null;
SortField[] sortFields = new SortField[sortKeys.size()];
for (int i = 0; i < sortKeys.size(); i++) {
JsonObject sortKey = sortKeys.getJsonObject(i);
String sortBy = sortKey.getString("sortBy");
boolean sortDescending = sortKey.getBoolean("sortDescending", false);
String core = sortKey.getString("core", null);
SortField field;
if (sortBy.equals(SORT_ON_SCORE))
field = new SortField(null, SortField.Type.SCORE, !sortDescending);
else {
Type type = typeForSortField(sortKey.getString("type"));
if (core == null || core.equals(coreName))
field = new SortField(sortBy, type, sortDescending);
else
field = new JoinSortField(sortBy, type, sortDescending, core);
Object missingValue = missingSortValue(sortKey, type);
if (missingValue != null)
field.setMissingValue(missingValue);
}
sortFields[i] = field;
}
return new Sort(sortFields);
}
示例2: missingSortValue
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
private Object missingSortValue(JsonObject sortKey, Type type) {
JsonValue missingValue = sortKey.getOrDefault("missingValue", null);
if (missingValue == null)
return null;
if (missingValue instanceof JsonString) {
if (((JsonString) missingValue).getString().equals("STRING_FIRST"))
return SortField.STRING_FIRST;
else if (((JsonString) missingValue).getString().equals("STRING_LAST"))
return SortField.STRING_LAST;
} else {
switch (type) {
case INT:
return ((JsonNumber) missingValue).intValue();
case LONG:
return ((JsonNumber) missingValue).longValue();
case DOUBLE:
return ((JsonNumber) missingValue).doubleValue();
default:
break;
}
}
return null;
}
示例3: browseAllDocs
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
/**
* Finds the top n hits from whole Index where all results are after a
* previous result (after)
*
* @param after
* the last doc from previous search
* @param nDocs
* nb of elements to retrieve in total
* @return
*/
public BrowseAllDocsResponse browseAllDocs(ScoreDoc after, int nDocs) {
List<String> listOfDocReferences = new ArrayList<String>();
IndexSearcher searcher = null;
try {
searcher = iaviewSearcherManager.acquire();
TopDocs topDocs = searcher.searchAfter(after, new MatchAllDocsQuery(), nDocs, new Sort(new SortField(null,
Type.DOC)));
ScoreDoc scoreDoc = null;
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
scoreDoc = topDocs.scoreDocs[i];
Document document = searcher.doc(scoreDoc.doc,
new HashSet<String>(Arrays.asList(InformationAssetViewFields.DOCREFERENCE.toString())));
String docReferenceFromLuceneDocument = LuceneTaxonomyMapper
.getDocReferenceFromLuceneDocument(document);
listOfDocReferences.add(docReferenceFromLuceneDocument);
}
return new BrowseAllDocsResponse(listOfDocReferences, scoreDoc);
} catch (IOException ioException) {
throw new TaxonomyException(TaxonomyErrorType.LUCENE_IO_EXCEPTION, ioException);
} finally {
LuceneHelperTools.releaseSearcherManagerQuietly(iaviewSearcherManager, searcher);
}
}
示例4: getSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Override
public SortField getSortField(boolean reverse) {
if (reverse) {
return new SortField(getFieldName(), Type.LONG, reverse);
}
return new SortField(getFieldName(), Type.LONG);
}
示例5: getSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Override
public SortField getSortField(boolean reverse) {
if (reverse) {
return new SortField(getFieldName(), Type.STRING, reverse);
}
return new SortField(getFieldName(), Type.STRING);
}
示例6: getSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Override
public SortField getSortField(boolean reverse) {
if (reverse) {
return new SortField(getFieldName(), Type.DOUBLE, reverse);
}
return new SortField(getFieldName(), Type.DOUBLE);
}
示例7: getSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Override
public SortField getSortField(boolean reverse) {
if (reverse) {
return new SortField(getFieldName(), Type.INT, reverse);
}
return new SortField(getFieldName(), Type.INT);
}
示例8: getSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Override
public SortField getSortField(boolean reverse) {
if (reverse) {
return new SortField(getFieldName(), Type.FLOAT, reverse);
}
return new SortField(getFieldName(), Type.FLOAT);
}
示例9: testSimpleSearchPagingWithSorting
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Test
public void testSimpleSearchPagingWithSorting() throws Exception {
IndexReader reader = getReaderFlatScore(length);
IndexSearcherCloseable searcher = getSearcher(reader);
TotalHitsRef totalHitsRef = new TotalHitsRef();
ProgressRef progressRef = new ProgressRef();
printHeapSize();
TermQuery query = new TermQuery(new Term("f1", "value"));
Sort sort = new Sort(new SortField("index", Type.INT, true));
IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query, 100, null, null, false, sort,
new DeepPagingCache());
IterablePaging itPaging = paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef);
BlurIterator<ScoreDoc, BlurException> iterator = itPaging.iterator();
int position = 90;
int searches = 1;
while (iterator.hasNext()) {
ScoreDoc sd = iterator.next();
assertEquals(position, progressRef.currentHitPosition());
assertEquals(searches, progressRef.searchesPerformed());
System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits() + "] "
+ "searches [" + progressRef.searchesPerformed() + "] " + "position [" + progressRef.currentHitPosition()
+ "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
position++;
if (position == 100) {
searches++;
}
}
printHeapSize();
}
示例10: getComparator
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
public FieldComparator<?> getComparator(String field, Type type, boolean reverse, final int numHits, final int sortPos, Object missingValue) {
switch(type) {
case STRING:
return new JoinTermOrdValComparator(numHits, field, missingValue == SortField.STRING_LAST, this);
case INT:
return new JoinIntComparator(numHits, field, (Integer) missingValue, this);
case DOUBLE:
return new JoinDoubleComparator(numHits, field, (Double) missingValue, this);
default:
throw new IllegalStateException("Illegal join sort type: " + type);
}
}
示例11: typeForSortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
private SortField.Type typeForSortField(String type) {
switch (type) {
case "String":
return SortField.Type.STRING;
case "Int":
return SortField.Type.INT;
case "Double":
return SortField.Type.DOUBLE;
case "Long":
return SortField.Type.LONG;
}
return null;
}
示例12: testEmptyIndex
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
@Test
public void testEmptyIndex() throws Exception {
// LUCENE-5045: make sure DrillSideways works with an empty index
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
writer = new RandomIndexWriter(random(), dir);
taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
IndexSearcher searcher = newSearcher(writer.getReader());
writer.close();
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
taxoWriter.close();
// Count "Author"
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("Author"), 10));
DrillSideways ds = new DrillSideways(searcher, taxoReader);
DrillDownQuery ddq = new DrillDownQuery(fsp.indexingParams, new MatchAllDocsQuery());
ddq.add(new CategoryPath("Author", "Lisa"));
DrillSidewaysResult r = ds.search(null, ddq, 10, fsp); // this used to fail on IllegalArgEx
assertEquals(0, r.hits.totalHits);
r = ds.search(ddq, null, null, 10, new Sort(new SortField("foo", Type.INT)), false, false, fsp); // this used to fail on IllegalArgEx
assertEquals(0, r.hits.totalHits);
IOUtils.close(searcher.getIndexReader(), taxoReader, dir, taxoDir);
}
示例13: sortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public SortField sortField(String field, boolean reverse) {
return new SortField(field, Type.LONG, reverse);
}
示例14: sortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public SortField sortField(String field, boolean reverse) {
return new SortField(field, Type.STRING, reverse);
}
示例15: sortField
import org.apache.lucene.search.SortField.Type; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public SortField sortField(String field, boolean reverse) {
return new SortField(field, Type.FLOAT, reverse);
}