0

For a relatively small Drupal 8 website, I need to enable a search box, with multiple indexes based on the path or menu value.

For example; the main menu has 2 menu items linking to basic pages: Employers and Employees, and rest of the website pages are created under these two pages, and each page has a menu item with matching hierarchy.

  • Employers
    • Section A
      • Sub-section A-1
      • Sub-section A-2
      • Sub-section A-3
    • Section B
      • Sub-section B-1
    • Section C
      • Sub-section C-1
      • Sub-section C-2
  • Employees
    • Section D
      • Sub-section D-1
      • Sub-section D-2
    • Section E
      • Sub-section E-1
      • Sub-section E-2
      • Sub-section E-3
      • Sub-section E-4
    • Section F
      • Sub-section F-1
      • Sub-section F-2
      • Sub-section F-3

I need to be able to search only in Employers or Employees. And the search results must be limited to those indivual landing pages.

Thoughts?

2 Answers 2

2

I was able to resolve the issue by using the Views, not through the search indexes as I initially thought was the path for a solution.

Created a required field for the content-types that would be searched against. Let's call it Section for now, with the values of Employers and Employees. This will be used in the view to filter content by section. (Taxonomy terms can be used for this as well.)

Then created a view page for each section.

enter image description here

In the view, used Content for the row style with Search result highlighting input option, and sorted content by Search: Score (asc).

The real trick for this to work is enabling Search result highlighting input display mode and configuring it with the fields we want to be searched within.

Hope this helps who needs a similar solution in their projects.

1

Thee is no out of the box solution available.

Nodes have a "Path" field, but it's a special field at the moment that doesn't load data when requested.

Using the Search API project, you could implement your own code to make the path available at index time, so that you can filter by it.

What's more common is to not have the path be the primary data for this but have reference fields or list fields where you store this information and based on that generate an automated alias (menu still needs to be set up manually). Then you are close to being able to create a view that allows to search and filter by that field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.