/** * @param InvertedIndex $invertedIndex * @return arrray */ public function queryIndex(InvertedIndex $invertedIndex) { $r = $invertedIndex->getDocumentIdsByTerm($this->getQuery()[0]); if (!empty($r)) { return [$this->getQuery()[0] => $r]; } // do partial matches $terms = array_keys($invertedIndex->getIndex()); $found = []; foreach ($terms as $term) { if (Text::contains($term, $this->getQueryString())) { $found[$term] = $invertedIndex->getDocumentIdsByTerm($term); } } return $found; }
/** * * @param InvertedIndex $invertedIndex * @return array */ public function queryIndex(InvertedIndex $invertedIndex) { $terms = array_keys($invertedIndex->getIndex()); $found = []; foreach ($terms as $term) { foreach ($this->getQuery() as $queryTerm) { if (Text::contains($term, $queryTerm)) { $found[$term] = $invertedIndex->getDocumentIdsByTerm($term); } } } return $found; }