How to parse custom user search request into full-text search?

Viewed 144

At the moment I am using a simple full-text search with against/match of full phrase typed by the user. The idea is to allow user type a search request using the following connectors:

AND, OR, NOT
"" - exact match
() - grouping terms
* - single letter wildcard
! - root expander
/n - terms within n words of each other
/s - terms within same sentence of each other
/p - terms within the same paragraph

All these connectors will work as boolean operators. The task contains two parts:
1. to parse the string typed by the user (with the possible syntax errors)
2. build the SQL query

The exact same search works here - https://casetext.com/search

Also, I'm wondering if it will be easier to move to Lucena/Solr or Elasticsearch which have build-in parsers but still not the same what I need?

I saw already this parsing user-typed Full Text Search queries into WHERE clause of MySQL using PHP but it's not giving any answers

And I saw these packages:
https://packagist.org/packages/pecee/boolean-query-parser - basic syntax supported
https://packagist.org/packages/gdbots/query-parser - more sophisticated but not covering last 4 connectors from my list

0 Answers
Related