Extract term stats by position from a term vectors query response.
Wil return an array of doc_freq, analayzers and term by position.

@param array $termVectors The term vector query response.

@return array
557552
private function extractTermStatsByPoisition($termVectors)
    {
        $statByPosition = [];
        $analyzers      = [FieldInterface::ANALYZER_STANDARD, FieldInterface::ANALYZER_WHITESPACE];

        foreach ($termVectors['term_vectors'] as $propertyName => $fieldData) {
            $analyzer = $this->getAnalyzer($propertyName);
            if (in_array($analyzer, $analyzers)) {
                foreach ($fieldData['terms'] as $term => $termStats) {
                    foreach ($termStats['tokens'] as $token) {
                        $positionKey = $token['position'];

                        if (!isset($termStats['doc_freq'])) {
                            $termStats['doc_freq'] = 0;
                        }

                        if (!isset($statByPosition[$positionKey])) {
                            $statByPosition[$positionKey]['term']     = $term;
                            $statByPosition[$positionKey]['doc_freq'] = $termStats['doc_freq'];
                        }

                        if ($termStats['doc_freq']) {
                            $statByPosition[$positionKey]['analyzers'][] = $analyzer;
                        }

                        $statByPosition[$positionKey]['doc_freq'] = max(
                            $termStats['doc_freq'],
                            $statByPosition[$positionKey]['doc_freq']
                        );
                    }
                }
            }
        }

        return $statByPosition;
    }
568991
public function getTerms()
    {
        if (is_null($this->_terms) && isset($this->object)) {
            $this->_terms = [];
        }

        return $this->_terms;
    }
241457
@Override
    public INDArray getWordVectorMatrix(String word) {
        // TODO: add variable UNK here
        int idx = 0;
        if (hasWord(word))
            idx = vocabCache.indexOf(word);
        else if (getUNK() != null)
            idx = vocabCache.indexOf(getUNK());
        else
            return null;

        int deviceId = Nd4j.getAffinityManager().getDeviceForCurrentThread();
        INDArray array = null;

        if (cachePerDevice > 0 && cacheWrtDevice.get(deviceId).containsKey(idx))
            return cacheWrtDevice.get(Nd4j.getAffinityManager().getDeviceForCurrentThread()).get(idx);

        array = storage.get(idx);

        if (cachePerDevice > 0) {
            // TODO: add cache here
            long arrayBytes = array.length() * array.data().getElementSize();
            if ((arrayBytes * cacheWrtDevice.get(deviceId).size()) + arrayBytes < cachePerDevice)
                cacheWrtDevice.get(deviceId).put(idx, array);
        }

        return array;
    }
846183
public function getSentMessages($filters=array())
	{
		$entries = $this->buildQuery($filters);
		$entries->order($entries->getTableName() . '.created', 'desc');

		if (isset($filters['limit']) && $filters['limit'] != 0)
		{
			$entries->limit($filters['limit'])
				->start($filters['start']);
		}

		return $entries->rows();
	}
536207
public function getTermIds($taxonomies)
    {
        $tags = [];
        foreach ($taxonomies as $voc => $terms) {
            $vocabulary_id = $this->vocabulary($voc);
            $exploded = is_array($terms) ? $terms : explode(',', $terms);

            foreach ($exploded as $term) {
                $result = $this->getTermId($term, $vocabulary_id);
                if ($result) {
                    $tags[] = $result;
                }
            }
        }

        return $tags;
    }
52989
public function parse(&$segments)
    {
        $vars = array();

        if (preg_match('/@\w+/', current($segments))) {
            $vars['oid'] = str_replace('@', '', array_shift($segments));
        }

        if (!empty($segments)) {
            $vars['term'] = array_pop($segments);
        }

        return $vars;
    }
1179468
protected static function fetch_concepts(array $glossaries) {
        global $DB;

        $glossarylist = implode(',', $glossaries);

        $sql = "SELECT id, glossaryid, concept, casesensitive, 0 AS category, fullmatch
                  FROM {glossary_entries}
                 WHERE glossaryid IN ($glossarylist) AND usedynalink = 1 AND approved = 1

                 UNION

                SELECT id, glossaryid, name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch
                  FROM {glossary_categories}
                 WHERE glossaryid IN ($glossarylist) AND usedynalink = 1

                UNION

                SELECT ge.id, ge.glossaryid, ga.alias AS concept, ge.casesensitive, 0 AS category, ge.fullmatch
                  FROM {glossary_alias} ga
                  JOIN {glossary_entries} ge ON (ga.entryid = ge.id)
                 WHERE ge.glossaryid IN ($glossarylist) AND ge.usedynalink = 1 AND ge.approved = 1";

        $concepts = array();
        $rs = $DB->get_recordset_sql($sql);
        foreach ($rs as $concept) {
            $currentconcept = trim(strip_tags($concept->concept));

            // Concept must be HTML-escaped, so do the same as format_string to turn ampersands into &amp;.
            $currentconcept = replace_ampersands_not_followed_by_entity($currentconcept);

            if (empty($currentconcept)) {
                continue;
            }

            // Rule out any small integers, see MDL-1446.
            if (is_number($currentconcept) and $currentconcept < 1000) {
                continue;
            }

            $concept->concept = $currentconcept;

            $concepts[$concept->glossaryid][] = $concept;
        }
        $rs->close();

        return $concepts;
    }
349471
public function extractUrlAliasListFromData(array $rows)
    {
        $urlAliases = array();
        foreach ($rows as $row) {
            $urlAliases[] = $this->extractUrlAliasFromData($row);
        }

        return $urlAliases;
    }
1184846
private function getTermVectors(RequestInterface $request)
    {
        $termVectorsQuery = [
            'index'           => $request->getIndex(),
            'type'            => $request->getType(),
            'term_statistics' => true,
            'fields'          => [
                MappingInterface::DEFAULT_SPELLING_FIELD,
                MappingInterface::DEFAULT_SPELLING_FIELD . "." . FieldInterface::ANALYZER_WHITESPACE,
            ],
        ];

        $termVectorsQuery['body']['doc'] = [MappingInterface::DEFAULT_SPELLING_FIELD => $request->getQueryText()];

        return $this->client->termvectors($termVectorsQuery);
    }
1093240
public function getFacets() {
		if ($this->returnedFacets) {
			return $this->returnedFacets;
		}
		
		$result = $this->getResult();
		if (!isset($result->facet_counts)) {
			return;
		}

		if (isset($result->facet_counts->exception)) {
			// $this->logger->error($result->facet_counts->exception)
			return array();
		}
		
		$elems = $result->facet_counts->facet_fields;
		
		$facets = array();
		foreach ($elems as $field => $values) {
			$elemVals = array();
			foreach ($values as $vname => $vcount) {
				if ($vname == '_empty_') {
					continue;
				}
				$r = new stdClass;
				$r->Name = $vname;
				$r->Query = $vname;
				$r->Count = $vcount;
				$elemVals[] = $r;
			}
			$facets[$field] = $elemVals;
		}
		
		// see if there's any query facets for things too
		$query_elems = $result->facet_counts->facet_queries;
		if ($query_elems) {
			foreach ($query_elems as $vname => $count) {
				if ($vname == '_empty_') {
					continue;
				}
				
				list($field, $query) = explode(':', $vname);

				$r = new stdClass;
				$r->Type = 'query';
				$r->Name = $vname;
				$r->Query = $query;
				$r->Count = $count;
				
				$existing = isset($facets[$field]) ? $facets[$field] : array();
				$existing[] = $r;
				$facets[$field] = $existing;
			}
		}
		
		$this->returnedFacets = $facets;
		return $this->returnedFacets;
	}
644621
protected function getFrequentSearchTermsFromStatistics(array $frequentSearchConfiguration) : array
    {
        $terms = [];

        if ($frequentSearchConfiguration['select.']['checkRootPageId']) {
            $checkRootPidWhere = 'root_pid = ' . $this->tsfe->tmpl->rootLine[0]['uid'];
        } else {
            $checkRootPidWhere = '1';
        }
        if ($frequentSearchConfiguration['select.']['checkLanguage']) {
            $checkLanguageWhere = ' AND language =' . $this->tsfe->sys_language_uid;
        } else {
            $checkLanguageWhere = '';
        }

        $frequentSearchConfiguration['select.']['ADD_WHERE'] = $checkRootPidWhere .
            $checkLanguageWhere . ' ' .
            $frequentSearchConfiguration['select.']['ADD_WHERE'];

        $frequentSearchTerms = $this->statisticsRepository->getFrequentSearchTermsFromStatisticsByFrequentSearchConfiguration($frequentSearchConfiguration);

        if (!is_array($frequentSearchTerms)) {
            return $terms;
        }

        foreach ($frequentSearchTerms as $term) {
            $cleanedTerm = html_entity_decode($term['search_term'], ENT_QUOTES, 'UTF-8');
            $terms[$cleanedTerm] = $term['hits'];
        }

        return $terms;
    }
1188382
public function sortSearchResults($results, $term)
    {
        $sortedResults = [];

        if (!empty($results)) {
            foreach ($results as $result) {
                if (stripos($result->getTitle(), $term) !== false) {
                    array_unshift($sortedResults, $result);
                } else {
                    $sortedResults[] = $result;
                }
            }
        }

        return $sortedResults;
    }
273104
public function extractLanguageCodesFromData(array $rows): array
    {
        $languageMask = 0;
        foreach ($rows as $row) {
            $languageMask |= $row['lang_mask'];
        }

        return $this->languageMaskGenerator->extractLanguageCodesFromMask($languageMask);
    }
47871
public function docFreq(Zend_Search_Lucene_Index_Term $term)
    {
        $result = 0;
        foreach ($this->_segmentInfos as $segInfo) {
            $termInfo = $segInfo->getTermInfo($term);
            if ($termInfo !== null) {
                $result += $termInfo->docFreq;
            }
        }

        return $result;
    }
985283
public function getRecords($filters = array())
	{
		$entries = self::all();

		$c = $entries->getTableName();
		$e = '#__extensions';

		$entries
			->select($c . '.*,' . $e . '.name')
			->join($e, $e . '.element', $c . '.component', 'inner')
			->whereEquals($e . '.type', 'component');

		if (isset($filters['component']) && $filters['component'])
		{
			$entries->whereEquals($e . '.element', $filters['component']);
		}

		return $entries
			->ordered($c . '.component', 'asc')
			->rows();
	}
833094
public function extract($rules)
    {
        $data = [];

        foreach ($this->_nodes as $node) {
            $selector = new Selector($this->_document, $node);
            $data[] = $selector->extract($rules);
        }

        return $data;
    }
1251707
public function getRes($pageColumns = null){
      $page = array();
      $pageColumns = empty($pageColumns) && (!is_array($pageColumns)) ? $this->pageColumnsRes : $pageColumns;
      if (empty($pageColumns)) {
          $page = $this->pageArray;
      }else{
          $page = array();
          foreach ($pageColumns as $index => $key) {
              $page[$key] = $this->pageArray[$key];
          }
      }
      $lists = empty($this->lists)?array():$this->lists;
      return array(
          'lists'=>$lists,
          'page'=>$page
      );
  }