Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use as text matcher against search text? #27

Open
bradparks opened this issue Mar 8, 2019 · 4 comments
Open

Use as text matcher against search text? #27

bradparks opened this issue Mar 8, 2019 · 4 comments

Comments

@bradparks
Copy link

bradparks commented Mar 8, 2019

I'd like to use this to match text, like someone would with a search engine, e.g.

e.g If I had the text

this is a test of the system
brad and his dog

this search would match
test or you and (brad and dog)

but this one wouldnt
test and rabbit

I could use a custom function, but for this use case, the variable names are actually the variable values.

Is there an easy way to do this? I'd prefer not to use a custom function, as I want it to be natural for my end users.

@m93a
Copy link
Contributor

m93a commented Mar 8, 2019

Here test, you, brag and dog would be interpreted as variable names – this behavior is baked into Filtrex and there's really no way around. If you're not happy with something like contains("test") or contains("you") and contains("brad") and contains("dog"), you could add special string operators to the language, but this would probably be as difficult as writing a new filter engine from scratch.

Edit: When I think about it more, maybe overloading the logical operators could add some ergonomics. I mean, boolean values would behave the same as they did, but for the rest, instead of coercing to boolean, the compiler would construct an expression tree and then, when you apply a function on it, it would distribute the function to the inside. Let me demonstrate this on an example:

This thing:
contains( "test" or "you" and "brad" and "dog" )

Compile-time translates into this:
contains("test") or contains("you") and contains("brad") and contains("dog")

The problem with this behavior, however, is the dichotomy between booleans and other types, as it would have to be decided on runtime, depending on the type information only available on runtime. And adding different operators like & takes away the readability and similarity to human language, so does wrapping the "distributed" sections into eg. braces.

So while the idea sounds good, I haven't yet come to an solution.

@bradparks
Copy link
Author

bradparks commented Mar 9, 2019

How about this idea?

#28

I know it mostly makes sense only for booleans, and other operators don't quite make sense, but it works for those cases, which is mostly what i want... I actually coded that up, then popped in here to comment and saw your comments ;-)

@m93a
Copy link
Contributor

m93a commented Mar 9, 2019

I love your idea, it provides extensibility that fits the library very nicely! However, it seems that @joewalnes lost his interest in this repository a while ago. I'm strongly considering making my fork the default and hijacking the NPM module (see issue #22)… 🤔

@m93a
Copy link
Contributor

m93a commented Mar 1, 2020

I was just randomly browsing the issues and felt a sudden urge to point out this was implemented in the end. Tutorial for a text matcher in filtrex can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants