- Refactored the Search method to support context-aware execution, allowing handlers to utilize context when performing searches. - Introduced a new SearchWithContext method in the handler interface to facilitate context-based search operations. - Updated the DB handler to implement the context-aware search, ensuring proper QueryDSL generation and execution. - Enhanced test cases to validate the new context requirements and scenarios for database searches, improving error handling and robustness. - Added scenario type support for QueryDSL generation, allowing for more complex query handling. - Updated documentation to reflect the new context handling and scenario features in search operations.
24 lines
739 B
Go
24 lines
739 B
Go
package interfaces
|
|
|
|
import (
|
|
"github.com/yaoapp/yao/agent/context"
|
|
"github.com/yaoapp/yao/agent/search/types"
|
|
)
|
|
|
|
// Handler defines the interface for search implementations
|
|
type Handler interface {
|
|
// Type returns the search type this handler supports
|
|
Type() types.SearchType
|
|
|
|
// Search executes the search and returns results
|
|
Search(req *types.Request) (*types.Result, error)
|
|
}
|
|
|
|
// ContextHandler extends Handler with context support
|
|
// Handlers that need context (e.g., DB handler for QueryDSL generation) should implement this
|
|
type ContextHandler interface {
|
|
Handler
|
|
|
|
// SearchWithContext executes the search with context and returns results
|
|
SearchWithContext(ctx *context.Context, req *types.Request) (*types.Result, error)
|
|
}
|