Skip to content

Commit ffaa852

Browse files
authored
[Collections] Change package search query to allow substring search (#3808)
Motivation: The current FTS query uses `MATCH`, which matches by whole words only. This seems to be narrow the results too much. e.g., searching for 'proto' or 'num' in the Apple package collection returns nothing. Modification: Change query to use `LIKE` instead so it searches by substring. rdar://84218640
1 parent ef59ec2 commit ffaa852

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
301301
var matchingCollections = Set<Model.CollectionIdentifier>()
302302

303303
do {
304-
let packageQuery = "SELECT collection_id_blob_base64, repository_url FROM \(Self.packagesFTSName) WHERE \(Self.packagesFTSName) MATCH ?;"
304+
// rdar://84218640
305+
//let packageQuery = "SELECT collection_id_blob_base64, repository_url FROM \(Self.packagesFTSName) WHERE \(Self.packagesFTSName) MATCH ?;"
306+
let packageQuery = "SELECT collection_id_blob_base64, repository_url FROM \(Self.packagesFTSName) WHERE name LIKE ? OR summary LIKE ? OR keywords LIKE ? OR products LIKE ? OR targets LIKE ? OR repository_url LIKE ?;"
305307
try self.executeStatement(packageQuery) { statement in
306-
try statement.bind([.string(query)])
308+
try statement.bind((1...6).map { _ in .string("%\(query)%") })
307309

308310
while let row = try statement.step() {
309311
if let collectionData = Data(base64Encoded: row.string(at: 0)),

0 commit comments

Comments
 (0)