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

feat(api): enhance /search endpoint with flexible filtering and dynamic aggregations #155

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from

Conversation

kouloumos
Copy link
Member

@kouloumos kouloumos commented Dec 18, 2024

This PR is the first step towards addressing #154, enhancing the Bitcoin Search API with several new features and improvements:

  • Search API Enhancements:

    • Support for filter operations (include/exclude).
    • OR logic via array values.
    • Dynamic aggregation fields and sub-aggregations.
    • Switching between default and coredev indices.

    For a deeper dive into the rationale and specifics of the new implementation, refer to Consolidate search functionality across products by enhancing Bitcoin Search API #154.

  • New /explore Page:

    • Replaces the existing /sources page, generalizing document exploration to include sources, authors, and tags.
    • Leverages the improved /search endpoint for a unified exploration experience.
    • Provides threaded, flat, and summary view modes for all content types.
    • Implements reusable data-fetching hooks for cleaner, modular code.
    • Serves as a testbed for the enhanced /search API.
  • Search Page Enhancements:

    • Support for dev mode document inspector for examining raw document data in search results.
      Set dev mode by running in the browser console:
    localStorage.setItem('devMode', 'true')
    

    devmode

  • Code Refactor:

Copy link

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bitcoinsearch-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2025 10:04am

},
};
const buildFilterQueryClause = (filter: Facet): QueryDslQueryContainer => {
if (Array.isArray(filter.value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what situation would you have the filter value as an array?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

An array filter means OR clause between the filters in the array. For more you can read the comment on the line below this or the extended explanation in the connected issue.

Copy link
Collaborator

@Emmanuel-Develops Emmanuel-Develops left a comment

Choose a reason for hiding this comment

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

Works good! (Tested with postman)

@Emmanuel-Develops
Copy link
Collaborator

@kouloumos can you rebase on staging

@kouloumos
Copy link
Member Author

can you rebase on staging

just did. I am not sure what happened and @0tuedon's d099438 commit made it here after the rebase with the latest staging. I'll just drop it.

Add support for filter operations (include/exclude), OR logic via array
values, dynamic aggregation fields and sub-aggregations in the search API.
Allow switching between default and coredev indices. This consolidates
search functionality across products by making the Bitcoin Search API
more flexible while maintaining backward compatibility.
@kouloumos
Copy link
Member Author

kouloumos commented Jan 28, 2025

I just updated the PR with a change in the Explore Page that takes advantage of the newly introduced API functionality for switching between indices to allow exploration of documents on both of our indices. For this to work, we need to define a new COREDEV_INDEX env variable in our deployment, cc @Emmanuel-Develops edit: no need for this after c4c1e7f

@kouloumos
Copy link
Member Author

Just pushed an update that removes the need for index-related environment variables (INDEX and COREDEV_INDEX). Since index names aren't sensitive information, I moved them to a typed configuration in src/config/config.ts. This makes it easier to:

  • Add new indexes without requiring environment changes
  • Maintain type-safety across the application
  • Document available indexes directly in the code

Introduces a flexible explore page that generalizes source exploration to handle domains, authors, and tags.
Consolidates API usage by leveraging the existing /search endpoint with aggregations instead of specialized
source endpoints. The new implementation uses reusable hooks for data fetching and provides threaded,
 flat, and summary view modes across different content types.
Removes /sources and /sourceDocuments endpoints and their associated hooks
now that their functionality has been consolidated into the /search endpoint
used by the explore interface.
@kouloumos
Copy link
Member Author

Just pushed a new commit that adds support for dev mode document inspector for examining raw document data in search results.

Set dev mode by running in the browser console:

localStorage.setItem('devMode', 'true')

devmode

The application was previously using URLs to fetch document content, but URLs
are not guaranteed to be unique across documents. Switch to using Elasticsearch
document IDs which are guaranteed unique identifiers. Update types, API
endpoints, and components to pass document IDs instead of URLs throughout the
content fetching flow.
Implement index selector dropdown to toggle between default
and coredev indexes throughout the explore page. Update all
data fetching hooks and components to support index selection,
including document exploration, thread views, and content modal.
This enables users to seamlessly switch between different
elasticsearch indices while maintaining consistent data fetching across all views.
Moves index names from environment variables to config.ts since they
aren't sensitive data. This provides type-safety and makes it easier to
add new indexes. Updates API endpoints, components and
documentation to use the new configuration.
Adds a clickable code icon to search result cards when dev mode is enabled
(via localStorage) that opens a modal showing the raw document data.
</div>

{showModal && (
<DocumentModal
Copy link
Collaborator

Choose a reason for hiding this comment

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

For devMode in the results page, is there a reason fetching the document again?

we can pull the data already and pass it along to render. The only difference is data exempted from the main query, i.e summary_embeddings will be unavaialable

Copy link
Member Author

Choose a reason for hiding this comment

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

it makes it easier:

  • it allows us to reuse the same component as is
  • I don't need to care about moving data
  • This is a mode that will not be used a lot

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