fix(search): parse the instance_name from query
Actually I'm not sure if it's a bug or intended behaviour, but anyway, following #3498, I tried to add some logic on search queries.
Currently, the search will take the "@" character literally, and since in the database the object only have their "local" names, you won't find anything.
The idea of this fix is that if you put a "@" in the search bar, you are searching for a remote object, so the api should probably take that into account.
To do so, I use a regexp on the search term, and anything after the "@" is considered the domain_name and a filter is added to the request accordingly. If there is no such character, that filter is not applied.
Let me know if you think this is the correct way to tackle is issue.
Fixes #3498
[EDIT] : @L3v3L mentionned to me that by tweaking the PR slightly, we could also resolve https://github.com/LemmyNet/lemmy/issues/3207 so I allowed to have no search_term in the regexp while still having a domain_name.
I also added the same logic for user searches, I'm not sure if that makes sense for other objects such as posts or comments
Search for actor id like [email protected] is handled in src/apub/src/api/resolve_object.rs. So you are editing the wrong file. And like I commented in the issue, the problem is that leading ! or @ is required for this to work, because we need to know if its a user or community.
Ok so from what I understand, to resolve an actorID like : [email protected], you would need to call the /resolve_object endpoint ?
When I do the search here : https://lemmy.ml/search?q=!ukraine%40sopuli.xyz&type=Communities&listingType=All&page=1&sort=TopAll it's the search endpoint that's called, so it's more of a lemmy-ui bug that should call this endpoint rather than search ?
So yeah maybe my PR isn't the best to solve the linked issues, especially https://github.com/LemmyNet/lemmy/issues/3498. However maybe there is some value to handling '@' in the search endpoint ?
The lemmy-ui search calls both search and resolve_object api endpoints and combines the results.
Its true that there is a problem with resolve_object not working without login. This is because it needs to make a network call and possibly fetch the object from another instance, so it can have high resource usage. And supporting queries without leading ! or @ might also be a good idea, but it will be confusing if that fails to fetch objects from the remote server. With this change it is also likely that search and resolve_object will return the same items, then lemmy-ui search page needs to deduplicate them.
In short, its complicated and Im not sure whats a good solution.
Okay thanks for that explanation I'll close that PR and continue the discussion on the original issue (https://github.com/LemmyNet/lemmy/issues/3498)