protected function buildResultIndex($result)
    {
        $corpus = [];

        foreach ($this->getContentFields() as $field => $weightings) {
            $textualContent = $result->{$field};

            // This is to handle taxonomies that need to be converted from an array
            // into a string of words.
            if (is_array($textualContent)) {
                $textualContent = implode(' ', $textualContent);
            }

            $textualContent = strip_tags($textualContent);
            $textualContent = preg_replace('/[^\w\s]/', '', $textualContent);
            $textualContent = mb_strtolower($textualContent);
            $corpus[$field] = $textualContent;
        }

        $dictionary = [];
        $count = [];

        foreach ($corpus as $id => $doc) {
            $terms = explode(' ', $doc);
            $count[$id] = count($terms);

            foreach ($terms as $term) {
                if (!isset($dictionary[$term])) {
                    $dictionary[$term] = ['frequency' => 0, 'postings' => []];
                }
                if (!isset($dictionary[$term]['postings'][$id])) {
                    ++$dictionary[$term]['frequency'];
                    $dictionary[$term]['postings'][$id] = ['frequency' => 0];
                }

                ++$dictionary[$term]['postings'][$id]['frequency'];
            }
        }

        return ['count' => $count, 'dictionary' => $dictionary];
    }