(
query: string,
limit: number = 5,
filters?: SearchFilters,
options: SearchOptions = DEFAULT_SEARCH_OPTIONS
)
| 914 | } |
| 915 | |
| 916 | async search( |
| 917 | query: string, |
| 918 | limit: number = 5, |
| 919 | filters?: SearchFilters, |
| 920 | options: SearchOptions = DEFAULT_SEARCH_OPTIONS |
| 921 | ): Promise<SearchResult[]> { |
| 922 | if (!this.initialized) { |
| 923 | await this.initialize(); |
| 924 | } |
| 925 | |
| 926 | const merged = { |
| 927 | ...DEFAULT_SEARCH_OPTIONS, |
| 928 | ...options |
| 929 | }; |
| 930 | const { |
| 931 | useSemanticSearch, |
| 932 | useKeywordSearch, |
| 933 | profile, |
| 934 | enableQueryExpansion, |
| 935 | enableLowConfidenceRescue, |
| 936 | candidateFloor, |
| 937 | enableReranker |
| 938 | } = merged; |
| 939 | |
| 940 | const { intent, weights: intentWeights } = this.classifyQueryIntent(query); |
| 941 | // Intent weights are the default; caller-supplied weights override them |
| 942 | const finalSemanticWeight = merged.semanticWeight ?? intentWeights.semantic; |
| 943 | const finalKeywordWeight = merged.keywordWeight ?? intentWeights.keyword; |
| 944 | |
| 945 | const candidateLimit = Math.max(limit * 2, candidateFloor || 30); |
| 946 | const primaryVariants = this.buildQueryVariants(query, enableQueryExpansion ? 1 : 0); |
| 947 | |
| 948 | const primaryMatches = await this.collectHybridMatches( |
| 949 | primaryVariants, |
| 950 | candidateLimit, |
| 951 | filters, |
| 952 | Boolean(useSemanticSearch), |
| 953 | Boolean(useKeywordSearch), |
| 954 | finalSemanticWeight, |
| 955 | finalKeywordWeight |
| 956 | ); |
| 957 | |
| 958 | const primaryTotalWeight = |
| 959 | primaryVariants.reduce((sum, v) => sum + v.weight, 0) * |
| 960 | (finalSemanticWeight + finalKeywordWeight); |
| 961 | const primaryResults = this.scoreAndSortResults( |
| 962 | query, |
| 963 | limit, |
| 964 | primaryMatches, |
| 965 | (profile || 'explore') as SearchIntentProfile, |
| 966 | intent, |
| 967 | primaryTotalWeight |
| 968 | ); |
| 969 | |
| 970 | let bestResults = primaryResults; |
| 971 | |
| 972 | if (enableLowConfidenceRescue) { |
| 973 | const primaryQuality = assessSearchQuality(query, primaryResults); |
no test coverage detected