Skip to content

PCH: Add category slug support in search#3210

Merged
acicovic merged 3 commits intodevelopfrom
add/section-slug-support-in-pch-search
Mar 24, 2025
Merged

PCH: Add category slug support in search#3210
acicovic merged 3 commits intodevelopfrom
add/section-slug-support-in-pch-search

Conversation

@acicovic
Copy link
Collaborator

@acicovic acicovic commented Mar 18, 2025

Description

With this PR, we're introducing a wp_parsely_use_category_slugs_in_searches filter. Setting it to true (strict bool, any other value will be considered as false) will force PCH's Related Posts search to use the category's slug instead of its name.

The filter name is purposefully generic since its use could be expanded to tools outside of PCH Related Posts, for any site setups requiring this configuration.

Edit: Initially, the filter name was wp_parsely_use_section_slugs_in_searches, but it was renamed to wp_parsely_use_category_slugs_in_searches after @vaurdan's feedback.

Motivation and context

How has this been tested?

  • Manually tested locally, using settings that emulate the customer's environment. Verified that searching by section works as expected when the wp_parsely_use_category_slugs_in_searches filter is set to true or false, as well as invalid values such as strings, numbers, null and undefined.
  • Existing tests pass.

Summary by CodeRabbit

  • New Features
    • Introduced a configurable option that adapts how post category is interpreted during searches, giving users a more tailored search experience.
    • Enhanced category handling in the editor sidebar and related content filters by supplying richer category details, which improves the precision of post categorization and display.

@acicovic acicovic added Changelog: Added PR to be added under the changelog's "Added" section Feature: PCI Ticket/PR related to Content Intelligence labels Mar 18, 2025
@acicovic acicovic added this to the 3.18.0 milestone Mar 18, 2025
@acicovic acicovic self-assigned this Mar 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

This pull request introduces support for using category slugs in search queries for PCH Related Posts. A new global boolean property is added to the Window interface to control this behavior. The Editor Sidebar’s PHP code now sets this configuration via an inline script, while the TypeScript side updates interfaces and data extraction logic. Specifically, the modification changes the type of sidebar post categories from simple strings to objects containing both a name and a slug, and adjusts component logic to use the flag when determining which value to use in search queries.

Changes

File(s) Change Summary
src/@types/assets/window.d.ts Added new boolean property wpParselyUseCategorySlugsInSearches to the global Window interface.
src/content-helper/editor-sidebar/class-editor-sidebar.php Modified the run() method to retrieve a filter value with apply_filters and inject an inline script setting window.wpParselyUseCategorySlugsInSearches.
src/content-helper/editor-sidebar/editor-sidebar.tsx, src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx, src/content-helper/editor-sidebar/related-posts/component.tsx Introduced new TypeScript interface SidebarPostDataCategory and changed SidebarPostData.categories from string[] to SidebarPostDataCategory[]; updated logic to extract both name and slug and selectively use one based on the wpParselyUseCategorySlugsInSearches flag.

Sequence Diagram(s)

sequenceDiagram
    participant PHP as Editor_Sidebar (PHP)
    participant WIN as Global Window
    participant TS as RelatedPosts Component (TS)

    PHP->>WIN: Inject inline script with wpParselyUseCategorySlugsInSearches flag
    WIN-->>TS: Provide configuration via window object
    TS->>TS: Check wpParselyUseCategorySlugsInSearches flag
    alt Flag is true
        TS->>TS: Use category slugs for search filtering
    else Flag is false
        TS->>TS: Use category names for search filtering
    end
Loading

Assessment against linked issues

Objective (Linked Issue) Addressed Explanation
Support slugs in search (#2968)

Possibly related PRs

Suggested reviewers

  • vaurdan

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab04587 and f01217e.

⛔ Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
📒 Files selected for processing (3)
  • src/@types/assets/window.d.ts (1 hunks)
  • src/content-helper/editor-sidebar/class-editor-sidebar.php (1 hunks)
  • src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/content-helper/editor-sidebar/related-posts/component-filter-settings.tsx
  • src/@types/assets/window.d.ts
  • src/content-helper/editor-sidebar/class-editor-sidebar.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: E2E against WordPress latest

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@acicovic acicovic marked this pull request as ready for review March 18, 2025 16:21
@acicovic acicovic requested a review from a team as a code owner March 18, 2025 16:21
Copy link
Contributor

@vaurdan vaurdan left a comment

Choose a reason for hiding this comment

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

This looks good to me! Approved.

Regarding the naming of the filter. wp_parsely_use_section_slugs_in_searches sounds good to me, however conceptually I'm not sure if we should call it use_category_slugs instead, considering that the actual slug comes from the WordPress category, that is matched with the Parse.ly section name. What do you think?

@acicovic
Copy link
Collaborator Author

Good point, I'll give it a thought. We probably are using WP terminology internally, and in this case it would make sense to go with category.

@acicovic
Copy link
Collaborator Author

acicovic commented Mar 24, 2025

@vaurdan, I've updated the filter's name per your feedback, and will be merging soon. You can take a look at the changes in f01217e if you want.

@acicovic acicovic changed the title PCH: Add section slug support in search PCH: Add category slug support in search Mar 24, 2025
@acicovic acicovic merged commit 831b23b into develop Mar 24, 2025
41 checks passed
@acicovic acicovic deleted the add/section-slug-support-in-pch-search branch March 24, 2025 09:17
github-actions bot added a commit that referenced this pull request Mar 24, 2025
…-in-pch-search PCH: Add category slug support in search" (831b23b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Added PR to be added under the changelog's "Added" section Feature: PCI Ticket/PR related to Content Intelligence

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PCH Related Posts: Support slugs in search

2 participants