Skip to main content
Topic: Search with OR option (Read 1648 times) previous topic - next topic

Search with OR option

Hi,
i have an issue on a list page search Field.

i have in a db field named faq_problem some text: examp. "error on row rp8"
if i search 'error rp8' not record  displayed.
if i search 'error % rp8' wil show the record.
if i search 'rp8 % error' not record displayed.

How i can edit the search function?

the sql is like this: SELECT * FROM table WHERE (name LIKE '%value1%') OR (name LIKE '%value2%') ORDER BY id ASC

thx.

Re: Search with OR option

Reply #1
@alekib‍ please check the image below for reference.
1. For a List Page, you can configure the fields you want the search to match against on that page, by checking the fields checkbox and unchecking any field checkbox you don't want to add to the search
2. Use the SearchType to set the type of search you want to use in each field when searching. Note that this will depend on if you enabled the Search by checking the checkbox.

Re: Search with OR option

Reply #2
Hi willvin,
thanks for reply but your answer dont fix my issue.
Still not filter record if i invert the search terms.

i have found this code but i dont know ho to implement this on list page  search fields

$str = yourinput;
$strarray = (explode(" ",$str));
$query = "SELECT * FROM table WHERE ";
Foreach($strarray as $key=>$value){
If($key > 0){
$query = $query . "OR";
}
$query = $query . " (name LIKE '%" . $value . "%') ";
}
$query = $query . "ORDER BY id ASC";


 

Re: Search with OR option

Reply #4
@alekib‍ currently there is no configuration for that, you will need to edit your project manually after publishing it.
Ok. Can you explain me where is the file to be edit with new custom sql?
Thx.

Re: Search with OR option

Reply #5
@alekib‍ please locate the controllers folder in app/, there you will see a list of controllers, find and open the page controller you want to work on, the file name will start with the page name followed by controller.php(e.g InventoryController.php).  in the list() function you can now edit it to do what you want.