PHP full text search functionality using AND, OR and NOT operators
P粉076987386
2023-09-05 15:06:32
<p>Newbie question:
I'm trying to implement a full text search on a search string using php and eloquent. </p>
<pre class="brush:php;toolbar:false;">$searchstring = " (victim suspect) crime -covid";
$searchresult = RssItem::whereRaw("MATCH (description) AGAINST ('$searchstring' IN BOOLEAN MODE)")->get();</pre>
<p>I want my users to be able to set a search string like this: </p>
<pre class="brush:php;toolbar:false;">$searchstring = "(victim OR suspect) AND crime NOT covid";</pre>
<p>Is there an easy way to convert user input to a boolean full text search string for mysql in php? </p>
I've done it the following way:
But maybe there is a better way? :-)