-
Notifications
You must be signed in to change notification settings - Fork 20
IBX-11441: Provided proper index limit for the StringField for search engines
#744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
barw4
wants to merge
16
commits into
4.6
Choose a base branch
from
ibx-11441-textblock-index-limit
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3b3522e
IBX-11441: Provide proper index limit for the `StringField` for searc…
barw4 244ba13
IBX-11441: Baseline
barw4 e67bf2b
IBX-11441: Baseline
barw4 4778a8e
IBX-11441: Update
barw4 1677a1a
IBX-11441: PHPStan
barw4 7834c65
IBX-11441: Update
barw4 7148ad3
IBX-11441: Added logger
barw4 533c97e
IBX-11441: Rollbacked baseline
barw4 954e0ab
IBX-11441: Fixed logger
barw4 c96913d
IBX-11441: Removed new lines from indexed string in TextBlock
barw4 b641fff
IBX-11441: Altered tests
barw4 31d75bc
Used `autoconfigure`
barw4 259db31
PHPStan
barw4 3ff20a0
PHPStan
barw4 9d7ee58
PHPStan
barw4 5036fff
PHPStan
barw4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/lib/Search/Common/FieldValueMapper/StringMapperTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Tests\Core\Search\Common\FieldValueMapper; | ||
|
|
||
| use Ibexa\Contracts\Core\Search\Field; | ||
| use Ibexa\Contracts\Core\Search\FieldType\StringField; | ||
| use Ibexa\Core\Search\Common\FieldValueMapper\StringMapper; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * @covers \Ibexa\Core\Search\Common\FieldValueMapper\StringMapper | ||
| */ | ||
| final class StringMapperTest extends TestCase | ||
| { | ||
| private StringMapper $mapper; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->mapper = new StringMapper(); | ||
| } | ||
|
|
||
| public function testCanMap(): void | ||
| { | ||
| $field = $this->createFieldWithValue('hello', new StringField()); | ||
|
|
||
| self::assertTrue($this->mapper->canMap($field)); | ||
| } | ||
|
|
||
| public function testMapsPlainString(): void | ||
| { | ||
| $field = $this->createFieldWithValue('hello world', new StringField()); | ||
|
|
||
| self::assertSame('hello world', $this->mapper->map($field)); | ||
| } | ||
|
|
||
| public function testStripsNonPrintableCharacters(): void | ||
| { | ||
| $field = $this->createFieldWithValue("hello\x01\x02world", new StringField()); | ||
|
|
||
| self::assertSame('helloworld', $this->mapper->map($field)); | ||
| } | ||
|
|
||
| public function testReplacesTabAndVerticalWhitespaceWithSpace(): void | ||
| { | ||
| $field = $this->createFieldWithValue("hello\x09world\x0Bfoo", new StringField()); | ||
|
|
||
| self::assertSame('hello world foo', $this->mapper->map($field)); | ||
| } | ||
|
|
||
| public function testTruncatesToMaxTermLength(): void | ||
| { | ||
| $longValue = str_repeat('a', StringMapper::MAX_TERM_LENGTH + 100); | ||
| $field = $this->createFieldWithValue($longValue, new StringField()); | ||
| $result = $this->mapper->map($field); | ||
|
|
||
| self::assertSame(StringMapper::MAX_TERM_LENGTH, strlen($result)); | ||
| } | ||
|
|
||
| public function testTruncatesMultibyteStringAtCharacterBoundary(): void | ||
| { | ||
| // Each UTF-8 character here is 3 bytes (€ = E2 82 AC). | ||
| // Fill up to just past the limit so truncation must happen on a char boundary. | ||
| $char = '€'; | ||
| $charBytes = strlen($char); | ||
|
|
||
| self::assertSame(3, $charBytes); | ||
|
|
||
| $count = (int) ceil((StringMapper::MAX_TERM_LENGTH + $charBytes) / $charBytes); | ||
| $longValue = str_repeat($char, $count); | ||
|
|
||
| $field = $this->createFieldWithValue($longValue, new StringField()); | ||
| $result = $this->mapper->map($field); | ||
|
|
||
| self::assertSame(StringMapper::MAX_TERM_LENGTH, strlen($result)); | ||
| // Result must be valid UTF-8 (no split mid-character). | ||
| self::assertSame(1, preg_match('//u', $result)); | ||
| } | ||
|
|
||
| public function testValueWithinLimitIsNotTruncated(): void | ||
| { | ||
| $value = str_repeat('a', StringMapper::MAX_TERM_LENGTH); | ||
| $field = $this->createFieldWithValue($value, new StringField()); | ||
|
|
||
| self::assertSame($value, $this->mapper->map($field)); | ||
| } | ||
|
|
||
| private function createFieldWithValue(string $value, StringField $type): Field | ||
| { | ||
| $field = $this->createMock(Field::class); | ||
| $field | ||
| ->method('getValue') | ||
| ->willReturn($value); | ||
| $field | ||
| ->method('getType') | ||
| ->willReturn($type); | ||
|
|
||
| return $field; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against changing the method name here, because what we are doing is we're extracting the first paragraph - and another "field" (see calling location) contains the whole text.
(that's what
strtokdoes in this context)or straight up declare what we're doing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think the method name is correct, but implementation is not. Imo we should store whole text, not just first paragraph by simply removing new lines. Wdyt @Steveb-p @konradoboza @alongosz?