Skip to content
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

[3.x]: searchScore below 1 are set to null #11973

Closed
dgsiegel opened this issue Sep 20, 2022 · 2 comments
Closed

[3.x]: searchScore below 1 are set to null #11973

dgsiegel opened this issue Sep 20, 2022 · 2 comments

Comments

@dgsiegel
Copy link

What happened?

Description

Suppose you have a simple entry search like the following:

{% set results = craft.entries()
  .search('foo')
  .orderBy('score')
  .all() %}

{% for r in results %}
  {{ r.searchScore }}
{% endfor %}

This will output all search scores of matching entries. However all numbers were cast to an integer.

If you inspect the search scores at this point (https://github.com/craftcms/cms/blob/v3/src/elements/db/ElementQuery.php#L2909), you'll get the actual floating numbers.

At some point however they are cast to an integer, and I think the culprit could be this line (https://github.com/craftcms/cms/blob/v3/src/base/Element.php#L1837):

$this->searchScore = (int)$this->searchScore ?: null;

Expected behavior

searchScore's below 1 should be set to a 0 or the actual floating value.

Actual behavior

searchScore's below 1 are set to null instead of a number.

Craft CMS version

3.7.54

PHP version

PHP 8.0.18

Operating system and version

No response

Database type and version

MySQL

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Just released Craft 3.7.55 and 4.2.5 with a fix.

@dgsiegel
Copy link
Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants