Extend String Search to Include Path Aliases

Created on 19 September 2023, 10 months ago
Updated 30 September 2023, 9 months ago

Problem/Motivation

The Linkit module currently supports searching for node titles when a user types a string. However, it does not include path aliases in this search, which limits the usability of the module. This issue aims to enhance the Linkit module by extending the string search functionality to include path aliases, providing users with a more comprehensive search experience.

Steps to reproduce

1. Install and enable the Linkit module.
2. Create or edit a content entity that contains a link field.
3. Try to add a link using the Linkit module.
4. Type a string that exists in the path alias of a node.

Proposed resolution

The proposed resolution for this issue involves modifying the Linkit module's search functionality to include path aliases in its search scope.
so i created this patch : linkit_autocomplete_alias.patch, and i need a review

Remaining tasks

Review The patch.

Thank you.

✨ Feature request
Status

Needs work

Version

6.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 10 months ago
    Patch Failed to Apply
  • Issue created by @Merrydbe
  • Status changed to Needs work 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom james.williams

    Nice idea! On reviewing this, my first thought is that it's a real shame that the additional query is needed at all, as it seems you can't add a condition for the path on the initial query.

    Next, more actionable thoughts:

    1. Please use the injected database connection which is already available ($this->database) instead of \Drupal::database()
    2. The additional query could include a LIKE condition on the 'path' field so that it already matches the right path pattern, instead of using preg_match() to filter the results after querying.
    3. The query is currently specific to nodes, but the linkit class is rightly written to be as generic as possible for any entity type. So instead, the link template for the target entity type could be used (rather than hardcoding '/node/'). The condition in the above point could then use this. (Tip: $entity_type->getLinkTemplate('canonical') can be used; it gets '/node/{node}' for nodes - so the '{node}' part would then need stripping out, but remember it would need to work for any/most entity type(s). Any entity that doesn't have a canonical link template probably can't be supported anyway.)

    Final less actionable thought: wouldn't it be nice if Linkit could support querying on other fields too? Is there any work anywhere else for supporting that, e.g. in another issue?

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    wouldn't it be nice if Linkit could support querying on other fields too? Is there any work anywhere else for supporting that, e.g. in another issue?

    The active issue for this is at ✨ Search on non-title fields Needs review

Production build 0.69.0 2024