Excluding search terms for dependencySearch fuse searches (would be willing to work on a PR) #81
manuelsteiner
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I would like to ask if you're open to a pull request that makes it possible to exclude search terms from the
dependencySearch
fuse searches? I'll explain my use case below. I would be willing to work on a PR if you're interested.Problem
I have quite a few models that implement a custom search trait. This trait filters the database data by adding query constraints. When implementing a command dependency of type
search
I use the search query to to pre-filter the data that is provided to the spotlight component. These search keywords can contain special keywords to filter specific things. Think of e.g.is:finished
to filter a model based on some finished state oruser:(.*)
where the second part is denoting a regular expression. In this case the keyword would specify a username of a related user model to filter by which specific user is attached through a relationship. An instantiation of that search term could beu:user
oru:[email protected]
. Just to give an idea of how the regexp part works.The filtered data gets pushed to the spotlight component as expected, however I run into a similar problem as described in issue #67. When the search query contains any of these special filters, none of the database results will pass the fuse filter since neither
name
nordescription
contain such special terms.This means i can not use special search keywords in the spotlight search dependencies. Thus I would propose the following.
Proposed Pull Request
I would propose to extend the command dependency and javascript components in the following way.
SpotlightCommandDependency
class with a propertyprotected array $exludedSearchTerms
or similar. Provide a setter for this property to be able to set excluded search terms. Maybe check in the setter if the dependency type issearch
and only set the terms when this is the case?filteredItems()
method inspotlight.js
to check if the json representation of the dependency includes the excluded search terms property and filter these terms from the user input before letting fuse filter the final results. That would also require matching search terms split by white space to the excluded terms based on included regular expressions.This would allow special search terms, such as
is:finished
oruser:(.*)
to be handled by the database query and then be excluded from how fuse filters the database results for showing them in spotlight.I'm also open for any better implementation suggestions? Thanks for hearing me out.
Beta Was this translation helpful? Give feedback.
All reactions