Sonu's avatar
Level 3

How we can Limit over Search Query

I want to know that there is any way to limit the search query. Actually i have 10 Lakh records in Db. For example if a user search chicken then its search from all data base and generate the pagination. so its generate alot of pages.

I want to just search on 2000 records only. How can i do that. Here is my search function

$input = trim(Input::get('diet_search'));
    $exp = explode(' ', $input);
    $s = '';
    $c = 1;
    foreach ($exp AS $e)
    {
        $s .= "+$e*";
    
        if ($c + 1 == count($exp))
            $s .= ' ';
        $c++;
    }
    $query = "MATCH (diet_name) AGAINST ('$s' IN BOOLEAN MODE)";    
    $result = Diets::whereRaw($query)->paginate(10);
    return view('Front.my_health.health')->with('result',$result);
0 likes
8 replies
martinbean's avatar

I want to just search on 2000 records only

@Sonu I don’t understand this. Which particular 2000 records…?

Sonu's avatar
Level 3

@martinbean if user search chicken then query search all records related to chicken in 10 lakh records. i just want he can only get 2000 records not all.

Sonu's avatar
Level 3

Means that query just return only 2000 records which word user search. its it possible. ?

PLB-RR's avatar

I don't know if take or limit goes together with paginate.

But if you are going top cap it, why 2000? A user will not go through 2000 results.

jekinney's avatar

Group by breaks laravel's pagination but using limit shouldn't. You have to test it but should work.

jekinney's avatar

After your whereRaw and paginate slip in limit().

Please or to participate in this conversation.