Skip to content

Commit 86ec00a

Browse files
committed
Add setSelect() and getSelect() to modify select fields
Fixes #51
1 parent 165e702 commit 86ec00a

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

src/SphinxQL.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,37 @@ public function select($columns = null)
813813
return $this;
814814
}
815815

816+
/**
817+
* Alters which arguments to select
818+
*
819+
* Query is assumed to be in SELECT mode
820+
* See select() for usage
821+
*
822+
* @param array|string $columns Array or multiple string arguments containing column names
823+
*
824+
* @return SphinxQL
825+
*/
826+
public function setSelect($columns = null)
827+
{
828+
if (is_array($columns)) {
829+
$this->select = $columns;
830+
} else {
831+
$this->select = \func_get_args();
832+
}
833+
834+
return $this;
835+
}
836+
837+
/**
838+
* Get the columns staged to select
839+
*
840+
* @return array
841+
*/
842+
public function getSelect()
843+
{
844+
return $this->select;
845+
}
846+
816847
/**
817848
* Activates the INSERT mode
818849
*

tests/SphinxQL/SphinxQLTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,56 @@ public function testSubselect()
924924
$this->assertEquals('10', $result[0]['id']);
925925
}
926926

927+
/**
928+
* @covers \Foolz\SphinxQL\SphinxQL::setSelect
929+
*/
930+
public function testSetSelect()
931+
{
932+
$this->refill();
933+
$q1 = SphinxQL::create(self::$conn)
934+
->select(array('id', 'gid'))
935+
->from('rt');
936+
$q2 = clone $q1;
937+
$q2->setSelect(array('id'));
938+
$result = $q1
939+
->execute()
940+
->getStored();
941+
$this->assertArrayHasKey('id', $result[0]);
942+
$this->assertArrayHasKey('gid', $result[0]);
943+
$result = $q2
944+
->execute()
945+
->getStored();
946+
$this->assertArrayHasKey('id', $result[0]);
947+
$this->assertArrayNotHasKey('gid', $result[0]);
948+
949+
$q1 = SphinxQL::create(self::$conn)
950+
->select('id', 'gid')
951+
->from('rt');
952+
$q2 = clone $q1;
953+
$q2->setSelect('id');
954+
$result = $q1
955+
->execute()
956+
->getStored();
957+
$this->assertArrayHasKey('id', $result[0]);
958+
$this->assertArrayHasKey('gid', $result[0]);
959+
$result = $q2
960+
->execute()
961+
->getStored();
962+
$this->assertArrayHasKey('id', $result[0]);
963+
$this->assertArrayNotHasKey('gid', $result[0]);
964+
}
965+
966+
/**
967+
* @covers \Foolz\SphinxQL\SphinxQL::getSelect
968+
*/
969+
public function testGetSelect()
970+
{
971+
$query = SphinxQL::create(self::$conn)
972+
->select('id', 'gid')
973+
->from('rt');
974+
$this->assertEquals(array('id', 'gid'), $query->getSelect());
975+
}
976+
927977
/**
928978
* @covers \Foolz\SphinxQL\SphinxQL::facet
929979
* @covers \Foolz\SphinxQL\SphinxQL::compileSelect

0 commit comments

Comments
 (0)