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

Issue 290 allow granular search by sections #301

Merged
merged 5 commits into from
May 19, 2022

Conversation

onweru
Copy link
Collaborator

@onweru onweru commented May 14, 2022

This PR fixes issue #290

Changes / fixes

  1. Searching within a section produce results only from that section.
    For example, if you have 2 mainSections 1/ vegetables 2/ fruits, searching in the fruits section will only produce results for that section.

  2. Searching outside a section will search the entire site.
    For example, with the above mainSections setup, searching from the homepage will produce results from both sections and other pages of the site.

    Future implementations may include a github-like feature i.e search all site. This PR will leave that to a future PR

    Screen Shot 2022-05-15 at 00 10 53

Screenshots (if applicable)

(prefer animated gif)

Checklist

Ensure you have checked off the following before submitting your PR.

@chipzoller

This comment was marked as duplicate.

Copy link
Owner

@chipzoller chipzoller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would a visitor to that site know that the search they were executing was in context of that mainSection and not site-global?

@onweru
Copy link
Collaborator Author

onweru commented May 15, 2022

How would a visitor to that site know that the search they were executing was in context of that mainSection and not site-global?

🤔 interesting question. They wouldn't really know in most cases; at least in this current form. This implementation assumes that the user would most likely benefit from results from the section they are searching from.

I would like to clarify something though. The search function has no awareness of mainSections, only the site author has that knowledge. The function is only aware of the Section (scope), only when the user is in it. Perhaps fruits & vegetables are too rudimentary. A better example would be blog & docs. I assume it would be preferable to return docs results from the docs section. Even if the user doesn't know, they would benefit nonetheless.

This situation is still not quite ideal, hence 👇🏼

Future implementations may include a github-like feature i.e search all site

I think should read as "may should include a github-like feature i.e search all site, search blog, search docs ..."

@chipzoller
Copy link
Owner

Ok, so with this change, would a user still be able to execute a global search if they weren't navigated to one of those sections, or does this essentially replace the current global search with section-scoped search?

@onweru
Copy link
Collaborator Author

onweru commented May 15, 2022

Ok, so with this change, would a user still be able to execute a global search if they weren't navigated to one of those sections, or does this essentially replace the current global search with section-scoped search?

Yes, any search outside a section is a global search by default. Scope only applies within sections. For example, using neonmirrors searches from the homepage, about us or any other page that is outside the posts section will be global.

@chipzoller
Copy link
Owner

My suggestion would be one of two following options until a more advanced search can be implemented:

  1. Make search truly "global" without being confined to simply one mainSection entry.
  2. If section-scoped search is implemented, define a way to inform the user (perhaps as "shadow" text when clicking in the search box) this search will be isolated to the section where they are executing the search.

@rootwork what's your suggestion here?

@onweru
Copy link
Collaborator Author

onweru commented May 15, 2022

Just to clarify,

Make search truly "global" without being confined to simply one mainSection entry.

The changes in this PR fix this very problem. On master, the active search scope is restrained to one mainSection. Else it was hardcoded to 'post' section. That's why in issue #290, specifying more than one entry threw the search off.

  1. Now, the search function has no awareness of mainSections entries, it doesn't use them at all. The Section scope is defined on the page level.
  2. the hardcoded post section is removed.
  3. In Hugo Section refers to the top-level folder in the content directory. Therefore, the search function doesn't treat nested sections as independent scope; only the topmost Section applies as valid scope,
    From what I have observed, most site authors use these top level folders to isolate 'apples' from 'oranges'; if they've more than one of this folder anyway. My sense is that unless searching from outside a section, it rarely benefits a user search for an orange from within a basket of apples. That's not to say that global search is entirely undesirable.

@chipzoller
Copy link
Owner

I see, thanks for Clarity (ha!). @rootwork what is your opinion?

Copy link
Contributor

@rootwork rootwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good step forward, and I like making things more configurable.

@onweru if you're not ready to take on the sitewide search option right away, maybe just create an issue or a draft PR so it doesn't get forgotten, since I do think that would be good to work towards.

README.md Outdated Show resolved Hide resolved
Copy link
Owner

@chipzoller chipzoller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor readme change requested.

@chipzoller chipzoller merged commit e511e14 into master May 19, 2022
@onweru onweru deleted the issue-290-allow-granular-search-by-sections branch May 19, 2022 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants