mysql - Get similar entities in Symfony using Doctrine -
I have a unit in the symphony for the video saying that DB looks like this:
id: full name: varchar uploader: int (user unit) video_mp4: varchar param1: int param2: int param3: int
I want to load similar videos.
Actually I get the most matching (which means that the same user uploaded The video should be more important with the same parameter 1 + Ultimate 3 then there is only one where there is only 2 matching) order by most matches Dexc
How to get any ideas I have to use this question for this ( Yes I know that is not good for "db" or "sugestions are welcome;))
I created a function in my entity class that looks like this: ($ q is a quierbilder)
Public functions are found ($ q, $ limit = 6) {$ Uploader = $ this- & gt; GetUploader () - & gt; GetId (); $ Param 1 = $ this- & gt; GetParam1 (); $ Param 2 = $ this- & gt; GetParam2 (); $ Param 3 = $ this- & gt; GetParam3 (); $ Q- & gt; ('MyBackendBundle: Video', 'e') -> Choose from ('E') - & gt; Where ('e.id! =? 0') - & gt; And where ('e.uploader =? 1 or E. Param 1 =? 2 or E. Param 2 =? 3 or E. Param 3 =? 4'); If ($ range> 0) {$ q-> SetMaxResults ($ border); } $ Q- & gt; Setpermators (Arrays ($ -; ID, $ Uploader, $ Param 1, $ Ultimate 2, $ Ultimate 3)); Return $ q- & gt; GetQuery () - & gt; GetResult (); }
Two questions:
- How can I get a query builder in one unit, I do not like to pass it to my controller.
- Is there a better way to load similar entries?
- How can I order them through the most similarity (Uploader, Ultimate 1, Ultimate 2, Paragraph 3), to make sure that I can do this with PHP but what will be the result 7 There will be a 100% match but can I load only 6?
You just add all these matches:
< Code> SELECT *, (CAST (e.uploader =? 1 Uncredited) + CAST (e.param1 =? 2 UNSIGNED AS) + CAST (unassigned as e.param2 =? 3) + Cast (E Parag 3 =? 4 unknowingly as the United Nations) match_count match_count decomm to video command
Comments
Post a Comment