import React, { useState } from 'react'; import { Box, Paper, Typography, FormControl, FormControlLabel, Switch, Select, MenuItem, InputLabel, Accordion, AccordionSummary, AccordionDetails, Chip, Slider, TextField, Button, Divider, IconButton, Tooltip, Alert, List, ListItem, ListItemIcon, ListItemText, ToggleButtonGroup, ToggleButton, Card, CardContent, Collapse, Badge, Grid, } from '@mui/material'; import { ExpandMore as ExpandMoreIcon, ExpandLess as ExpandLessIcon, Settings as SettingsIcon, Speed as SpeedIcon, Visibility as VisibilityIcon, TextSnippet as SnippetIcon, Search as SearchIcon, Tune as TuneIcon, Psychology as PsychologyIcon, FormatQuote as QuoteIcon, Code as CodeIcon, BlurOn as BlurIcon, Help as HelpIcon, RestoreFromTrash as ResetIcon, BookmarkBorder as SaveIcon, Lightbulb as TipIcon, } from '@mui/icons-material'; type SearchMode = 'simple' | 'phrase' | 'fuzzy' | 'boolean'; interface AdvancedSearchSettings { useEnhancedSearch: boolean; searchMode: SearchMode; includeSnippets: boolean; snippetLength: number; fuzzyThreshold: number; resultLimit: number; includeOcrText: boolean; includeFileContent: boolean; includeFilenames: boolean; boostRecentDocs: boolean; enableAutoCorrect: boolean; } interface AdvancedSearchPanelProps { settings: AdvancedSearchSettings; onSettingsChange: (settings: Partial) => void; onSavePreset?: (name: string, settings: AdvancedSearchSettings) => void; onLoadPreset?: (preset: AdvancedSearchSettings) => void; availablePresets?: { name: string; settings: AdvancedSearchSettings }[]; expanded?: boolean; onExpandedChange?: (expanded: boolean) => void; } const AdvancedSearchPanel: React.FC = ({ settings, onSettingsChange, onSavePreset, onLoadPreset, availablePresets = [], expanded = false, onExpandedChange, }) => { const [activeSection, setActiveSection] = useState('search-behavior'); const [showPresetSave, setShowPresetSave] = useState(false); const [presetName, setPresetName] = useState(''); const sections = [ { id: 'search-behavior', label: 'Search Behavior', icon: , description: 'How search queries are processed and matched', }, { id: 'results-display', label: 'Results Display', icon: , description: 'How search results are shown and formatted', }, { id: 'performance', label: 'Performance', icon: , description: 'Speed and resource optimization settings', }, { id: 'content-sources', label: 'Content Sources', icon: , description: 'Which parts of documents to search', }, ]; const handleSettingChange = ( key: K, value: AdvancedSearchSettings[K] ) => { onSettingsChange({ [key]: value }); }; const handleResetToDefaults = () => { const defaults: AdvancedSearchSettings = { useEnhancedSearch: true, searchMode: 'simple', includeSnippets: true, snippetLength: 200, fuzzyThreshold: 0.8, resultLimit: 100, includeOcrText: true, includeFileContent: true, includeFilenames: true, boostRecentDocs: false, enableAutoCorrect: true, }; onSettingsChange(defaults); }; const handleSavePreset = () => { if (presetName.trim() && onSavePreset) { onSavePreset(presetName.trim(), settings); setPresetName(''); setShowPresetSave(false); } }; const getSearchModeDescription = (mode: SearchMode) => { switch (mode) { case 'simple': return 'Basic keyword matching with stemming'; case 'phrase': return 'Exact phrase matching in order'; case 'fuzzy': return 'Flexible matching with typo tolerance'; case 'boolean': return 'Advanced operators (AND, OR, NOT)'; default: return ''; } }; return ( onExpandedChange?.(!expanded)} > Advanced Search Options Customize search behavior and result display {expanded ? : } {/* Section Tabs */} {sections.map((section) => ( ))} {/* Search Behavior Section */} {activeSection === 'search-behavior' && ( These settings control how your search queries are interpreted and matched against documents. Search Mode {getSearchModeDescription(settings.searchMode)} Fuzzy Match Threshold: {settings.fuzzyThreshold} handleSettingChange('fuzzyThreshold', value as number)} min={0.1} max={1.0} step={0.1} marks disabled={settings.searchMode !== 'fuzzy'} valueLabelDisplay="auto" valueLabelFormat={(value) => `${(value * 100).toFixed(0)}%`} /> Higher values = stricter matching handleSettingChange('useEnhancedSearch', e.target.checked)} /> } label="Enhanced Search Engine" /> handleSettingChange('enableAutoCorrect', e.target.checked)} /> } label="Auto-correct Spelling" /> handleSettingChange('boostRecentDocs', e.target.checked)} /> } label="Boost Recent Documents" /> )} {/* Results Display Section */} {activeSection === 'results-display' && ( Control how search results are presented and what information is shown. handleSettingChange('includeSnippets', e.target.checked)} /> } label="Show Text Snippets" /> Snippet Length Results Per Page )} {/* Content Sources Section */} {activeSection === 'content-sources' && ( Choose which parts of your documents to include in search. Search In: handleSettingChange('includeFileContent', e.target.checked)} /> } label="Document Content" /> handleSettingChange('includeOcrText', e.target.checked)} /> } label="OCR Extracted Text" /> handleSettingChange('includeFilenames', e.target.checked)} /> } label="Filenames" /> )} {/* Performance Section */} {activeSection === 'performance' && ( These settings can affect search speed. Use with caution for large document collections. Maximum Results: {settings.resultLimit} handleSettingChange('resultLimit', value as number)} min={10} max={500} step={10} marks={[ { value: 25, label: '25' }, { value: 100, label: '100' }, { value: 250, label: '250' }, { value: 500, label: '500' }, ]} valueLabelDisplay="auto" /> Higher values may slow down search for large collections )} {/* Action Buttons */} {availablePresets.length > 0 && ( Load Preset )} {/* Save Preset Dialog */} Save Current Settings as Preset setPresetName(e.target.value)} fullWidth /> ); }; export default AdvancedSearchPanel;