Skip to content

Commit 13a46d3

Browse files
authored
Merge pull request #106 from alpha0010/master
Add setSelect() and getSelect() to modify select fields
2 parents 165e702 + 43216cb commit 13a46d3

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ matrix:
2525
before_install:
2626
- mkdir $HOME/sphinx
2727
- pushd $HOME/sphinx
28-
- wget --quiet http://ppa.launchpad.net/builds/sphinxsearch-${SPHINXSEARCH_BUILD}/ubuntu/dists/`lsb_release -cs`/main/binary-amd64/Packages
28+
- wget --quiet http://ppa.launchpad.net/builds/sphinxsearch-${SPHINXSEARCH_BUILD}/ubuntu/dists/`lsb_release -cs`/main/binary-amd64/Packages.gz
29+
- gzip -d Packages.gz
2930
- SPHINX_DEB=`grep -m1 Filename Packages | cut -f2 -d' '`
3031
- wget --quiet -O sphinxsearch.deb http://ppa.launchpad.net/builds/sphinxsearch-${SPHINXSEARCH_BUILD}/ubuntu/${SPHINX_DEB}
3132
- dpkg -x sphinxsearch.deb .

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)