Skip to content

Commit 7eb2f10

Browse files
committed
[spalenque] - #13156 * improve videos search
1 parent bb2fa69 commit 7eb2f10

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

summit-video-app/code/SummitVideoAppBackend.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ public function getVideos($params = [])
112112

113113
case 'search':
114114
$search = trim($criteria);
115+
$search_words = explode(' ',$search);
116+
117+
foreach ($search_words as $key => $search_word) {
118+
// check for summit
119+
$summit = Summit::get()->filter('Title:PartialMatch', $search_word)->first();
120+
if ($summit) {
121+
$videos = $videos->where('Summit.ID = '.$summit->ID);
122+
unset($search_words[$key]);
123+
continue;
124+
}
125+
}
126+
127+
$search = implode(' ', $search_words);
128+
if (!empty($search)) {
129+
$videos = $videos->where("
130+
CONCAT(PresentationSpeaker.FirstName,' ',PresentationSpeaker.LastName) = '$search'
131+
OR PresentationSpeaker.FirstName LIKE '%$search%'
132+
OR PresentationSpeaker.LastName LIKE '%$search%'
133+
OR PresentationCategory.Title LIKE '%$search%'
134+
OR SummitEvent.Title LIKE '%$search%'"
135+
);
136+
}
115137

116138
$videos = $videos
117139
->innerJoin('Presentation', 'Presentation.ID = PresentationMaterial.PresentationID')
@@ -122,28 +144,20 @@ public function getVideos($params = [])
122144
->innerJoin('PresentationSpeaker',
123145
'PresentationSpeaker.ID = Presentation_Speakers.PresentationSpeakerID')
124146
->leftJoin('PresentationCategory', 'PresentationCategory.ID = SummitEvent.CategoryID')
125-
->where("
126-
CONCAT(PresentationSpeaker.FirstName,' ',PresentationSpeaker.LastName) = '$search'
127-
OR PresentationSpeaker.FirstName LIKE '%$search%'
128-
OR PresentationSpeaker.LastName LIKE '%$search%'
129-
OR SummitEvent.Title LIKE '%$search%'
130-
OR PresentationCategory.Title = '%$search%'
131-
OR Summit.Title LIKE '%$search%'")
132147
->limit($defaultLimit);
133148

134-
$match_videos = GroupedList::create($videos)->groupBy('YouTubeID');
135-
136-
$response = [
137-
'results' => []
138-
];
149+
$search_results = $videos->toArray();
150+
$unique_youtube_ids = [];
151+
$unique_videos = [];
139152

140-
foreach ($match_videos as $v) {
141-
if (is_a($v,'ArrayList'))
142-
$v = $v->first();
143-
$response['results'][] = $this->createVideoJSON($v);
153+
foreach ($search_results as $v) {
154+
if (!isset($unique_youtube_ids[$v->YouTubeID])) {
155+
$unique_youtube_ids[$v->YouTubeID] = 1;
156+
$unique_videos[] = $this->createVideoJSON($v);
157+
}
144158
}
145159

146-
return $response;
160+
return array( 'results' => $unique_videos );
147161

148162
}
149163

0 commit comments

Comments
 (0)