Skip to content

feat(search): add ranked post id pool API#3

Merged
rbcorrales merged 4 commits into
mainfrom
feat/native-search-post-ids
May 26, 2026
Merged

feat(search): add ranked post id pool API#3
rbcorrales merged 4 commits into
mainfrom
feat/native-search-post-ids

Conversation

@rbcorrales

Copy link
Copy Markdown
Member

Summary

Adds Search::post_ids() for consumers that need a ranked pool of unique post IDs and want to hydrate inside their own WP_Query context.

  1. Adds Search::MAX_POOL, capped at 200.
  2. Reuses dense, sparse, and hybrid ranking.
  3. Collapses raw chunk rows by doc_id before hydration.
  4. Keeps Search::run() unchanged, including the public 20 result cap and response shape.

Manual test plan

  1. On a site with indexed posts, invoke Search::post_ids() from a small test plugin, a theme snippet, or wp eval with mode values dense, sparse, and hybrid.
  2. Confirm each call returns a plain ordered list of post IDs rather than enriched result rows.
  3. Confirm a post with multiple matching chunks appears once, at the position of its best ranked chunk.
  4. Confirm requesting a pool larger than 200 returns no more than 200 IDs.
  5. Confirm a caller can run a perm => readable hydration pass and preserve the returned ranking with orderby => post__in.
  6. Confirm a normal Smart Search or Ability request that uses Search::run() still returns the existing result payload.

Co-authored-by: Codex <noreply@openai.com>
rbcorrales and others added 3 commits May 25, 2026 20:13
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new consumer-facing API, WPVDB_Search\Search::post_ids(), to return an ordered, de-duplicated pool of ranked post IDs (for callers that want to hydrate results in their own WP_Query context) while keeping Search::run() behavior and payload unchanged.

Changes:

  • Introduces Search::post_ids() and Search::MAX_POOL (200), reusing existing dense/sparse/hybrid ranking and collapsing chunk rows to unique doc_ids.
  • Adds a private helper collapse_raw_post_ids() to de-duplicate merged chunk rows while preserving rank order.
  • Updates unit tests, test bootstrap stubs, and README documentation to cover and describe the new API.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
includes/class-search.php Adds MAX_POOL, implements post_ids(), and adds collapse_raw_post_ids() to return ranked unique post IDs.
tests/Unit/SearchTest.php Adds unit tests covering raw collapse behavior, post ID pools across modes, and pool clamping.
tests/bootstrap.php Extends WP/WPVDB stubs to support fulltext checks, embeddings, and SQL/json helpers used by the new path.
README.md Documents Search::post_ids() usage, arguments, max pool cap, and hydration/visibility responsibilities for callers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rbcorrales rbcorrales merged commit b95a65e into main May 26, 2026
3 checks passed
@rbcorrales rbcorrales deleted the feat/native-search-post-ids branch May 27, 2026 21:49
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.

2 participants