org.apache.lucene.search.SortField.Type Java Examples
The following examples show how to use
org.apache.lucene.search.SortField.Type.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSort.java From lucene-solr with Apache License 2.0 | 6 votes |
private static SortField getStringSortField(String fieldName, boolean reverse, boolean nullLast, boolean nullFirst) { SortField sortField = new SortField(fieldName, SortField.Type.STRING, reverse); // 4 cases: // missingFirst / forward: default lucene behavior // missingFirst / reverse: set sortMissingLast // missingLast / forward: set sortMissingLast // missingLast / reverse: default lucene behavior if (nullFirst && reverse) { sortField.setMissingValue(SortField.STRING_LAST); } else if (nullLast && !reverse) { sortField.setMissingValue(SortField.STRING_LAST); } return sortField; }
Example #2
Source File: TestingPagingCollector.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@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(); }
Example #3
Source File: FloatFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.FLOAT, reverse); } return new SortField(getFieldName(), Type.FLOAT); }
Example #4
Source File: AclDiscoverFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.STRING, reverse); } return new SortField(getFieldName(), Type.STRING); }
Example #5
Source File: ChildFieldValueSourceParser.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { final Type type = childField.getSortField(reverse).getType(); return new ToParentBlockJoinSortField(childField.getName(), type, reverse, parentFilter, childFilter) { @SuppressWarnings("unchecked") @Override public FieldComparator<?> getComparator(int numHits, int sortPos) { final FieldComparator<?> comparator = super.getComparator(numHits, sortPos); return type ==Type.STRING ? new BytesToStringComparator((FieldComparator<BytesRef>) comparator) : comparator; } }; }
Example #6
Source File: IntFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.INT, reverse); } return new SortField(getFieldName(), Type.INT); }
Example #7
Source File: AclReadFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.STRING, reverse); } return new SortField(getFieldName(), Type.STRING); }
Example #8
Source File: DoubleFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.DOUBLE, reverse); } return new SortField(getFieldName(), Type.DOUBLE); }
Example #9
Source File: LongFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.LONG, reverse); } return new SortField(getFieldName(), Type.LONG); }
Example #10
Source File: StringFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.STRING, reverse); } return new SortField(getFieldName(), Type.STRING); }
Example #11
Source File: DateFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public SortField getSortField(boolean reverse) { if (reverse) { return new SortField(getFieldName(), Type.LONG, reverse); } return new SortField(getFieldName(), Type.LONG); }
Example #12
Source File: ColumnMapperText.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #13
Source File: ColumnMapperBigDecimal.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #14
Source File: ColumnMapperLong.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.LONG, reverse); }
Example #15
Source File: ColumnMapperDouble.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.DOUBLE, reverse); }
Example #16
Source File: ColumnMapperUUID.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #17
Source File: ColumnMapperBoolean.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #18
Source File: FloatFieldSource.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public SortField getSortField(boolean reverse) { return new SortField(field, Type.FLOAT, reverse); }
Example #19
Source File: ColumnMapperDate.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.LONG, reverse); }
Example #20
Source File: ColumnMapperInet.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #21
Source File: ColumnMapperInteger.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.INT, reverse); }
Example #22
Source File: ColumnMapperString.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #23
Source File: ColumnMapperBigInteger.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #24
Source File: ColumnMapperFloat.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.FLOAT, reverse); }
Example #25
Source File: ColumnMapperBlob.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.STRING, reverse); }
Example #26
Source File: GeoShapeMapper.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public SortField sortField(String field, boolean reverse) { return new SortField(field, Type.LONG, reverse); }
Example #27
Source File: TestSort.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testRandomFieldNameSorts() throws Exception { SolrQueryRequest req = lrf.makeRequest("q", "*:*"); final int iters = atLeast(5000); // infinite loop abort when trying to generate a non-blank sort "name" final int nonBlankAttempts = 37; for (int i = 0; i < iters; i++) { final StringBuilder input = new StringBuilder(); final String[] names = new String[TestUtil.nextInt(r, 1, 10)]; final boolean[] reverse = new boolean[names.length]; for (int j = 0; j < names.length; j++) { names[j] = null; for (int k = 0; k < nonBlankAttempts && null == names[j]; k++) { names[j] = TestUtil.randomRealisticUnicodeString(r, 1, 100); // munge anything that might make this a function names[j] = names[j].replaceFirst("\\{","\\}\\{"); names[j] = names[j].replaceFirst("\\(","\\)\\("); names[j] = names[j].replaceFirst("(\\\"|\\')","$1$1z"); names[j] = names[j].replaceFirst("(\\d)","$1x"); // eliminate pesky problem chars names[j] = names[j].replaceAll("\\p{Cntrl}|\\p{javaWhitespace}",""); if (0 == names[j].length()) { names[j] = null; } } // with luck this bad, never go to vegas // alternatively: if (null == names[j]) names[j] = "never_go_to_vegas"; assertNotNull("Unable to generate a (non-blank) names["+j+"] after " + nonBlankAttempts + " attempts", names[j]); reverse[j] = r.nextBoolean(); input.append(r.nextBoolean() ? " " : ""); input.append(names[j]); input.append(" "); input.append(reverse[j] ? "desc," : "asc,"); } input.deleteCharAt(input.length()-1); SortField[] sorts = null; List<SchemaField> fields = null; try { SortSpec spec = SortSpecParsing.parseSortSpec(input.toString(), req); sorts = spec.getSort().getSort(); fields = spec.getSchemaFields(); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse sort: " + input, e); } assertEquals("parsed sorts had unexpected size", names.length, sorts.length); assertEquals("parsed sort schema fields had unexpected size", names.length, fields.size()); for (int j = 0; j < names.length; j++) { assertEquals("sorts["+j+"] had unexpected reverse: " + input, reverse[j], sorts[j].getReverse()); final Type type = sorts[j].getType(); if (Type.SCORE.equals(type)) { assertEquals("sorts["+j+"] is (unexpectedly) type score : " + input, "score", names[j]); } else if (Type.DOC.equals(type)) { assertEquals("sorts["+j+"] is (unexpectedly) type doc : " + input, "_docid_", names[j]); } else if (Type.CUSTOM.equals(type) || Type.REWRITEABLE.equals(type)) { log.error("names[{}] : {}", j, names[j]); log.error("sorts[{}] : {}", j, sorts[j]); fail("sorts["+j+"] resulted in a '" + type.toString() + "', either sort parsing code is broken, or func/query " + "semantics have gotten broader and munging in this test " + "needs improved: " + input); } else { assertEquals("sorts["+j+"] ("+type.toString()+ ") had unexpected field in: " + input, names[j], sorts[j].getField()); assertEquals("fields["+j+"] ("+type.toString()+ ") had unexpected name in: " + input, names[j], fields.get(j).getName()); } } } }
Example #28
Source File: DoubleFieldSource.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public SortField getSortField(boolean reverse) { return new SortField(field, Type.DOUBLE, reverse); }
Example #29
Source File: IntFieldSource.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public SortField getSortField(boolean reverse) { return new SortField(field, Type.INT, reverse); }
Example #30
Source File: LongFieldSource.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public SortField getSortField(boolean reverse) { return new SortField(field, Type.LONG, reverse); }