|
4 | 4 | from typing import Optional |
5 | 5 | import uuid |
6 | 6 |
|
7 | | -from sqlalchemy import select, delete, update, or_, func |
| 7 | +from sqlalchemy import select, delete, update, or_, func, cast |
8 | 8 | from sqlalchemy.ext.asyncio import AsyncSession |
9 | 9 | from open_webui.internal.db import Base, JSONField, get_async_db_context |
10 | 10 |
|
@@ -313,11 +313,16 @@ async def search_knowledge_files( |
313 | 313 | permission='read', |
314 | 314 | ) |
315 | 315 |
|
316 | | - # Apply filename search |
| 316 | + # Apply filename / content search |
317 | 317 | if filter: |
318 | 318 | q = filter.get('query') |
319 | 319 | if q: |
320 | | - stmt = stmt.filter(File.filename.ilike(f'%{q}%')) |
| 320 | + stmt = stmt.filter( |
| 321 | + or_( |
| 322 | + File.filename.ilike(f'%{q}%'), |
| 323 | + cast(File.data['content'], Text).ilike(f'%{q}%'), |
| 324 | + ) |
| 325 | + ) |
321 | 326 |
|
322 | 327 | # Order by file changes |
323 | 328 | stmt = stmt.order_by(File.updated_at.desc(), File.id.asc()) |
@@ -467,7 +472,12 @@ async def search_files_by_id( |
467 | 472 | if filter: |
468 | 473 | query_key = filter.get('query') |
469 | 474 | if query_key: |
470 | | - stmt = stmt.filter(or_(File.filename.ilike(f'%{query_key}%'))) |
| 475 | + stmt = stmt.filter( |
| 476 | + or_( |
| 477 | + File.filename.ilike(f'%{query_key}%'), |
| 478 | + cast(File.data['content'], Text).ilike(f'%{query_key}%'), |
| 479 | + ) |
| 480 | + ) |
471 | 481 |
|
472 | 482 | view_option = filter.get('view_option') |
473 | 483 | if view_option == 'created': |
|
0 commit comments