XF 2.3 Exclude XFMG media results from search

TrevC2

Member
Is it possible to exclude all media items from search/XFES?

If we were to enable XFMG, our search results would end up polluted with millions of attachment file names. With our potential use-case for XMFG we're mirroring most image attachments for the entire forum.

Any guidance is appreciated.
 
The option to search for photos is only available if you are looking at the gallery.
If you are in the forum and do a search, the option to search the gallery does not appear.
 
The option to search for photos is only available if you are looking at the gallery.
If you are in the forum and do a search, the option to search the gallery does not appear.
I should've been more clear that we're using Xenforo Enhanced search with Elastic. The media results show up in any search field without a specific constraint like "threads" applied, so that's any of the normal search inputs. In our case it would result in millions of extra (and completely useless) search results in the index. Not really ideal.

1726520891570.webp

We're only using XFMG in a limited capacity, like a photos feed for the forum. We've stripped out most of it at the template level, but I'd love if someone could point me in the right direction for cleaning up the search results. We don't mind if media items are excluded from all search and feeds, or if some edits are required to the addon src. Whatever it takes.
 
How many times is the search term "img" going to be entered?

I've never once had a return for an image when searching.
We have a few million images with file names that could be generic or file names people have given them. Given the large volume of entries, they do start to show up in search results for terms like watch models and brands. The results then point to a mostly empty and redundant media item page.

It's particularly an issue for auto-complete, since media results take up space that could be something relevant and more important.
 
ChatGPT o1 decided to null a bunch of stuff in XFMG/Search/Data/Media.php.
Doing more testing, but that seems to have worked. 😄

PHP:
class Media extends AbstractData
{
    public function getEntityWith($forView = false)
    {
        $get = ['User', 'Category', 'Album'];
        if ($forView)
        {
            $visitor = \XF::visitor();
            $get[] = 'Category.Permissions|' . $visitor->permission_combination_id;
        }

        return $get;
    }

    public function getIndexData(Entity $entity)
    {
        // Return null to prevent media items from being indexed
        return null;
    }

    protected function getMetaData(MediaItem $entity)
    {
        // No metadata needed as media items are not indexed
        return [];
    }

    public function setupMetadataStructure(MetadataStructure $structure)
    {
        // No metadata fields needed
    }

    public function getResultDate(Entity $entity)
    {
        return $entity->media_date;
    }

    public function getSearchableContentTypes()
    {
        // Return an empty array to exclude media items from search
        return [];
    }

    public function getTemplateData(Entity $entity, array $options = [])
    {
        return [
            'mediaItem' => $entity,
            'options' => $options,
        ];
    }

    public function getSearchFormTab()
    {
        // Return null to remove the media tab from the search form
        return null;
    }

    public function getSectionContext()
    {
        return 'xfmg';
    }

    public function getSearchFormData()
    {
        return [
            'categoryTree' => $this->getSearchableCategoryTree(),
        ];
    }

    /**
     * @return Tree
     */
    protected function getSearchableCategoryTree()
    {
        /** @var Category $categoryRepo */
        $categoryRepo = \XF::repository('XFMG:Category');
        $categoryTree = $categoryRepo->createCategoryTree($categoryRepo->getViewableCategories());

        return $categoryTree;
    }

    public function applyTypeConstraintsFromInput(Query $query, Request $request, array &$urlConstraints)
    {
        // Do not apply any constraints as media items are not searchable
    }

    public function canUseInlineModeration(Entity $entity, &$error = null)
    {
        return $entity->canUseInlineModeration($error);
    }
}
 
At least ChatGPT isn't sarcastic and doesn't lecture you... He responds, that's all.
haha, but to be fair it's kind of an edge-case situation (mirroring so many attachments and not using the rest of XFMG). We just wanted a big photo-stream for members. For that specific scenario the search results are contaminated with junk, since it doesn't take that many files with specific names to start appearing in autocomplete more frequently.

It does still feel like indexing XFMG items should be an optional setting.
 
Back
Top Bottom