@@ -82,6 +82,13 @@ class SphinxQL
8282 */
8383 protected $ group_by = array ();
8484
85+ /**
86+ * When not null changes 'GROUP BY' to 'GROUP N BY'
87+ *
88+ * @var null|int
89+ */
90+ protected $ group_n_by = null ;
91+
8592 /**
8693 * ORDER BY array
8794 *
@@ -561,7 +568,11 @@ public function compileSelect()
561568 $ query .= $ this ->compileMatch ().$ this ->compileWhere ();
562569
563570 if (!empty ($ this ->group_by )) {
564- $ query .= 'GROUP BY ' .implode (', ' , $ this ->group_by ).' ' ;
571+ $ query .= 'GROUP ' ;
572+ if ($ this ->group_n_by !== null ) {
573+ $ query .= $ this ->group_n_by .' ' ;
574+ }
575+ $ query .= 'BY ' .implode (', ' , $ this ->group_by ).' ' ;
565576 }
566577
567578 if (!empty ($ this ->within_group_order_by )) {
@@ -999,6 +1010,21 @@ public function groupBy($column)
9991010 return $ this ;
10001011 }
10011012
1013+ /**
1014+ * GROUP N BY clause (SphinxQL-specific)
1015+ * Changes 'GROUP BY' into 'GROUP N BY'
1016+ *
1017+ * @param int $n Number of items per group
1018+ *
1019+ * @return SphinxQL
1020+ */
1021+ public function groupNBy ($ n )
1022+ {
1023+ $ this ->group_n_by = $ n ;
1024+
1025+ return $ this ;
1026+ }
1027+
10021028 /**
10031029 * WITHIN GROUP ORDER BY clause (SphinxQL-specific)
10041030 * Adds to the previously added columns
@@ -1351,6 +1377,7 @@ public function reset()
13511377 $ this ->where = array ();
13521378 $ this ->match = array ();
13531379 $ this ->group_by = array ();
1380+ $ this ->group_n_by = null ;
13541381 $ this ->within_group_order_by = array ();
13551382 $ this ->having = array ();
13561383 $ this ->order_by = array ();
@@ -1382,6 +1409,7 @@ public function resetMatch()
13821409 public function resetGroupBy ()
13831410 {
13841411 $ this ->group_by = array ();
1412+ $ this ->group_n_by = null ;
13851413
13861414 return $ this ;
13871415 }
0 commit comments