tantivy icon indicating copy to clipboard operation
tantivy copied to clipboard

Add a lenient mode to QueryParser

Open fulmicoton opened this issue 8 years ago • 7 comments

The role of the QueryParser is to give an off-the-shelf solution to people wanting to deliver a search box to end user. Currently QueryParser::parse can return an error if the query does not match our query grammar.

e.g.: +(happy : the parenthesis is not closed.

This is great, but how should somebody writing a site handle this error? Maybe for a log analysis search engine, displaying an explicit syntax error is a good idea, but for most use case, (ecommerce, document search, etc.) we want to never return an error and just do our best to handle the user query.

For this reason, we want to add a new parse_lenient that would never fail and always return a result.

pub fn parse_query_lenient(&self, query: &str) -> Box<Query> {
    // ...
}

The behavior of this lenient mode does NOT have to be very smart... For instance, it could be a second very naive parser taking over when the initial parser failed.

For instance, this naive parser could remove all special characters and run the initial parser.

Smarter attempts to interpret the faulty user query are also welcome, as long as we return Box<Query> and we are confident the code will never panic.

fulmicoton avatar Aug 16 '16 00:08 fulmicoton

Not really a bug... but well.

fulmicoton avatar Aug 16 '16 01:08 fulmicoton

Requires #57

fulmicoton avatar Nov 09 '16 00:11 fulmicoton

If you can give me some more specs I'd be willing to take a look at this. I like things that are about making it better for the user

drusellers avatar Aug 17 '18 02:08 drusellers

Improved the description. The ticket voluntarily does not give much implementation details.

fulmicoton avatar Aug 17 '18 04:08 fulmicoton

What's the status of this? I see the opened PR has recently been closed, seemingly without result?

I'm currently working on a web application, which exposes search functionality to non-technical users, and I was hoping I could let them try their hands into using advanced queries, with some sort of fallback in case they fail. This would be just what the doctor ordered.

If #382 has merely stalled, and not dropped due to fundamental problems, I can put in the hours to get it over the finish line.

slckl avatar Feb 05 '21 13:02 slckl

Any news on this? It's problematic we still don't have a lenient mode when exposing the search feature to non-technical users...

ClementNerma avatar Apr 04 '22 11:04 ClementNerma

If someone wants to pick this feature it is up for grabs.

fulmicoton avatar Apr 04 '22 13:04 fulmicoton

Reassigning to @trinity-1686a

fulmicoton avatar Jun 15 '23 05:06 fulmicoton