You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Christine Poerschke (JIRA)" <ji...@apache.org> on 2016/06/16 11:00:11 UTC

[jira] [Commented] (LUCENE-7341) EarlyTerminatingSortingCollector support for grouped searches

    [ https://issues.apache.org/jira/browse/LUCENE-7341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333568#comment-15333568 ] 

Christine Poerschke commented on LUCENE-7341:
---------------------------------------------

*proposed EarlyTerminatingSortingCollector constructor change:*
{code}
+ final private boolean aaa; // as yet unnamed flag
+ @Deprecated
  public EarlyTerminatingSortingCollector(Collector in, Sort sort, int numDocsToCollect) {
-   ...
+   this(in, sort, numDocsToCollect, false);
+ }
+ public EarlyTerminatingSortingCollector(Collector in, Sort sort, int numDocsToCollect, boolean aaa) {
+   ...
    this.aaa = aaa;
  }
{code}

*proposed EarlyTerminatingSortingCollector method change:*
{code}
  public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
    ...
    if (...) {
      // segment is sorted, can early-terminate
      return new FilterLeafCollector(super.getLeafCollector(context)) {
        private int numCollected;
        @Override
        public void collect(int doc) throws IOException {
          super.collect(doc);
-         if (++numCollected >= numDocsToCollect) {
+         if (aaa) {
+           final Boolean zzz = gotAndKeptAtLeast(numDocsToCollect);
+           if (Boolean.TRUE.equals(zzz) {
+             terminatedEarly.set(true);
+             throw new CollectionTerminatedException();+
+           }
+         } else if (++numCollected >= numDocsToCollect) {
            terminatedEarly.set(true);
            throw new CollectionTerminatedException();
          }
        }
      };
    } else {
      return super.getLeafCollector(context);
    }
  }
{code}

*proposed LeafCollector interface extension:*
{code}
public interface LeafCollector {
  ...
   // Return null to indicate "don't know".
  Boolean gotAndKeptAtLeast(int numDocs);
  ...
}
{code}

*outline AbstractFirstPassGroupingCollector change:*
{code}
public abstract class AbstractFirstPassGroupingCollector ... {
  ...
  Boolean gotAndKeptAtLeast(int numDocs) {
    return (groupMap == null ? null : (groupMap.size() >= numDocs)); 
  }
  ...
}
{code}

*outline AbstractSecondPassGroupingCollector change:*
{code}
public abstract class AbstractSecondPassGroupingCollector ... {
  ...
  Boolean gotAndKeptAtLeast(int numDocs) {
    Boolean gak = null;
    for (SearchGroupDocs<GROUP_VALUE_TYPE> groupDocs : groupMap.values()) {
      gak = groupDocs.leafCollector.gotAndKeptAtLeast(maxDocsPerGroup);
      if (!Boolean.TRUE.equals(gak)) {
        return gak;
      }
    }
    return gak;
  }
  ...
}
{code}

_I think something like this should work, what do you think?_

> EarlyTerminatingSortingCollector support for grouped searches
> -------------------------------------------------------------
>
>                 Key: LUCENE-7341
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7341
>             Project: Lucene - Core
>          Issue Type: New Feature
>            Reporter: Christine Poerschke
>            Assignee: Christine Poerschke
>            Priority: Minor
>
> Currently grouped searches must not use the early terminating sorting collector because the wrong results would be returned. This ticket proposes to change the {{EarlyTerminatingSortingCollector}} class and probably the {{LeafCollector}} interface to support early termination for grouped searches.
> *Illustration (aaa is an as yet unnamed boolean flag):*
> {code}
> # fictitious (sorted by X) segment
> | doc key | D0 D1 D2 D3 D4 D5 ... D10 D11 D12 D13 D14 D15 ... D20 D21 D22 D23 D24 D25 ...
> | doc grp | G0 G0 G0 G0 G0 G0 ... D10 G10 G10 G10 G10 G10 ... G20 G20 G20 G20 G20 G20 ... 
> {code}
> {code}
> # query with rows=3 sort=X group=false
> | query result | D0 D1 D2
> # existing code:
> #   use a EarlyTerminatingSortingCollector with numDocsToCollect=3
> #   EarlyTerminatingSortingCollector.getLeafCollector returns a LeafCollector
> #   whose collect method uses (++numCollected >= numDocsToCollect) as the terminating condition
> {code}
> {code}
> # query with rows=3 sort=X group=true group.field=grp group.sort=X group.limit=1
> | query result | G0(D0) G10(D10) G20(D20)
> # existing code:
> #   cannot use EarlyTerminatingSortingCollector (query result would wrongly be just 'G0(D0)')
> # proposed new code:
> #   use a EarlyTerminatingSortingCollector(... numDocsToCollect=3 aaa=true)
> {code}
> {code}
> # query with rows=3 sort=X group=true group.field=grp group.sort=X group.limit=5
> | query result | G0(D0,D1,D2,D3,D4) G10(D10,D11,D12,D13,D14) G20(D20,D21,D22,D23,D24)
> # existing code:
> #   cannot use EarlyTerminatingSortingCollector (query result would wrongly be just 'G0(D0,D1,D2)')
> # proposed new code:
> #   use a EarlyTerminatingSortingCollector(... numDocsToCollect=3 aaa=true)
> {code} 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org