Skip to content

Commit

Permalink
Phrase query test (#1107)
Browse files Browse the repository at this point in the history
* Phrase query test

* Add more reserved characters to test phrase

Co-authored-by: Alexander Schranz <alexander@sulu.io>

* Add back `\r\n` sequence

---------

Co-authored-by: Alexander Schranz <alexander@sulu.io>
Co-authored-by: Markus Kalkbrenner <git@kalki.de>
  • Loading branch information
3 people authored Nov 27, 2023
1 parent 3095ebd commit f33afe7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/Integration/AbstractTechproductsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function testEscapes(string $requestFormat)
$update->addCommit(true, true);
self::$client->update($update);

// check if stored correctly in index
$select = self::$client->createSelect();
$select->setQuery('id:%T1%', ['solarium-test-escapes']);
$result = self::$client->select($select);
Expand Down Expand Up @@ -332,6 +333,62 @@ public function testEscapes(string $requestFormat)
$this->assertCount(0, $result);
}

/**
* @see https://github.com/solariumphp/solarium/issues/1104
*
* @dataProvider updateRequestFormatProvider
*/
public function testPhraseQuery(string $requestFormat)
{
$phrase = "^The 17\" O'Conner && O`Series \n OR a || 1%2 1~2 1*2 \r\n book? \r \twhat \\ text: }{ )( ][ - + // \n\r ok? end$";

$update = self::$client->createUpdate();
$update->setRequestFormat($requestFormat);
$doc = $update->createDocument();
$doc->setField('id', 'solarium-test-phrase');
$doc->setField('name', 'Solarium Test Phrase Query');
$doc->setField('cat', [$phrase]);
$update->addDocument($doc);
$update->addCommit(true, true);
self::$client->update($update);

if ($update::REQUEST_FORMAT_XML === $requestFormat) {
/*
* Per https://www.w3.org/TR/REC-xml/#sec-line-ends line breaks are normalized
*
* [...] by translating both the two-character sequence #xD #xA and
* any #xD that is not followed by #xA to a single #xA character.
*/
$phrase = str_replace(["\r\n", "\r"], ["\n", "\n"], $phrase);
}

// check if stored correctly in index
$select = self::$client->createSelect();
$select->setQuery('id:solarium-test-phrase');
$result = self::$client->select($select);
$this->assertSame([$phrase], $result->getIterator()->current()->getFields()['cat']);

// as term
$select->setQuery('cat:%T1%', [$phrase]);
$result = self::$client->select($select);
$this->assertCount(1, $result);
$this->assertSame('solarium-test-phrase', $result->getIterator()->current()->getFields()['id']);

// as phrase
$select->setQuery('cat:%P1%', [$phrase]);
$result = self::$client->select($select);
$this->assertCount(1, $result);
$this->assertSame('solarium-test-phrase', $result->getIterator()->current()->getFields()['id']);

// cleanup
$update->addDeleteQuery('cat:%P1%', [$phrase]);
$update->addCommit(true, true);
self::$client->update($update);
$select->setQuery('id:solarium-test-phrase');
$result = self::$client->select($select);
$this->assertCount(0, $result);
}

/**
* @see https://github.com/solariumphp/solarium/issues/974
* @see https://solr.apache.org/guide/local-parameters-in-queries.html#basic-syntax-of-local-parameters
Expand Down

0 comments on commit f33afe7

Please sign in to comment.