Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Updated post, added some markup for better readability

Last updated 1 year ago.
0

First off you can create a view in your DB that will hold concatenated game|title + video|title, this will make things easier. Then simply search the view.

Last updated 1 year ago.
0

jarektkaczyk said:

First off you can create a view in your DB that will hold concatenated game|title + video|title, this will make things easier. Then simply search the view.

Thank you very much for the reply! This will solve a large part of my problem. I do still have another problem of wich i'm not entirely sure if it will be easy to create.

To give a good example there is a games called "Grand Theft Auto V", which people often used to write like "GTA", "GTA 5" or "Grand theft 5".

Would this be a good solution? :


<?php

/ ** TABLE videos **/
	ID | search_col
	----------------
	1  | Grand Theft V Trailer GTA V GTA 5 Grand Theft 5

/**-------------- **/

$userInput = 'GTA V Trailer';

// Array ( 'GTA',  'V', 'Trailer' )
$keywords = explode( ' ', $userInput);

$video = Video::query();

foreach($keywords as $keyword){
	$video->where('search_col', 'LIKE', '%'. $keyword .'%');
}

$videos = $video->get();



Last updated 1 year ago.
0

For best user experience you could setup dictionary and use it with every search query. Then whenever a user searches for GTA 5 or GTA5 or GTA V or grand theft auto etc.. you translate it to grand theft auto 5 (entry in the db). It works like 'did you mean ...' in google and other serach engines or apps. Additionally you may want to run string comparison to sort the results as best for the user.

The query looks fine.

Last updated 1 year ago.
0

jarektkaczyk said:

For best user experience you could setup dictionary and use it with every search query. Then whenever a user searches for GTA 5 or GTA5 or GTA V or grand theft auto etc.. you translate it to grand theft auto 5 (entry in the db). It works like 'did you mean ...' in google and other serach engines or apps. Additionally you may want to run string comparison to sort the results as best for the user.

The query looks fine.

Thanks! This seems like the best solution for my problem :)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dmitrev dmitrev Joined 13 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.