Project

Fuzzy entity reference module allows users to integrate loilo/fuse (https://github.com/loilo/Fuse) library for entity reference autocomplete.

Typically when we have CONTAINS or STARTS_WITH operator to match the entity reference results.
Sometimes what happens when we have the correct matching it doesn't consider appropriate string because it doesn't do the approximate search. Due to that matched string doesn't appear in the auto-complete results.

This module implements the fuzzy search on node title and displays the results based on the calculated distance from the searched input string.

Code checks

Pareview.sh output is coming okay apart from suggestions related to branch name.
Sharing following output:

<ul>
-e <li>It appears you are working in the "1.0.x" branch in git. You should really be working in a version specific branch. The most direct documentation on this is <a href="https://www.drupal.org/node/1127732">Moving from a master branch to a version branch.</a> For additional resources please see the documentation about <a href="https://www.drupal.org/node/1015226">release naming conventions</a> and <a href="https://www.drupal.org/node/1066342">creating a branch in git</a>.</li>
</ul>
Review of the 1.0.x branch (commit 5fad7e8):
<ul>
</ul>
<i>This automated report was generated with <a href="https://www.drupal.org/project/pareviewsh">PAReview.sh</a>, your friendly project application review script.</i>

Branch name is already following semantic versionsing.

Project link

https://www.drupal.org/project/fuzzy_entity_reference

Comments

mohit_aghera created an issue. See original summary.

mohit_aghera’s picture

Status: Active » Needs review
vishal.kadam’s picture

Thank you for applying! Reviewers will review the project files, describing what needs to be changed.

Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

To reviewers: Please read How to review security advisory coverage applications, What to cover in an application review, and Drupal.org security advisory coverage application workflow.

While this application is open, only the user who opened the application can make commits to the project used for the application.

Reviewers only describe what needs to be changed; they don't provide patches to fix what reported in a review.

vishal.kadam’s picture

Issue summary: View changes
avpaderno’s picture

Issue summary: View changes
vishal.kadam’s picture

Hello @mohit_aghera,

I have reviewed the code and it look fine to me.

Let’s wait for other reviewers to take a look and if everything goes fine, you will get the role.

Thanks

andrei.vesterli’s picture

hi @mohit_aghera

  • I would set requirements like this core_version_requirement: ^8.8 || ^9 || ^10 and not core_version_requirement: ^8 || ^9 || ^10 because it has 10 too.
  • Remove core: 8.x from info file
  • Change this line to this getReferenceableEntities(bool $match = NULL, string $match_operator = 'CONTAINS', int $limit = 10) and test it.
  • As a suggestion, add the PHP version requirements in the composer.json file.

The rest seems to be ok.

Regards,
Andrei

andrei.vesterli’s picture

Status: Needs review » Needs work
mohit_aghera’s picture

Status: Needs work » Needs review

Hi @andrei.vesterli
Fixed 1, 2 and 4th points.

Regarding point 3: I think PHP will throw error due to declaration of method compatibility.
Base class's method doesn't have typed arguments.

Update:
Tried 3rd points on local and got following error:
Declaration of Drupal\fuzzy_entity_reference\Plugin\EntityReferenceSelection\FuzzyEntityAutocomplete::getReferenceableEntities(?bool $match = NULL, string $match_operator = 'CONTAINS', int $limit = 10): array must be compatible with Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0

andrei.vesterli’s picture

Hi @mohit_aghera again

I see. It's an extend probably. No worries then. For me, this is more than ok!

Regards,
Andrei

reszli’s picture

General remark:
This appreach loads all the possible entities that can possibly be referenced in order to build the source of the fuzzy search.
This can be an issues for sites with a large number of entities - this should be explained on the project detail page.
Even for small/medium data sets, IMHO a major performance imporovement would be to cache that data and only invalidate on ENTITY_TYPE_list:BUNDLE cache tags.

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.
Coding style & Drupal API usage
List of identified issues in no particular order
  1. Just a recommendation: split larger method into smaller chunks for readability

This review uses the Project Application Review Template.

avpaderno’s picture

Status: Needs review » Needs work
  • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
  • A specific point may just be an example and may apply in other places
  • A review is about code that doesn't follow the coding standards, contains possible security issue, or doesn't correctly use the Drupal API; the single points aren't ordered, not even by importance

Since the module is compatible with Drupal 8.8.x and Drupal 9.x, it cannot use features implemented in PHP 8.1 without declaring the minimum required PHP version. Either that or the code is changed to be compatible with the PHP version required by Drupal 8.8.x.

src/Plugin/Field/FieldWidget/FuzzyAutocompleteWidget.php

  /**
   * {@inheritdoc}
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, AccountProxyInterface $current_user) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
    $this->currentUser = $current_user;
  }

{@inheritdoc} is not used for class constructors.

mohit_aghera’s picture

@reszli
Thank you for the feedback.
I've little doubt about following:
Even for small/medium data sets, IMHO a major performance imporovement would be to cache that data and only invalidate on ENTITY_TYPE_list:BUNDLE cache tags.
I initially tried to cache it, however, since search term can be anything, we can't cache the results based on the search term.
Can you please give me more information, it seems I am missing something here.

@apaderno
{@inheritdoc} is not used for class constructors.
It is already added here https://git.drupalcode.org/project/fuzzy_entity_reference/-/blob/1.0.x/s...
Should I describe each argument further?

avpaderno’s picture

I am referring to the documentation comment before the class constructor.

  /**
   * {@inheritdoc}
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, AccountProxyInterface $current_user) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
    $this->currentUser = $current_user;
  }

{@inheritdoc} is not used for class constructors. Their documentation comments need to document the parameters the constructor receives, but not the return value.

reszli’s picture

@mohit_aghera I'm proposing to cache the list of entity labels used to run the search on (and not caching the search results themselves)

https://git.drupalcode.org/project/fuzzy_entity_reference/-/blob/1.0.x/s..., lines 57-82, aka. the $matches variable calculation could be cached until new labels are added / existing ones are updated

mohit_aghera’s picture

Status: Needs work » Needs review

Hi @reszli
Thanks for the feedback and guidance for the implementation.
I did refactoring so that we can cache the results for particular search term.

I've pushed the code in the branch along with test for it.
Commit https://git.drupalcode.org/project/fuzzy_entity_reference/-/commit/1df25...
(Please ignore schema changes from config, already removed in next commit)

Also, I've fixed the changes mentioned by @apaderno in comment #14

Can you please review this and let me know how it goes?

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Reviewed & tested by the community

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the Slack #contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the reviewers.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.