Skip to content

Pro search file searches with new file format #4385

@robinsowell

Description

@robinsowell

Currently, pro search indexes file data by simply using the content of the field's table- i.e.,

Screenshot 2024-07-08 at 1 38 59 PM

This isn't useful- we need the filename in there. We could put more- like captions or some such. But at least the filename.

I have a solution that works, but I'm not at all sure it's the correct solution, so making this an issue rather than a pr.

In ft.file.php if you add this method:

	// prep data for pro search- give it the filename
	function third_party_search_index($data) {

		//ee()->file_field->parse_field($field_data);
		
		if (is_string($data) && preg_match('/^{file\:(\d+)\:url}/', $data, $matches)) {
        // If the file field is in the "{file:XX:url}" format
        // Set upload directory ID and file name
        $file_id = $matches[1];
        $file = ee()->file_field->get_file($file_id);
		
		
		return (string) $file['file_name'];
		
    } elseif (is_string($data) && preg_match('/^{filedir_(\d+)}/', (string) $data, $matches)) {
        // If the file field is in the "{filedir_n}image.jpg" format
        $dir_id = $matches[1];
        $file_name = str_replace($matches[0], '', $data);
		return $file_name;

	}
		return '';

	}

Then when you index, you get the filename in the index. It sanitizes it, stripping out dashes and periods, but... that may well be fine. I'm just not 100% sure this is the best way to go. But it does work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: AcceptedBug has been confirmed, is reproducible, and ready to work on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions