As far as I know, there are currently no libraries to search for queries in natural language, neither in PHP, nor in any other programming language (I suppose you cannot use IBM Watson :).
I think possible approaches are a parser and fuzzy search :
Using a parser generator, such as Jison , you can analyze and "understand" in the user's browser all the statements that correspond to the generating grammar, sending only the generated query or intermediate representation to the server.
This is better than the PHP parser because the user can get immediate feedback when entering text and is less disappointing than submitting a form and receiving an error message. Interpretation of the request in this case will be 99% correct, but in many cases the perfectly correct (from a human point of view) request will be rejected because it will not include a grammar.
In another case, you can do some pre-processing, for example, deleting stop words, creating lowercase lines, creating lines, etc., then searching using a full-text search engine (Lucene is probably the most powerful, but in Java). PostgreSQL supports it , and MySQL also has some full text search capabilities. It is also possible to build a primitive engine based on a basic DBMS using index and tokenizing text on spaces and punctuation.
Which method depends on how varied and noisy your data and various expected requests are. You can also try to implement a hybrid approach, that is, analyze the text using the grammar, and if you could not use the full text search.
source share