Merge documents from other response, keeping size below $pageSize

@param $other
@param $pageSize
978979
private function mergeDocuments($other, $pageSize)
    {
        $numberResults = sizeof($this->response->docs);
        if ($numberResults < $pageSize) {

            $foundProductIds = array();
            foreach ($this->response->docs as $nonFuzzyDoc) {
                /* @var $nonFuzzyDoc \Apache_Solr_Document */
                $field = $nonFuzzyDoc->getField('product_id');
                $foundProductIds[] = $field['value'];
            }

            $numberDuplicates = 0;

            foreach ($other->response->docs as $fuzzyDoc) {
                /* @var $fuzzyDoc \Apache_Solr_Document */
                $field = $fuzzyDoc->getField('product_id');
                if (!in_array($field['value'], $foundProductIds)) {
                    if ($numberResults++ >= $pageSize) {
                        continue;
                    }
                    $this->response->docs[] = $fuzzyDoc;
                } else {
                    $numberDuplicates++;
                }
            }

            $this->response->numFound = $this->response->numFound
                + $other->response->numFound
                - $numberDuplicates;
        } else {
            $this->response->numFound = max(
                $this->response->numFound,
                $other->response->numFound
            );
        }
    }
625441
public function setPageSize($size)
    {
        $this->pageSize = ($size === null ? self::PAGE_SIZE : (int)$size);
        if ($this->pageSize < 0)
            $this->pageSize = self::PAGE_SIZE;

        return $this;
    }
1248512
public function FilteredUpdates($pageSize = 20)
    {
        $params = $this->parseParams();

        $items = $this->Updates(
            $params['tag'],
            $params['from'],
            $params['to'],
            $params['year'],
            $params['month']
        );

        // Apply pagination
        $list = PaginatedList::create($items, $this->getRequest());
        $list->setPageLength($pageSize);
        return $list;
    }
699939
public function get($sinceId, $pageSize)
    {
        $this->validateSinceId($sinceId);

        $this
            ->initCollection()
            ->removeOldEvents($sinceId)
            ->initCollection()
            ->getEvents($sinceId)
            ->setOrder()
            ->setPageSize($pageSize);

        return $this->eventsApiResponseFactory->create()
            ->setCurrentPage($this->eventCollection->getCurPage())
            ->setLastPage($this->eventCollection->getLastPageNumber())
            ->setPageSize($this->eventCollection->getPageSize())
            ->setTotalCount($this->eventCollection->getSize())
            ->setEvents($this->handleEvents());
    }
236689
public function merge(File $other): self
    {
        $new = new static($this->filename);
        $new->issues = array_merge($this->issues, $other->issues);
        return $new;
    }
1069630
public function getSinglePageResourceUri( $pagenum = null, $pagesize=null)
    {
        if( is_null($pagenum) ) $pagenum  =$this->pagenum;
        if( is_null($pagesize)) $pagesize =$this->pagesize;
        
        //rebuild query string from already parsed _GET superglobal but do not override it.
        $vars = $_GET;
        $o=$this->ns(self::LOCAL);
        $vars[$o->getValue('plabel')]   = $pagenum;
        $vars[$o->getValue('pslabel')]  = $pagesize;
        
        return $this->getQueryStrippedUri() . '?'. http_build_query($vars);
    }
434206
def merge(self, other):
        ''''''
        assert self.refnames == other.refnames
        assert self.dirs == other.dirs
        assert self.lengths == other.lengths

        for i in range(2):
            if self.pos[i] is None:
                if other.pos[i] is None:
                   raise Error('Error merging these two links:\n' + str(self) + '\n' + str(other))
                self.pos[i] = other.pos[i]
            else:
                if other.pos[i] is not None:
                   raise Error('Error merging these two links:\n' + str(self) + '\n' + str(other))
755292
private function cascadeMerge(object $document, object $managedCopy, array &$visited) : void
    {
        $class = $this->dm->getClassMetadata(get_class($document));

        $associationMappings = array_filter(
            $class->associationMappings,
            static function ($assoc) {
                return $assoc['isCascadeMerge'];
            }
        );

        foreach ($associationMappings as $assoc) {
            $relatedDocuments = $class->reflFields[$assoc['fieldName']]->getValue($document);

            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
                if ($relatedDocuments === $class->reflFields[$assoc['fieldName']]->getValue($managedCopy)) {
                    // Collections are the same, so there is nothing to do
                    continue;
                }

                foreach ($relatedDocuments as $relatedDocument) {
                    $this->doMerge($relatedDocument, $visited, $managedCopy, $assoc);
                }
            } elseif ($relatedDocuments !== null) {
                $this->doMerge($relatedDocuments, $visited, $managedCopy, $assoc);
            }
        }
    }
359275
public function merge(Assembler $other)
    {
        //N.B. reflection used so as to not expose values
        //via some public method
        $refl = new \ReflectionObject($other);
        $reflValues = $refl->getProperty('values');
        $reflValues->setAccessible(true);
        $oValues = $reflValues->getValue($other);
        if (count($oValues) == 0) {
            return $this;
        }

        $this->values = array_merge($this->values, $oValues);

        return $this;
    }
1075215
public function mergeWith(Parsed $other)
    {
        $mergeMethod = Translations::MERGE_ADD | Translations::MERGE_PLURAL;
        if ($other->sourceStrings !== null) {
            if ($this->sourceStrings === null) {
                $this->sourceStrings = $other->sourceStrings;
            } else {
                $this->sourceStrings->mergeWith($other->sourceStrings, $mergeMethod);
            }
        }
        foreach ($other->translations as $key => $data) {
            if (isset($this->translations[$key])) {
                $this->translations[$key][1]->mergeWith($data[1], $mergeMethod);
            } else {
                $this->translations[$key] = $data;
            }
        }
    }
294803
public function pagesize($pagesize = null)
    {
        if ($pagesize === null) {
            return $this->options['pagesize'];
        } else {
            $this->options['pagesize'] = intval($pagesize);
            return $this;
        }
    }
1238133
public function setPageSize($pagesize)
    {
        if($pagesize>0)
           $this->pagesize = $pagesize;
        else 
           $this->pagesize = 20;
        
        $this->currentpage = 1;
        // $this->Reload();
    }
825187
public function mergeWith(Field $other)
    {
        if (($name = $other->getName()) !== $this->name) {
            throw new MergeException(sprintf("Fields have different names (%s vs %s)", $this->name, $name));
        }

        // Since mapping is merged between databoxes, two fields may
        // have conflicting names. Indexing is the same for a given
        // type so we reject only those with different types.

        if (($type = $other->getType()) !== $this->type) {
            throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type));
        }

        if ($other->isPrivate() !== $this->is_private) {
            throw new MergeException(sprintf("Field %s can't be merged, could not mix private and public fields with same name", $name));
        }

        if ($other->isSearchable() !== $this->is_searchable) {
            throw new MergeException(sprintf("Field %s can't be merged, incompatible searchablility", $name));
        }

        if ($other->getFacetValuesLimit() !== $this->facet) {
            throw new MergeException(sprintf("Field %s can't be merged, incompatible facet eligibility", $name));
        }

        $thesaurus_roots = null;

        if ($this->thesaurus_roots !== null || $other->thesaurus_roots !== null) {
            $thesaurus_roots = array_merge(
                (array) $this->thesaurus_roots,
                (array) $other->thesaurus_roots
            );
        }

        $used_by_collections = array_values(
            array_unique(
                array_merge(
                    $this->used_by_collections,
                    $other->used_by_collections
                ),
                SORT_REGULAR
            )
        );

        return $this->withOptions([
            'thesaurus_roots' => $thesaurus_roots,
            'used_by_collections' => $used_by_collections
        ]);
    }
1234826
public static function create($totalPage, $pageSize = 10, $page = 1, $gets = [])
    {
        $p = new PageUtil();
        if ($pageSize < 1) {
            $pageSize = 1;
        }

        $total = ceil($totalPage / $pageSize);

        if ($page < 1) {
            $page = 1;
        } else if ($page > $total) {
            $page = $total;
        }

        $p->page = $page;
        $p->gets = $gets;
        $p->total = $total;
        $p->pageSize = $pageSize;
        return $p;
    }
386934
public function setPaperSize($sSize = null, $sOrientation = null)
    {
        $this->sPaperSize        = $sSize ?: static::DEFAULT_PAPER_SIZE;
        $this->sPaperOrientation = $sOrientation ?: static::DEFAULT_PAPER_ORIENTATION;
        $this->oDomPdf->setPaper($this->sPaperSize, $this->sPaperOrientation);
        return $this;
    }
176996
public function paginate($page, $pageSize)
    {
        $start = $page * $pageSize;
        return $this->limit($pageSize, $start);
    }
187380
def merge!(other)
      criteria = other.to_criteria
      selector.merge!(criteria.selector)
      options.merge!(criteria.options)
      self.documents = criteria.documents.dup unless criteria.documents.empty?
      self.scoping_options = criteria.scoping_options
      self.inclusions = (inclusions + criteria.inclusions).uniq
      self
    end