[PR #14907] [CLOSED] feat: Advanced search filters (before/after date based search, multiple tags) #10436

Closed
opened 2025-11-11 19:04:44 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/14907
Author: @Classic298
Created: 6/11/2025
Status: Closed

Base: devHead: before-after-search-filter


📝 Commits (3)

📊 Changes

5 files changed (+272 additions, -178 deletions)

View changed files

📝 backend/open_webui/models/chats.py (+80 -120)
📝 backend/open_webui/routers/chats.py (+29 -15)
📝 src/lib/apis/chats/index.ts (+21 -2)
📝 src/lib/components/layout/SearchModal.svelte (+49 -12)
📝 src/lib/components/layout/Sidebar/SearchInput.svelte (+93 -29)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch. (Assuming dev based on common practice)
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources? (No documentation changes were made by me)
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation? (No new dependencies were added)
  • Testing: Have you written and run sufficient tests to validate the changes? (Manual testing was performed by you throughout the process)
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? (Yes, to the best of my ability)
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • feat: Introduces a new feature or enhancement to the codebase

Changelog Entry

Description

This pull request enhances the chat search functionality in Open WebUI by

  • adding support for multiple tag searches and
  • filtering by chat update recency using before:YYYY-MM-DD and after:YYYY-MM-DD parameters.

The implementation spans frontend UI components, API communication layers, and backend database query logic. Several minor bug fixes identified during development were also addressed.

Added

  • Advanced Search Parameters:
    • You can now filter chats by their last update time using before:YYYY-MM-DD and after:YYYY-MM-DD syntax.
    • Multiple tag:<tag_id> parameters can now be used simultaneously to find chats matching all specified tags.
    • Multiple different search parameters can now be combined (i.e. combining tag: with before: like so: tag:general before:2025-06-11)
  • Frontend UI for New Filters:
    • SearchInput.svelte now suggests before: and after: parameters with descriptions.
    • SearchModal.svelte parses these new parameters from the query string.
  • Backend Support for New Filters:
    • API endpoint (/api/v1/chats/search) updated to accept tags, before_date, and after_date query parameters.
    • Database query logic in models/chats.py updated to filter chats based on updated_at timestamps and multiple tags.

Changed

  • Search Query Parsing (Frontend):
    • SearchModal.svelte's parseSearchQuery function updated to extract structured search terms (text, tags, before date, after date) from your input string.
    • (Note: Attempts to handle optional spaces like before: YYYY-MM-DD were reverted to maintain stability, so no space is currently supported after the colon).
  • API Layer (apis/chats/index.ts):
    • getChatListBySearchText now sends a structured object containing parsed search parameters to the backend.
  • Backend Router (routers/chats.py):
    • search_user_chats endpoint signature changed to accept distinct query parameters for text, tags, before date, and after date.
  • Backend Model (models/chats.py):
    • get_chats_by_user_id_and_search_text method signature changed to accept distinct search parameters.
    • Logic for tag filtering now uses the explicit list of tags.
    • Date filtering implemented by converting date strings to UTC timestamps and comparing against the updated_at field. before:DATE includes DATE (until 23:59:59 UTC), and after:DATE includes DATE (from 00:00:00 UTC).

Additional Information

  • The development process involved iterative testing and feedback
  • The before:DATE and after:DATE filters operate on the chat's updated_at timestamp. (This is the most logical approach in my opinion and is also logical from the added descriptive text for the two new parameters)

Screenshots or Videos

image

image
(this is correct because the cutoff for the dates is always at midnight - searching "before:2025-06-11" would yield all chats updated BEFORE 2025-06-11 at 23:59 for example, and searching for "after:2025-06-11" will yield all chats updated AFTER 2025-06-11 00:01 for example)

image
Combining different search parameters for a more detailed search!

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/14907 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 6/11/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `before-after-search-filter` --- ### 📝 Commits (3) - [`24de507`](https://github.com/open-webui/open-webui/commit/24de507c97f783857650da513eebaa2fe2b6bd86) merge (#10) - [`b35f358`](https://github.com/open-webui/open-webui/commit/b35f3584d45a1ab14104abec0279a4cbe4673145) Update chats.py - [`dd688d5`](https://github.com/open-webui/open-webui/commit/dd688d5033bed7d40121ced7472118f6aab02a14) Update SearchModal.svelte ### 📊 Changes **5 files changed** (+272 additions, -178 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/chats.py` (+80 -120) 📝 `backend/open_webui/routers/chats.py` (+29 -15) 📝 `src/lib/apis/chats/index.ts` (+21 -2) 📝 `src/lib/components/layout/SearchModal.svelte` (+49 -12) 📝 `src/lib/components/layout/Sidebar/SearchInput.svelte` (+93 -29) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. (Assuming `dev` based on common practice) - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? (No documentation changes were made by me) - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? (No new dependencies were added) - [x] **Testing:** Have you written and run sufficient tests to validate the changes? (Manual testing was performed by you throughout the process) - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? (Yes, to the best of my ability) - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **feat**: Introduces a new feature or enhancement to the codebase --- # Changelog Entry ### Description This pull request enhances the chat search functionality in Open WebUI by - adding support for multiple tag searches and - filtering by chat update recency using `before:YYYY-MM-DD` and `after:YYYY-MM-DD` parameters. The implementation spans frontend UI components, API communication layers, and backend database query logic. Several minor bug fixes identified during development were also addressed. ### Added - **Advanced Search Parameters:** - You can now filter chats by their last update time using `before:YYYY-MM-DD` and `after:YYYY-MM-DD` syntax. - Multiple `tag:<tag_id>` parameters can now be used simultaneously to find chats matching all specified tags. - Multiple different search parameters can now be combined (i.e. combining `tag:` with `before:` like so: `tag:general before:2025-06-11`) - **Frontend UI for New Filters:** - `SearchInput.svelte` now suggests `before:` and `after:` parameters with descriptions. - `SearchModal.svelte` parses these new parameters from the query string. - **Backend Support for New Filters:** - API endpoint (`/api/v1/chats/search`) updated to accept `tags`, `before_date`, and `after_date` query parameters. - Database query logic in `models/chats.py` updated to filter chats based on `updated_at` timestamps and multiple tags. ### Changed - **Search Query Parsing (Frontend):** - `SearchModal.svelte`'s `parseSearchQuery` function updated to extract structured search terms (text, tags, before date, after date) from your input string. - (Note: Attempts to handle optional spaces like `before: YYYY-MM-DD` were reverted to maintain stability, so no space is currently supported after the colon). - **API Layer (`apis/chats/index.ts`):** - `getChatListBySearchText` now sends a structured object containing parsed search parameters to the backend. - **Backend Router (`routers/chats.py`):** - `search_user_chats` endpoint signature changed to accept distinct query parameters for text, tags, before date, and after date. - **Backend Model (`models/chats.py`):** - `get_chats_by_user_id_and_search_text` method signature changed to accept distinct search parameters. - Logic for tag filtering now uses the explicit list of tags. - Date filtering implemented by converting date strings to UTC timestamps and comparing against the `updated_at` field. `before:DATE` includes `DATE` (until 23:59:59 UTC), and `after:DATE` includes `DATE` (from 00:00:00 UTC). --- ### Additional Information - The development process involved iterative testing and feedback - The `before:DATE` and `after:DATE` filters operate on the chat's `updated_at` timestamp. (This is the most logical approach in my opinion and is also logical from the added descriptive text for the two new parameters) ### Screenshots or Videos ![image](https://github.com/user-attachments/assets/b2e99b0a-1187-45b0-8415-2c8257f9c1c3) ![image](https://github.com/user-attachments/assets/9fec17e5-7729-4e1b-b1eb-afd52afaa3d5) (this is correct because the cutoff for the dates is always at midnight - searching "before:2025-06-11" would yield all chats updated BEFORE 2025-06-11 at 23:59 for example, and searching for "after:2025-06-11" will yield all chats updated AFTER 2025-06-11 00:01 for example) ![image](https://github.com/user-attachments/assets/94be279e-c6a8-4572-9f6e-9c81ae51af3d) Combining different search parameters for a more detailed search! ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-11 19:04:44 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#10436