Skip to content

Commit 0d37a5a

Browse files
authored
Merge pull request #13 from Chamepp/main
refact: improving the SearchAlgorithmSelector selection logic for scalability
2 parents c4ef01c + 29d98be commit 0d37a5a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Sources/SearchMind/Internal/SearchEngine.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,38 @@ public final class DefaultSearchEngine: SearchEngine {
6161
/// Selects the most appropriate search algorithm based on inputs
6262
final class SearchAlgorithmSelector: Sendable {
6363
func selectAlgorithm(for _: String, type: SearchType, options: SearchOptions) -> SearchAlgorithm {
64-
// For simple name searches without fuzzy matching, use exact matching
65-
if type == .file, !options.fuzzyMatching {
66-
return ExactMatchAlgorithm()
64+
switch type {
65+
case .file:
66+
return selectFileAlgorithm(options: options)
67+
case .fileContents:
68+
return selectFileContentsAlgorithm(options: options)
6769
}
70+
}
6871

69-
// For fuzzy file name searches, use fuzzy matching
70-
if type == .file, options.fuzzyMatching {
72+
private func selectFileAlgorithm(options: SearchOptions) -> SearchAlgorithm {
73+
if options.semantic {
74+
return GPTSemanticSearchAlgorithm()
75+
}
76+
if options.fuzzyMatching {
7177
return FuzzyMatchAlgorithm()
7278
}
73-
74-
// For content searches, use pattern matching
75-
if type == .fileContents, options.patternMatch {
79+
if options.patternMatch {
7680
return PatternMatchAlgorithm()
7781
}
82+
return ExactMatchAlgorithm()
83+
}
7884

79-
if type == .fileContents, options.semantic {
85+
private func selectFileContentsAlgorithm(options: SearchOptions) -> SearchAlgorithm {
86+
if options.semantic {
8087
return GPTSemanticSearchAlgorithm()
8188
}
82-
83-
// Default to fuzzy matching
84-
return FuzzyMatchAlgorithm()
89+
if options.patternMatch {
90+
return PatternMatchAlgorithm()
91+
}
92+
if options.fuzzyMatching {
93+
return FuzzyMatchAlgorithm()
94+
}
95+
return ExactMatchAlgorithm()
8596
}
8697
}
8798

0 commit comments

Comments
 (0)