We have an orders table with more than 100,000 records in it. The scenario is to search a string from all tables' columns and find the matching results. We have this query in place but it takes more than 30 seconds to complete.
$searchkeyword = "Umair";
$orders = Orders::orderBy("order_number","DESC")
->where(
[
['order_id','=',$searchkeyword],
]
)
->orWhere(
[
['shipping->first_name','LIKE','%'.$searchkeyword.'%'],
]
)
->orWhere(
[
['shipping->last_name','LIKE','%'.$searchkeyword.'%'],
]
)
->orWhere(
[
['billing->email','=',$searchkeyword],
]
)
->orWhere(
[
['billing->phone','=',$searchkeyword],
]
)
->orWhere(
[
['shipping->country','=',$searchkeyword],
]
)
->orWhere(
[
['woo_date_created','LIKE','%'.$searchkeyword.'%']
]
)
->orWhere(
[
['shipment_details->tracking_code','LIKE','%'.$searchkeyword.'%']
]
)
->orWhere([
['shipment_details','LIKE','%'.$searchkeyword.'%']
])
->paginate(200)
->toJson();
Can you please tell me if there is a better and faster way in eloquent to perform such searches?