Skip to content

Commit

Permalink
HSEARCH-3657 Clarify what "nested docs" are about in LuceneSearcherIm…
Browse files Browse the repository at this point in the history
…pl and projections
  • Loading branch information
yrodiere committed Dec 13, 2019
1 parent 223de23 commit c049b0f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Double getDistance(final int docId, LuceneCollectorExtractContext context
}

// try to find the field on nested docs
Set<Integer> nestedDocs = context.getNestedDocs( docId );
Set<Integer> nestedDocs = context.getNestedDocIds( docId );
if ( nestedDocs == null ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

public interface LuceneCollectorExtractContext {

Set<Integer> getNestedDocs(int docId);
Set<Integer> getNestedDocIds(int docId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class LuceneCollectors {
private final TimeoutManager timeoutManager;

private TopDocs topDocs = null;
private Map<Integer, Set<Integer>> nestedDocIds = Collections.emptyMap();
private Map<Integer, Set<Integer>> topDocIdsToNestedDocIds = Collections.emptyMap();

LuceneCollectors(boolean requireFieldDocRescoring, Integer scoreSortFieldIndexForRescoring,
Set<String> nestedDocumentPaths,
Expand Down Expand Up @@ -116,8 +116,8 @@ public TopDocs getTopDocs() {
return topDocs;
}

public Map<Integer, Set<Integer>> getNestedDocIds() {
return nestedDocIds;
public Map<Integer, Set<Integer>> getTopDocIdsToNestedDocIds() {
return topDocIdsToNestedDocIds;
}

private void extractTopDocs(int offset, Integer limit) {
Expand Down Expand Up @@ -155,9 +155,9 @@ private void collectNestedDocs(IndexSearcher indexSearcher, Query parentsQuery)
collectors.get( HibernateSearchDocumentIdToLuceneDocIdMapCollector.FACTORY );

Map<String, Set<Integer>> stringSetMap = applyCollectorsToNestedDocs( indexSearcher, parentsQuery );
this.nestedDocIds = new HashMap<>();
this.topDocIdsToNestedDocIds = new HashMap<>();
for ( Map.Entry<String, Set<Integer>> entry : stringSetMap.entrySet() ) {
nestedDocIds.put( searchDocumentIdToLuceneDocId.getLuceneDocId( entry.getKey() ), entry.getValue() );
topDocIdsToNestedDocIds.put( searchDocumentIdToLuceneDocId.getLuceneDocId( entry.getKey() ), entry.getValue() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class SearchProjectionExtractContext implements LuceneCollectorExtractCon

private final IndexSearcher indexSearcher;
private final Query luceneQuery;
private final Map<Integer, Set<Integer>> nestedDocs;
private final Map<Integer, Set<Integer>> topDocIdsToNestedDocIds;
private final Map<LuceneCollectorKey<?>, Collector> collectors;

public SearchProjectionExtractContext(IndexSearcher indexSearcher, Query luceneQuery,
Map<Integer, Set<Integer>> nestedDocs,
Map<Integer, Set<Integer>> topDocIdsToNestedDocIds,
Map<LuceneCollectorKey<?>, Collector> collectors) {
this.indexSearcher = indexSearcher;
this.luceneQuery = luceneQuery;
this.nestedDocs = nestedDocs;
this.topDocIdsToNestedDocIds = topDocIdsToNestedDocIds;
this.collectors = collectors;
}

Expand All @@ -49,8 +49,8 @@ public Explanation explain(int docId) {
}

@Override
public Set<Integer> getNestedDocs(int docId) {
return nestedDocs.get( docId );
public Set<Integer> getNestedDocIds(int docId) {
return topDocIdsToNestedDocIds.get( docId );
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TopDocs getTopDocs() {
SearchProjectionExtractContext createProjectionExtractContext() {
return new SearchProjectionExtractContext(
indexSearcher, luceneQuery,
luceneCollectors.getNestedDocIds(),
luceneCollectors.getTopDocIdsToNestedDocIds(),
luceneCollectors.getCollectors()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ private List<Object> extractHits(LuceneSearchQueryExtractContext extractContext)
}

ScoreDoc hit = topDocs.scoreDocs[i];
// add root object contribution
// add root document contribution
indexSearcher.doc( hit.doc, storedFieldVisitor );
Set<Integer> nestedDocIdsForDocument = projectionExtractContext.getNestedDocs( hit.doc );
// add nested documents contribution
Set<Integer> nestedDocIdsForDocument = projectionExtractContext.getNestedDocIds( hit.doc );
if ( nestedDocIdsForDocument != null ) {
for ( Integer child : nestedDocIdsForDocument ) {
indexSearcher.doc( child, storedFieldVisitor );
Expand Down

0 comments on commit c049b0f

Please sign in to comment.