How set AND condition to ALL columns - php

前端 未结 2 1819
粉色の甜心
粉色の甜心 2021-01-22 12:18

In MY TABLE if I type

floor fly

table returns No matching records because Global Search php function search records insid

相关标签:
2条回答
  • 2021-01-22 12:43

    well, you should decide what search criteria you want to use. If you want you use match by certain phrase, and do not want to use FULL TEXT search, you should rebuild your query like:

    SELECT * FROM a WHERE a.col1 REGEXP 'text1|text2|text3' OR a.col2 REGEXP 'text1|text2|text3';
    

    In your PHP code, it should be smth like this (you did not specify input data format, so I assume, you are using "$str" as space separated text, and want to check all words in "$str" phrase for search:

    if ( $requestColumn['searchable'] == 'true' ) {
       $str = str_replace(" ","|",$str);
       $binding = self::bind( $bindings, $str, PDO::PARAM_STR );
       $globalSearch[] = "".$column['db']." REGEXP ".$binding;
    }
    
    0 讨论(0)
  • 2021-01-22 12:54

    This is a bit long for a comment.

    For this type of search, you might consider a full text index. The documentation is here. These implement the MATCH . . . AGAINST functionality.

    With such functionality, you can order the results by relevance. This means that you do not have to decide in advance whether the connector is "and" or "or" between multiple words. You can also implement a boolean search, which would allow for more complex complex logic, if you so desire.

    0 讨论(0)
提交回复
热议问题