Remove advanced search functionality from search-server and SessionSearch classes
- Deleted the advanced_search tool from the search-server.ts file, which combined full-text search with structured filters for observations and sessions. - Removed the advancedSearch method from the SessionSearch class, which handled the logic for performing advanced searches using FTS5 and structured filters.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -686,80 +686,6 @@ const tools = [
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'advanced_search',
|
|
||||||
description: 'Advanced search combining full-text search with structured filters across both observations and sessions. IMPORTANT: Always use index format first (default) to get an overview with minimal token usage, then use format: "full" only for specific items of interest.',
|
|
||||||
inputSchema: z.object({
|
|
||||||
textQuery: z.string().optional().describe('Optional text query for FTS5 search'),
|
|
||||||
format: z.enum(['index', 'full']).default('index').describe('Output format: "index" for titles/dates only (default, RECOMMENDED for initial search), "full" for complete details (use only after reviewing index results)'),
|
|
||||||
searchSessions: z.boolean().default(true).describe('Include session summaries in results'),
|
|
||||||
...filterSchema.shape
|
|
||||||
}),
|
|
||||||
handler: async (args: any) => {
|
|
||||||
try {
|
|
||||||
const { format = 'index', ...searchArgs } = args;
|
|
||||||
const results = search.advancedSearch(searchArgs);
|
|
||||||
|
|
||||||
const totalResults = results.observations.length + results.sessions.length;
|
|
||||||
|
|
||||||
if (totalResults === 0) {
|
|
||||||
return {
|
|
||||||
content: [{
|
|
||||||
type: 'text' as const,
|
|
||||||
text: 'No results found matching the search criteria'
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let combinedText: string;
|
|
||||||
if (format === 'index') {
|
|
||||||
const header = `Found ${totalResults} result(s) matching search criteria:\n\n`;
|
|
||||||
const formattedResults: string[] = [];
|
|
||||||
|
|
||||||
// Add observations
|
|
||||||
results.observations.forEach((obs, i) => {
|
|
||||||
formattedResults.push(formatObservationIndex(obs, i));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add sessions
|
|
||||||
results.sessions.forEach((session, i) => {
|
|
||||||
formattedResults.push(formatSessionIndex(session, i + results.observations.length));
|
|
||||||
});
|
|
||||||
|
|
||||||
combinedText = header + formattedResults.join('\n\n') + formatSearchTips();
|
|
||||||
} else {
|
|
||||||
const formattedResults: string[] = [];
|
|
||||||
|
|
||||||
// Add observations
|
|
||||||
results.observations.forEach((obs, i) => {
|
|
||||||
formattedResults.push(formatObservationResult(obs, i));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add sessions
|
|
||||||
results.sessions.forEach((session, i) => {
|
|
||||||
formattedResults.push(formatSessionResult(session, i + results.observations.length));
|
|
||||||
});
|
|
||||||
|
|
||||||
combinedText = formattedResults.join('\n\n---\n\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
content: [{
|
|
||||||
type: 'text' as const,
|
|
||||||
text: combinedText
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
return {
|
|
||||||
content: [{
|
|
||||||
type: 'text' as const,
|
|
||||||
text: `Search failed: ${error.message}`
|
|
||||||
}],
|
|
||||||
isError: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -473,67 +473,6 @@ export class SessionSearch {
|
|||||||
return this.db.prepare(sql).all(...params) as ObservationSearchResult[];
|
return this.db.prepare(sql).all(...params) as ObservationSearchResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Advanced search combining FTS5 and structured filters
|
|
||||||
*/
|
|
||||||
advancedSearch(options: {
|
|
||||||
textQuery?: string;
|
|
||||||
searchSessions?: boolean;
|
|
||||||
} & SearchOptions): {
|
|
||||||
observations: ObservationSearchResult[];
|
|
||||||
sessions: SessionSummarySearchResult[];
|
|
||||||
} {
|
|
||||||
const { textQuery, searchSessions = true, ...searchOptions } = options;
|
|
||||||
|
|
||||||
let observations: ObservationSearchResult[] = [];
|
|
||||||
let sessions: SessionSummarySearchResult[] = [];
|
|
||||||
|
|
||||||
if (textQuery) {
|
|
||||||
// Use FTS5 search
|
|
||||||
observations = this.searchObservations(textQuery, searchOptions);
|
|
||||||
if (searchSessions) {
|
|
||||||
sessions = this.searchSessions(textQuery, searchOptions);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Pure structured query (no FTS)
|
|
||||||
const params: any[] = [];
|
|
||||||
const filterClause = this.buildFilterClause(searchOptions, params, 'o');
|
|
||||||
|
|
||||||
if (filterClause) {
|
|
||||||
const obsSql = `
|
|
||||||
SELECT o.*
|
|
||||||
FROM observations o
|
|
||||||
WHERE ${filterClause}
|
|
||||||
${this.buildOrderClause(searchOptions.orderBy, false)}
|
|
||||||
LIMIT ? OFFSET ?
|
|
||||||
`;
|
|
||||||
params.push(searchOptions.limit || 50, searchOptions.offset || 0);
|
|
||||||
observations = this.db.prepare(obsSql).all(...params) as ObservationSearchResult[];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchSessions) {
|
|
||||||
const sessionParams: any[] = [];
|
|
||||||
const sessionFilters = { ...searchOptions };
|
|
||||||
delete sessionFilters.type;
|
|
||||||
const sessionFilterClause = this.buildFilterClause(sessionFilters, sessionParams, 's');
|
|
||||||
|
|
||||||
if (sessionFilterClause) {
|
|
||||||
const sessSql = `
|
|
||||||
SELECT s.*
|
|
||||||
FROM session_summaries s
|
|
||||||
WHERE ${sessionFilterClause}
|
|
||||||
ORDER BY s.created_at_epoch DESC
|
|
||||||
LIMIT ? OFFSET ?
|
|
||||||
`;
|
|
||||||
sessionParams.push(searchOptions.limit || 50, searchOptions.offset || 0);
|
|
||||||
sessions = this.db.prepare(sessSql).all(...sessionParams) as SessionSummarySearchResult[];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { observations, sessions };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the database connection
|
* Close the database connection
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user