/** Confirms that the incoming index sort (if any) matches the existing index sort (if any). * This is unfortunately just best effort, because it could be the old index only has unsorted flushed segments built * before {@link Version#LUCENE_6_5_0} (flushed segments are sorted in Lucene 7.0). */ private void validateIndexSort() throws CorruptIndexException { Sort indexSort = config.getIndexSort(); if (indexSort != null) { for(SegmentCommitInfo info : segmentInfos) { Sort segmentIndexSort = info.info.getIndexSort(); if (segmentIndexSort != null && indexSort.equals(segmentIndexSort) == false) { throw new IllegalArgumentException("cannot change previous indexSort=" + segmentIndexSort + " (from segment=" + info + ") to new indexSort=" + indexSort); } else if (segmentIndexSort == null && info.info.getVersion().onOrAfter(Version.LUCENE_6_5_0)) { // Flushed segments are not sorted if they were built with a version prior to 6.5.0 throw new CorruptIndexException("segment not sorted with indexSort=" + segmentIndexSort, info.info.toString()); } } } }
private void validateMergeReader(CodecReader leaf) { LeafMetaData segmentMeta = leaf.getMetaData(); if (segmentInfos.getIndexCreatedVersionMajor() != segmentMeta.getCreatedVersionMajor()) { throw new IllegalArgumentException("Cannot merge a segment that has been created with major version " + segmentMeta.getCreatedVersionMajor() + " into this index which has been created by major version " + segmentInfos.getIndexCreatedVersionMajor()); } if (segmentInfos.getIndexCreatedVersionMajor() >= 7 && segmentMeta.getMinVersion() == null) { throw new IllegalStateException("Indexes created on or after Lucene 7 must record the created version major, but " + leaf + " hides it"); } Sort leafIndexSort = segmentMeta.getSort(); if (config.getIndexSort() != null && leafIndexSort != null && config.getIndexSort().equals(leafIndexSort) == false) { throw new IllegalArgumentException("cannot change index sort from " + leafIndexSort + " to " + config.getIndexSort()); } }
if (segmentSort.equals(indexSort) == false) { throw new IllegalArgumentException("index sort mismatch: merged segment has sort=" + indexSort + " but to-be-merged segment has sort=" + segmentSort);
if (indexSort == null) { indexSort = leafIndexSort; } else if (leafIndexSort != null && indexSort.equals(leafIndexSort) == false) { throw new IllegalArgumentException("cannot combine LeafReaders that have different index sorts: saw both sort=" + indexSort + " and " + leafIndexSort);
private boolean equalsTo(SearchAfterSortedDocQuery other) { return sort.equals(other.sort) && after.doc == other.after.doc && Double.compare(after.score, other.after.score) == 0 && Arrays.equals(after.fields, other.after.fields); }
/** * Returns true if the provided <code>query</code> returns docs in index order (internal doc ids). * @param query The query to execute * @param sf The query sort */ static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { if (sf == null || Sort.RELEVANCE.equals(sf.sort)) { // sort by score // queries that return constant scores will return docs in index // order since Lucene tie-breaks on the doc id return query.getClass() == ConstantScoreQuery.class || query.getClass() == MatchAllDocsQuery.class; } else { return Sort.INDEXORDER.equals(sf.sort); } }
msg(infoStream, " sort=" + indexSort); if (previousIndexSort != null) { if (previousIndexSort.equals(indexSort) == false) { throw new RuntimeException("index sort changed from " + previousIndexSort + " to " + indexSort);
if (indexSort != null && segmentIndexSort != null && indexSort.equals(segmentIndexSort) == false) {
private static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { if (sf == null || Sort.RELEVANCE.equals(sf.sort)) { // sort by score // queries that return constant scores will return docs in index // order since Lucene tie-breaks on the doc id return query.getClass() == ConstantScoreQuery.class || query.getClass() == MatchAllDocsQuery.class; } else { return Sort.INDEXORDER.equals(sf.sort); } }
private static boolean returnsDocsInOrder(Query query, Sort sort) { if (sort == null || Sort.RELEVANCE.equals(sort)) { // sort by score // queries that return constant scores will return docs in index // order since Lucene tie-breaks on the doc id return query.getClass() == ConstantScoreQuery.class || query.getClass() == MatchAllDocsQuery.class; } else { return Sort.INDEXORDER.equals(sort); } }
/** * Returns true if the provided <code>query</code> returns docs in index order (internal doc ids). * @param query The query to execute * @param sf The query sort */ static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { if (sf == null || Sort.RELEVANCE.equals(sf.sort)) { // sort by score // queries that return constant scores will return docs in index // order since Lucene tie-breaks on the doc id return query.getClass() == ConstantScoreQuery.class || query.getClass() == MatchAllDocsQuery.class; } else { return Sort.INDEXORDER.equals(sf.sort); } }
private boolean equalsTo(SearchAfterSortedDocQuery other) { return sort.equals(other.sort) && after.doc == other.after.doc && Double.compare(after.score, other.after.score) == 0 && Arrays.equals(after.fields, other.after.fields); }
private boolean equalsTo(SearchAfterSortedDocQuery other) { return sort.equals(other.sort) && after.doc == other.after.doc && Double.compare(after.score, other.after.score) == 0 && Arrays.equals(after.fields, other.after.fields); }
/** * Returns true if the provided <code>query</code> returns docs in index order (internal doc ids). * @param query The query to execute * @param sf The query sort */ static boolean returnsDocsInOrder(Query query, SortAndFormats sf) { if (sf == null || Sort.RELEVANCE.equals(sf.sort)) { // sort by score // queries that return constant scores will return docs in index // order since Lucene tie-breaks on the doc id return query.getClass() == ConstantScoreQuery.class || query.getClass() == MatchAllDocsQuery.class; } else { return Sort.INDEXORDER.equals(sf.sort); } }
public SearchGroupDocs(GROUP_VALUE_TYPE groupValue, TopDocsCollector<?> collector) { this.groupValue = groupValue; this.collector = collector; } }
/** * Create a new AllGroupHeadsCollector based on the type of within-group Sort required * @param selector a GroupSelector to define the groups * @param sort the within-group sort to use to choose the group head document * @param <T> the group value type */ public static <T> AllGroupHeadsCollector<T> newCollector(GroupSelector<T> selector, Sort sort) { if (sort.equals(Sort.RELEVANCE)) return new ScoringGroupHeadsCollector<>(selector, sort); return new SortingGroupHeadsCollector<>(selector, sort); }
/** Confirms that the incoming index sort (if any) matches the existing index sort (if any). * This is unfortunately just best effort, because it could be the old index only has unsorted flushed segments built * before {@link Version#LUCENE_6_5_0} (flushed segments are sorted in Lucene 7.0). */ private void validateIndexSort() throws CorruptIndexException { Sort indexSort = config.getIndexSort(); if (indexSort != null) { for(SegmentCommitInfo info : segmentInfos) { Sort segmentIndexSort = info.info.getIndexSort(); if (segmentIndexSort != null && indexSort.equals(segmentIndexSort) == false) { throw new IllegalArgumentException("cannot change previous indexSort=" + segmentIndexSort + " (from segment=" + info + ") to new indexSort=" + indexSort); } else if (segmentIndexSort == null && info.info.getVersion().onOrAfter(Version.LUCENE_6_5_0)) { // Flushed segments are not sorted if they were built with a version prior to 6.5.0 throw new CorruptIndexException("segment not sorted with indexSort=" + segmentIndexSort, info.info.toString()); } } } }
private void validateMergeReader(CodecReader leaf) { LeafMetaData segmentMeta = leaf.getMetaData(); if (segmentInfos.getIndexCreatedVersionMajor() != segmentMeta.getCreatedVersionMajor()) { throw new IllegalArgumentException("Cannot merge a segment that has been created with major version " + segmentMeta.getCreatedVersionMajor() + " into this index which has been created by major version " + segmentInfos.getIndexCreatedVersionMajor()); } if (segmentInfos.getIndexCreatedVersionMajor() >= 7 && segmentMeta.getMinVersion() == null) { throw new IllegalStateException("Indexes created on or after Lucene 7 must record the created version major, but " + leaf + " hides it"); } Sort leafIndexSort = segmentMeta.getSort(); if (config.getIndexSort() != null && leafIndexSort != null && config.getIndexSort().equals(leafIndexSort) == false) { throw new IllegalArgumentException("cannot change index sort from " + leafIndexSort + " to " + config.getIndexSort()); } }
if (segmentSort.equals(indexSort) == false) { throw new IllegalArgumentException("index sort mismatch: merged segment has sort=" + indexSort + " but to-be-merged segment has sort=" + segmentSort);
if (withinGroupSort.equals(Sort.RELEVANCE)) {