Apply Highlight to FluentDOM selection

@param FluentDOM\Query $fd

@return FluentDOM\Query
975221
public function highlight(FluentDOM\Query $fd): \FluentDOM\Query {
    $fd
      ->find('descendant-or-self::text()')
      ->each([$this, 'replace']);
    return $fd->spawn();
  }
795417
protected function _selectQueryTranslator($query)
    {
        $limit = $query->clause('limit');
        $offset = $query->clause('offset');

        if ($limit && $offset === null) {
            $query->modifier(['_auto_top_' => sprintf('TOP %d', $limit)]);
        }

        if ($offset !== null && !$query->clause('order')) {
            $query->order($query->newExpr()->add('(SELECT NULL)'));
        }

        if ($this->_version() < 11 && $offset !== null) {
            return $this->_pagingSubquery($query, $limit, $offset);
        }

        return $this->_transformDistinct($query);
    }
1343682
public function render(\DOMDocument $domDocument)
    {
        $domElement = $domDocument->createElement("mood");
        if ($this->lightAmbientColor) {
            $domElement->setAttribute("LAmbient_LinearRgb", $this->lightAmbientColor);
        }
        if ($this->cloudsMinimumColor) {
            $domElement->setAttribute("CloudsRgbMinLinear", $this->cloudsMinimumColor);
        }
        if ($this->cloudsMaximumColor) {
            $domElement->setAttribute("CloudsRgbMaxLinear", $this->cloudsMaximumColor);
        }
        if ($this->light0Color) {
            $domElement->setAttribute("LDir0_LinearRgb", $this->light0Color);
        }
        if ($this->light0Intensity != 1.) {
            $domElement->setAttribute("LDir0_Intens", $this->light0Intensity);
        }
        if ($this->light0PhiAngle) {
            $domElement->setAttribute("LDir0_DirPhi", $this->light0PhiAngle);
        }
        if ($this->light0ThetaAngle) {
            $domElement->setAttribute("LDir0_DirTheta", $this->light0ThetaAngle);
        }
        if ($this->lightBallColor) {
            $domElement->setAttribute("LBall_LinearRgb", $this->lightBallColor);
        }
        if ($this->lightBallIntensity != 1.) {
            $domElement->setAttribute("LBall_Intens", $this->lightBallIntensity);
        }
        if ($this->lightBallRadius) {
            $domElement->setAttribute("LBall_Radius", $this->lightBallRadius);
        }
        if ($this->fogColor) {
            $domElement->setAttribute("FogColorSrgb", $this->fogColor);
        }
        if ($this->selfIlluminationColor) {
            $domElement->setAttribute("SelfIllumColor", $this->selfIlluminationColor);
        }
        if ($this->skyGradientScale != 1.) {
            $domElement->setAttribute("SkyGradientV_Scale", $this->skyGradientScale);
        }
        if ($this->skyGradientKeys) {
            $skyGradientElement = $domDocument->createElement("skygradient");
            $domElement->appendChild($skyGradientElement);
            foreach ($this->skyGradientKeys as $skyGradientKey) {
                $skyGradientKeyElement = $skyGradientKey->render($domDocument);
                $skyGradientElement->appendChild($skyGradientKeyElement);
            }
        }
        return $domElement;
    }
1352535
public function getQuery()
    {
        $idField = $this->documentKey;

        if ($idField == null) {
            throw new QueryException('id should not be null');
        }

        $documentLimitation = $this->createFilterQuery('id')->setQuery(sprintf('id:%s', $idField));
        $this->addFilterQuery($documentLimitation);

        $this->setQuery('*:*');

        return parent::getQuery();
    }
786764
public static function getByID($fsID)
    {
        $db = Database::connection();
        $row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsID = ?', array($fsID));
        if (is_array($row)) {
            $fs = new static();
            $fs = array_to_object($fs, $row);
            if ($row['fsType'] == static::TYPE_SAVED_SEARCH) {
                $row2 = $db->GetRow(
                    'SELECT fsSearchRequest, fsResultColumns FROM FileSetSavedSearches WHERE fsID = ?',
                    array($fsID));
                $fs->fsSearchRequest = @unserialize($row2['fsSearchRequest']);
                $fs->fsResultColumns = @unserialize($row2['fsResultColumns']);
            }

            return $fs;
        }
    }
1009205
def highlight(key, query, options = {})
      logger.debug("highlight: #{key} query: #{query}")
      options.reverse_merge! :num_excerpts => 2, :pre_tag => '<em>', :post_tag => '</em>'
      highlights = []
      ferret_index.synchronize do
        doc_num = document_number(key)

        if options[:field]
          highlights << ferret_index.highlight(query, doc_num, options)
        else
          query = process_query(query) # process only once
          index_definition[:ferret_fields].each_pair do |field, config|
            next if config[:store] == :no || config[:highlight] == :no
            options[:field] = field
            highlights << ferret_index.highlight(query, doc_num, options)
          end
        end
      end
      return highlights.compact.flatten[0..options[:num_excerpts]-1]
    end
493945
public function close(int $fd = null)
    {
        return App::make(Server::class)->close($fd ?: $this->sender);
    }
547144
public function join(int $fd, $room): self
    {
        $this->room->add($fd, $this->filterGetRooms($room));

        return $this;
    }
260952
public static function render(SQL\Aliased $aliased)
    {
        $content = $aliased->getContent();

        if ($content instanceof Query\Select) {
            $content = "(".Select::render($content).")";
        } else {
            $content = Compiler::name($content);
        }

        return Compiler::expression(array(
            $content,
            Compiler::word('AS', Compiler::name($aliased->getAlias()))
        ));
    }
539434
public function compileCompletion(Fluent $fluent)
    {
        $map = [
            'type'                => 'completion',
            'analyzer'            => $fluent->analyzer,
            'search_analyzer'     => $fluent->search_analyzer,
            'payloads'            => $fluent->payloads,
            'preserve_separators' => $fluent->preserve_separators,
            'max_input_length'    => $fluent->max_input_length,
        ];

        return $this->formatMap($map);
    }
534475
public function highlight($fields = ['_all' => []], $parameters = [], $preTag = '<mark>', $postTag = '</mark>')
    {
        $highlight = new Highlight();
        $highlight->setTags([$preTag], [$postTag]);

        foreach ($fields as $field => $fieldParams) {
            $highlight->addField($field, $fieldParams);
        }

        if ($parameters) {
            $highlight->setParameters($parameters);
        }

        $this->query->addHighlight($highlight);

        return $this;
    }
776645
public function getPageThemeById($id, $mode = AbstractQuery::HYDRATE_OBJECT)
    {
        $qb = $this->getEntityManager()->createQueryBuilder();
        /** @var $query \Doctrine\ORM\Query */

        $query = $qb->select('e, m')
            ->from($this->getEntity(), 'e')
            ->innerJoin('e.pageId', 'm')
            ->where('e.id = :id')
            ->setMaxResults(1)
            ->setParameter('id', $id)
            ->getQuery();

        return $query->getOneOrNullResult($mode);
    }
1207164
public function render(\DOMDocument $domDocument)
    {
        $style3dXml = $domDocument->createElement("style3d");
        $this->checkId();
        if ($this->styleId) {
            $style3dXml->setAttribute("id", $this->styleId);
        }
        if ($this->model) {
            $style3dXml->setAttribute("model", $this->model);
        }
        if ($this->thickness) {
            $style3dXml->setAttribute("thickness", $this->thickness);
        }
        if ($this->color) {
            $style3dXml->setAttribute("color", $this->color);
        }
        if ($this->focusColor) {
            $style3dXml->setAttribute("fcolor", $this->focusColor);
        }
        if ($this->lightColor) {
            $style3dXml->setAttribute("lightcolor", $this->lightColor);
        }
        if ($this->focusLightColor) {
            $style3dXml->setAttribute("flightcolor", $this->focusLightColor);
        }
        if ($this->yOffset) {
            $style3dXml->setAttribute("yoffset", $this->yOffset);
        }
        if ($this->focusYOffset) {
            $style3dXml->setAttribute("fyoffset", $this->focusYOffset);
        }
        if ($this->zOffset) {
            $style3dXml->setAttribute("zoffset", $this->zOffset);
        }
        if ($this->focusZOffset) {
            $style3dXml->setAttribute("fzoffset", $this->focusZOffset);
        }
        return $style3dXml;
    }
1332893
public function highlight($type = 'bg', $isHighlight = true)
    {
        if ($type === 'bg') {
            $this->hasHighlightedBackground = $isHighlight;
        } else {
            $this->hasHighlightedForeground = $isHighlight;
        }

        return $this;
    }
862644
public function getSelectQueryBuilder($srid = null)
    {
        $driver             = $this->driver;
        $geomFieldCondition = $driver->getGeomAttributeAsWkt($this->geomField, $srid ? $srid : $this->getSrid());
        $queryBuilder       = $driver->getSelectQueryBuilder(array($geomFieldCondition));
        return $queryBuilder;
    }
1099678
protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
    {
        $words = array();

        include_once 'Zend/Search/Lucene/Index/Term.php';
        $prefix           = Zend_Search_Lucene_Index_Term::getPrefix($this->_term->text, $this->_prefixLength);
        $prefixByteLength = strlen($prefix);
        $prefixUtf8Length = Zend_Search_Lucene_Index_Term::getLength($prefix);

        $termLength       = Zend_Search_Lucene_Index_Term::getLength($this->_term->text);

        $termRest         = substr($this->_term->text, $prefixByteLength);
        // we calculate length of the rest in bytes since levenshtein() is not UTF-8 compatible
        $termRestLength   = strlen($termRest);

        $scaleFactor = 1/(1 - $this->_minimumSimilarity);

        $docBody = $highlighter->getDocument()->getFieldUtf8Value('body');
        include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
        $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8');
        foreach ($tokens as $token) {
            $termText = $token->getTermText();

            if (substr($termText, 0, $prefixByteLength) == $prefix) {
                // Calculate similarity
                $target = substr($termText, $prefixByteLength);

                $maxDistance = isset($this->_maxDistances[strlen($target)])?
                                   $this->_maxDistances[strlen($target)] :
                                   $this->_calculateMaxDistance($prefixUtf8Length, $termRestLength, strlen($target));

                if ($termRestLength == 0) {
                    // we don't have anything to compare.  That means if we just add
                    // the letters for current term we get the new word
                    $similarity = (($prefixUtf8Length == 0)? 0 : 1 - strlen($target)/$prefixUtf8Length);
                } else if (strlen($target) == 0) {
                    $similarity = (($prefixUtf8Length == 0)? 0 : 1 - $termRestLength/$prefixUtf8Length);
                } else if ($maxDistance < abs($termRestLength - strlen($target))) {
                    //just adding the characters of term to target or vice-versa results in too many edits
                    //for example "pre" length is 3 and "prefixes" length is 8.  We can see that
                    //given this optimal circumstance, the edit distance cannot be less than 5.
                    //which is 8-3 or more precisesly abs(3-8).
                    //if our maximum edit distance is 4, then we can discard this word
                    //without looking at it.
                    $similarity = 0;
                } else {
                    $similarity = 1 - levenshtein($termRest, $target)/($prefixUtf8Length + min($termRestLength, strlen($target)));
                }

                if ($similarity > $this->_minimumSimilarity) {
                    $words[] = $termText;
                }
            }
        }

        $highlighter->highlight($words);
    }
1233042
public function Highlight($class = 'highlight')
    {
        $owner = $this->owner;
        $new = DBHTMLText::create();
        $new->name = $owner->name;
        $owner->value = $owner->forTemplate();
        $new->value = preg_replace('/\[([^\]]*)\]/', '<span class="' . $class . '">$1</span>', $owner->value);
        return $new;
    }