/** * Is there more then one namespace in the provided index type? * @var string $indexType an index type * @return false|integer false if the number of indexes is unknown, an integer if it is known */ public function namespacesInIndexType($indexType) { if ($indexType === self::GENERAL_INDEX_TYPE) { return false; } $mappings = $this->config->get('CirrusSearchNamespaceMappings'); $count = count(array_keys($mappings, $indexType)); if ($indexType === self::CONTENT_INDEX_TYPE) { // The content namespace includes everything set in the mappings to content (count right now) // Plus everything in wgContentNamespaces that isn't already in namespace mappings $contentNamespaces = $this->config->get('ContentNamespaces'); $count += count(array_diff($contentNamespaces, array_keys($mappings))); } return $count; }
/** * @return boolean true if CommonTermsQuery is allowed */ public function isUseCommonTermsQuery() { return $this->config->get('CirrusSearchUseCommonTermsQuery'); }
/** * Get the weight of a namespace. * @param int $namespace the namespace * @return float the weight of the namespace */ private function getBoostForNamespace($namespace) { if ($this->normalizedNamespaceWeights === null) { $this->normalizedNamespaceWeights = array(); foreach ($this->config->get('CirrusSearchNamespaceWeights') as $ns => $weight) { if (is_string($ns)) { $ns = $this->language->getNsIndex($ns); // Ignore namespaces that don't exist. if ($ns === false) { continue; } } // Now $ns should always be an integer. $this->normalizedNamespaceWeights[$ns] = $weight; } } if (isset($this->normalizedNamespaceWeights[$namespace])) { return $this->normalizedNamespaceWeights[$namespace]; } if (MWNamespace::isSubject($namespace)) { if ($namespace === NS_MAIN) { return 1; } return $this->config->get('CirrusSearchDefaultNamespaceWeight'); } $subjectNs = MWNamespace::getSubject($namespace); if (isset($this->normalizedNamespaceWeights[$subjectNs])) { return $this->config->get('CirrusSearchTalkNamespaceWeight') * $this->normalizedNamespaceWeights[$subjectNs]; } if ($namespace === NS_TALK) { return $this->config->get('CirrusSearchTalkNamespaceWeight'); } return $this->config->get('CirrusSearchDefaultNamespaceWeight') * $this->config->get('CirrusSearchTalkNamespaceWeight'); }
/** * prepare the list of suggest requests used for geo context suggestions * This method will merge $this->config->get( 'CirrusSearchCompletionSettings and * $this->config->get( 'CirrusSearchCompletionGeoContextSettings * @param array $context user's geo context * @return array of suggest request profiles */ private function prepareGeoContextSuggestProfiles() { $profiles = array(); foreach ($this->config->get('CirrusSearchCompletionGeoContextSettings') as $geoname => $geoprof) { foreach ($this->config->get('CirrusSearchCompletionSettings') as $sugname => $sugprof) { if (!in_array($sugname, $geoprof['with'])) { continue; } $profile = $sugprof; $profile['field'] .= $geoprof['field_suffix']; $profile['discount'] *= $geoprof['discount']; $profile['context'] = array('location' => array('lat' => $this->context['geo']['lat'], 'lon' => $this->context['geo']['lon'], 'precision' => $geoprof['precision'])); $profiles["{$sugname}-{$geoname}"] = $profile; } } return $profiles; }