It may be impossible to find the filename for some content just from the file data, but a lot of files on ipfs come contained in directories (e.g. if added recursively, or with
ipfs add -w), containing a named link to the file.
QmDIR... - Directory, containing:
After indexing the QmDIR... directory (for example, finding it in the DHT), the search engine will see the filenames that the hashes QmAAA..., QmBBB... and QmCCC... were given, saving them in some index.
Now, when the file QmBBB... comes up in a search, the system can look at the filename index, and see that the file was named
I'm not sure if this is how ipfs-search works, but it's one of the possible ways to implement a way to bind filenames to indexed hashes. Another is to search for the hash of the file you want the filename for. The directory, having a reference to that file, will come up in the search.