Enhance Search Execution Results with DSL Handling
- Added a `Results` field to the `SearchExecutionResult` struct to store raw search results, facilitating the extraction of DSL from database searches. - Implemented logic in the `saveSearch` method to extract and store the first DSL from DB search results, improving data retention for search operations. - Introduced a `dslToMap` method in the DB handler to convert QueryDSL to a map format for storage, enhancing the flexibility of result handling. - Updated the `Result` struct to include a `DSL` field for generated QueryDSL, ensuring comprehensive data representation for database search results.
This commit is contained in:
parent
3cf3060e0c
commit
36939cd53a
3 changed files with 39 additions and 0 deletions
|
|
@ -518,6 +518,7 @@ func (ast *Assistant) executeAutoSearch(ctx *context.Context, messages []context
|
|||
Keywords: extractedKeywords,
|
||||
Config: ast.configToMap(searchConfig),
|
||||
RefCtx: refCtx,
|
||||
Results: results,
|
||||
Duration: duration,
|
||||
SearchType: "auto",
|
||||
})
|
||||
|
|
@ -925,6 +926,7 @@ type SearchExecutionResult struct {
|
|||
Keywords []searchTypes.Keyword // Extracted keywords with weights
|
||||
Config map[string]any // Search config used
|
||||
RefCtx *searchTypes.ReferenceContext // Reference context with results
|
||||
Results []*searchTypes.Result // Raw search results (for extracting DSL, etc.)
|
||||
Duration int64 // Search duration in ms
|
||||
Error error // Error if failed
|
||||
SearchType string // "auto", "web", "kb", "db"
|
||||
|
|
@ -1012,6 +1014,16 @@ func (ast *Assistant) saveSearch(ctx *context.Context, execResult *SearchExecuti
|
|||
searchRecord.Prompt = execResult.RefCtx.Prompt
|
||||
}
|
||||
|
||||
// Extract DSL from DB search results
|
||||
if execResult.Results != nil {
|
||||
for _, result := range execResult.Results {
|
||||
if result != nil && result.Type == searchTypes.SearchTypeDB && result.DSL != nil {
|
||||
searchRecord.DSL = result.DSL
|
||||
break // Only store the first DSL (usually there's only one DB search)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save to store
|
||||
if err := store.SaveSearch(searchRecord); err != nil {
|
||||
ctx.Logger.Warn("Failed to save search record: %v", err)
|
||||
|
|
|
|||
|
|
@ -207,6 +207,9 @@ func (h *Handler) SearchWithContext(ctx *agentContext.Context, req *types.Reques
|
|||
items = items[:maxResults]
|
||||
}
|
||||
|
||||
// 7. Convert DSL to map for storage
|
||||
dslMap := h.dslToMap(result.DSL)
|
||||
|
||||
return &types.Result{
|
||||
Type: types.SearchTypeDB,
|
||||
Query: req.Query,
|
||||
|
|
@ -214,6 +217,7 @@ func (h *Handler) SearchWithContext(ctx *agentContext.Context, req *types.Reques
|
|||
Items: items,
|
||||
Total: len(items),
|
||||
Duration: time.Since(start).Milliseconds(),
|
||||
DSL: dslMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -377,3 +381,23 @@ func (h *Handler) extractContent(rec map[string]interface{}, mod *model.Model) s
|
|||
}
|
||||
return string(content)
|
||||
}
|
||||
|
||||
// dslToMap converts QueryDSL to map for storage
|
||||
func (h *Handler) dslToMap(dsl *gou.QueryDSL) map[string]interface{} {
|
||||
if dsl == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal and unmarshal to get a clean map
|
||||
data, err := json.Marshal(dsl)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(data, &result); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ type Result struct {
|
|||
|
||||
// Graph associations (KB only, if enabled)
|
||||
GraphNodes []*GraphNode `json:"graph_nodes,omitempty"`
|
||||
|
||||
// DB specific
|
||||
DSL map[string]interface{} `json:"dsl,omitempty"` // Generated QueryDSL (DB only)
|
||||
}
|
||||
|
||||
// ResultItem represents a single search result item
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue