Skip to content

Commit fa9aab0

Browse files
villermenstevelacey
authored andcommitted
Add full "IN BOOLEAN MODE" and "WITH QUERY EXPANSION" (beberlei#332)
1 parent 4bb8604 commit fa9aab0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Query/Mysql/MatchAgainst.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,39 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)
4949

5050
if (strtolower($lexer->lookahead['value']) === 'boolean') {
5151
$parser->match(Lexer::T_IDENTIFIER);
52+
$this->booleanMode = true;
53+
} elseif (strtolower($lexer->lookahead['value']) === 'in') {
54+
$parser->match(Lexer::T_IDENTIFIER);
55+
56+
if (strtolower($lexer->lookahead['value']) !== 'boolean') {
57+
$parser->syntaxError('boolean');
58+
}
59+
$parser->match(Lexer::T_IDENTIFIER);
60+
61+
if (strtolower($lexer->lookahead['value']) !== 'mode') {
62+
$parser->syntaxError('mode');
63+
}
64+
$parser->match(Lexer::T_IDENTIFIER);
65+
5266
$this->booleanMode = true;
5367
}
5468

5569
if (strtolower($lexer->lookahead['value']) === 'expand') {
5670
$parser->match(Lexer::T_IDENTIFIER);
71+
$this->queryExpansion = true;
72+
} elseif (strtolower($lexer->lookahead['value']) === 'with') {
73+
$parser->match(Lexer::T_IDENTIFIER);
74+
75+
if (strtolower($lexer->lookahead['value']) !== 'query') {
76+
$parser->syntaxError('query');
77+
}
78+
$parser->match(Lexer::T_IDENTIFIER);
79+
80+
if (strtolower($lexer->lookahead['value']) !== 'expansion') {
81+
$parser->syntaxError('expansion');
82+
}
83+
$parser->match(Lexer::T_IDENTIFIER);
84+
5785
$this->queryExpansion = true;
5886
}
5987

tests/Query/Mysql/MatchAgainstTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,36 @@ public function testMatchAgainst()
1313
"SELECT MATCH (b0_.id) AGAINST ('3') AS sclr_0 FROM Blank b0_"
1414
);
1515
}
16+
17+
public function testMatchAgainstMultipleFields()
18+
{
19+
$this->assertDqlProducesSql(
20+
"SELECT MATCH(post.longitude, post.latitude) AGAINST ('3') from DoctrineExtensions\Tests\Entities\BlogPost AS post",
21+
"SELECT MATCH (b0_.longitude, b0_.latitude) AGAINST ('3') AS sclr_0 FROM BlogPost b0_"
22+
);
23+
}
24+
25+
public function testMatchAgainstInBooleanMode()
26+
{
27+
$this->assertDqlProducesSql(
28+
"SELECT MATCH(blank.id) AGAINST ('+3 -4' BOOLEAN) from DoctrineExtensions\Tests\Entities\Blank AS blank",
29+
"SELECT MATCH (b0_.id) AGAINST ('+3 -4' IN BOOLEAN MODE) AS sclr_0 FROM Blank b0_"
30+
);
31+
$this->assertDqlProducesSql(
32+
"SELECT MATCH(blank.id) AGAINST ('+3 -4' IN BOOLEAN MODE) from DoctrineExtensions\Tests\Entities\Blank AS blank",
33+
"SELECT MATCH (b0_.id) AGAINST ('+3 -4' IN BOOLEAN MODE) AS sclr_0 FROM Blank b0_"
34+
);
35+
}
36+
37+
public function testMatchAgainstWithQueryExpansion()
38+
{
39+
$this->assertDqlProducesSql(
40+
"SELECT MATCH(blank.id) AGAINST ('3' EXPAND) from DoctrineExtensions\Tests\Entities\Blank AS blank",
41+
"SELECT MATCH (b0_.id) AGAINST ('3' WITH QUERY EXPANSION) AS sclr_0 FROM Blank b0_"
42+
);
43+
$this->assertDqlProducesSql(
44+
"SELECT MATCH(blank.id) AGAINST ('3' WITH QUERY EXPANSION) from DoctrineExtensions\Tests\Entities\Blank AS blank",
45+
"SELECT MATCH (b0_.id) AGAINST ('3' WITH QUERY EXPANSION) AS sclr_0 FROM Blank b0_"
46+
);
47+
}
1648
}

0 commit comments

Comments
 (0)