mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Fix search tests
This commit is contained in:
parent
2973661099
commit
22d2feb50b
@ -123,19 +123,19 @@ class MysqlDriver extends AbstractDriver
|
||||
$againstQuery = '';
|
||||
|
||||
foreach ($query->andTerms as $keyword) {
|
||||
$againstQuery .= '+' . $keyword . '* ';
|
||||
$againstQuery .= '+' . rtrim($keyword, '*') . '* ';
|
||||
}
|
||||
foreach ($query->orTerms as $keyword) {
|
||||
$againstQuery .= $keyword . '* ';
|
||||
$againstQuery .= rtrim($keyword, '*') . '* ';
|
||||
}
|
||||
foreach ($query->orTerms as $keyword) {
|
||||
$againstQuery .= $keyword . ' ';
|
||||
foreach ($query->notTerms as $keyword) {
|
||||
$againstQuery .= '-' . $keyword . ' ';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'MATCH(%s) AGAINST (%s IN BOOLEAN MODE)',
|
||||
implode(', ', $matchFields),
|
||||
Yii::$app->db->quoteValue($againstQuery)
|
||||
Yii::$app->db->quoteValue(trim($againstQuery))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace humhub\modules\content\tests\codeception\unit\search;
|
||||
use humhub\modules\content\models\Content;
|
||||
use humhub\modules\content\Module;
|
||||
use humhub\modules\content\search\driver\AbstractDriver;
|
||||
use humhub\modules\content\search\driver\MysqlDriver;
|
||||
use humhub\modules\content\search\driver\ZendLucenceDriver;
|
||||
use humhub\modules\content\search\ResultSet;
|
||||
use humhub\modules\content\search\SearchRequest;
|
||||
use humhub\modules\content\services\ContentSearchService;
|
||||
@ -47,28 +47,29 @@ abstract class AbstractDriverTestSuite extends HumHubDbTestCase
|
||||
#$this->assertEquals(1, count($this->getSearchResultByKeyword('Marabru')->results));
|
||||
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('Marabru Leav Abcd')->results));
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('+Marabru +Leav +Abcd')->results));
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('+Marabru +Leav* +Abcd')->results));
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('Marabru Leav +Abcd')->results));
|
||||
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('Some -Marabru')->results));
|
||||
|
||||
// Wildcards
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('Marabr*')->results));
|
||||
}
|
||||
|
||||
public function testShortKeywords()
|
||||
{
|
||||
if ($this->searchDriver instanceof MysqlDriver) {
|
||||
// Not possible on MySQLDriver
|
||||
return;
|
||||
}
|
||||
|
||||
$space = Space::findOne(['id' => 1]);
|
||||
$this->becomeUser('Admin');
|
||||
(new Post($space, Content::VISIBILITY_PUBLIC, ['message' => 'Some Other']))->save();
|
||||
(new Post($space, Content::VISIBILITY_PUBLIC, ['message' => 'Marabru Leav Test X']))->save();
|
||||
|
||||
// Short keywords
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('M')->results));
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('X')->results));
|
||||
$this->assertEquals(0, count($this->getSearchResultByKeyword('R')->results));
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('T')->results));
|
||||
if ($this->searchDriver instanceof ZendLucenceDriver) {
|
||||
// MysqlDriver can find only at least 2 char exist after "X"
|
||||
$this->assertEquals(1, count($this->getSearchResultByKeyword('X')->results));
|
||||
}
|
||||
}
|
||||
|
||||
private function getSearchRequest(): SearchRequest
|
||||
|
Loading…
x
Reference in New Issue
Block a user