/** * Returns the number of documents in an index that a phrase occurs in. * If it occurs in more than threshold documents then cut off search. * * @param string $phrase to look up in index * @param int $threshold once count in posting list for any word * reaches to threshold then return the number * @param string $index_name selected index for search engine * @param string $lang locale tag for the query * @return int number of documents phrase occurs in */ static function numDocsIndex($phrase, $threshold, $index_name, $lang) { PhraseParser::canonicalizePunctuatedTerms($phrase, $lang); $terms = PhraseParser::stemCharGramSegment($phrase, $lang); $num = count($terms); if ($index_name == NULL) { return 0; } if (count($terms) > MAX_QUERY_TERMS) { $terms = array_slice($terms, 0, MAX_QUERY_TERMS); } $whole_phrase = implode(" ", $terms); return IndexManager::numDocsTerm($whole_phrase, $index_name, $threshold); }