From ab9a161e95da614f1a85cc299bd8b71baa823a17 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:39:51 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48f128b0..9ffaf954 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ Since Meilisearch is typo-tolerant, the movie `philadelphia` is a valid search r ## 🤖 Compatibility with Meilisearch -This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0). +This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0). ## 💡 Learn More From fee970b8dcbd7ad7e1c099095be7bbafd1fcd62e Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 21:24:18 +0200 Subject: [PATCH 2/7] Update Scripts/run-test.sh --- Scripts/run-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/run-test.sh b/Scripts/run-test.sh index 0a73d228..388a50b2 100755 --- a/Scripts/run-test.sh +++ b/Scripts/run-test.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker run -d --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key=masterKey +docker run -d --rm -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey swift test From aebf9db2488fe9df4f417adfcb1278004cce2138 Mon Sep 17 00:00:00 2001 From: cvermand <33010418+bidoubiwa@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:51:56 +0200 Subject: [PATCH 3/7] Fix tests dependent on a specific return order for the documents (#285) * Fix tests dependent on a specific return order for the documents --- Tests/MeiliSearchIntegrationTests/DocumentsTests.swift | 4 ++-- Tests/MeiliSearchIntegrationTests/SearchTests.swift | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift b/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift index 6e860310..58406f78 100755 --- a/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift +++ b/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift @@ -148,8 +148,8 @@ class DocumentsTests: XCTestCase { case .success(let returnedMovies): let returnedMovie = returnedMovies[0] XCTAssertEqual(returnedMovies.count, 1) - XCTAssertEqual(returnedMovie.id, 123) - XCTAssertEqual(returnedMovie.title, "Pride and Prejudice") + XCTAssertEqual(returnedMovie.id, 456) + XCTAssertEqual(returnedMovie.title, "Le Petit Prince") XCTAssertEqual(returnedMovie.comment, nil) expectation.fulfill() case .failure: diff --git a/Tests/MeiliSearchIntegrationTests/SearchTests.swift b/Tests/MeiliSearchIntegrationTests/SearchTests.swift index 23613b8d..dd1d56ce 100644 --- a/Tests/MeiliSearchIntegrationTests/SearchTests.swift +++ b/Tests/MeiliSearchIntegrationTests/SearchTests.swift @@ -87,7 +87,7 @@ class SearchTests: XCTestCase { XCTAssertEqual("", response.query) XCTAssertEqual(20, response.limit) XCTAssertEqual(books.count, response.hits.count) - XCTAssertEqual("Alice In Wonderland", response.hits[0].title) + XCTAssertEqual("Pride and Prejudice", response.hits[0].title) expectation.fulfill() case .failure(let error): dump(error) @@ -757,7 +757,6 @@ class SearchTests: XCTestCase { XCTAssertEqual(documents.query, query) XCTAssertEqual(documents.limit, limit) XCTAssertEqual(documents.hits.count, 0) - let facetsDistribution = documents.facetsDistribution! XCTAssertEqual(["genres": [:]], facetsDistribution) From 4b39f3fee30998445b8d1a3639f44cedf938db59 Mon Sep 17 00:00:00 2001 From: cvermand <33010418+bidoubiwa@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:57:50 +0200 Subject: [PATCH 4/7] Fix failing cropping tests (#286) --- Tests/MeiliSearchIntegrationTests/SearchTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/MeiliSearchIntegrationTests/SearchTests.swift b/Tests/MeiliSearchIntegrationTests/SearchTests.swift index dd1d56ce..ab316f80 100644 --- a/Tests/MeiliSearchIntegrationTests/SearchTests.swift +++ b/Tests/MeiliSearchIntegrationTests/SearchTests.swift @@ -326,7 +326,7 @@ class SearchTests: XCTestCase { XCTAssertEqual(documents.limit, limit) XCTAssertEqual(documents.hits.count, 1) let book: Book = documents.hits[0] - XCTAssertEqual("Manuel de Macedo", book.formatted!.comment!) + XCTAssertEqual("…Joaquim Manuel de Macedo", book.formatted!.comment!) expectation.fulfill() case .failure(let error): print(error) @@ -357,7 +357,7 @@ class SearchTests: XCTestCase { XCTAssertEqual(documents.hits.count, 2) let moreninhaBook: Book = documents.hits.first(where: { book in book.id == 1844 })! - XCTAssertEqual("A Book from", moreninhaBook.formatted!.comment!) + XCTAssertEqual("A Book from Joaquim Manuel…", moreninhaBook.formatted!.comment!) expectation.fulfill() case .failure(let error): dump(error) From b17e641685859b239e82bf2107923e285b5f5c26 Mon Sep 17 00:00:00 2001 From: cvermand <33010418+bidoubiwa@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:39:42 +0200 Subject: [PATCH 5/7] Update code samples for v0.27 (#289) * Update code samples for v0.27 * Fix attributes to crop type in code samples --- .code-samples.meilisearch.yaml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 2d4bd1af..3aafbc1f 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -719,8 +719,21 @@ search_parameter_guide_retrieve_1: |- search_parameter_guide_crop_1: |- let searchParameters = SearchParameters( query: "shifu", - attributesToCrop: "overview", - cropLength: 10) + attributesToCrop: ["overview"], + cropLength: 5) + client.index("movies").search(searchParameters) { (result: Result, Swift.Error>) in + switch result { + case .success(let searchResult): + print(searchResult) + case .failure(let error): + print(error) + } + } +search_parameter_guide_crop_marker_1: |- + let searchParameters = SearchParameters( + query: "shifu", + attributesToCrop: ["overview"], + cropMarker: "[…]") client.index("movies").search(searchParameters) { (result: Result, Swift.Error>) in switch result { case .success(let searchResult): @@ -741,6 +754,20 @@ search_parameter_guide_highlight_1: |- print(error) } } +search_parameter_guide_highlight_tag_1: |- + let searchParameters = SearchParameters( + query: "winter feast", + attributesToHighlight: ["overview"], + highlightPreTag: "", + highlightPostTag: "") + client.index("movies").search(searchParameters) { (result: Result, Swift.Error>) in + switch result { + case .success(let searchResult): + print(searchResult) + case .failure(let error): + print(error) + } + } search_parameter_guide_matches_1: |- let searchParameters = SearchParameters( query: "winter feast", From c4f10bfdfb1d5965426e43c3a091e5fc39ae1d8c Mon Sep 17 00:00:00 2001 From: cvermand <33010418+bidoubiwa@users.noreply.github.com> Date: Wed, 4 May 2022 12:17:47 +0200 Subject: [PATCH 6/7] Add new search parameters highlightPreTag, highlightPostTag and cropMarker (#288) --- .../MeiliSearch/Model/SearchParameters.swift | 18 ++++++ .../SearchTests.swift | 56 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/Sources/MeiliSearch/Model/SearchParameters.swift b/Sources/MeiliSearch/Model/SearchParameters.swift index 227e2e03..e8585740 100644 --- a/Sources/MeiliSearch/Model/SearchParameters.swift +++ b/Sources/MeiliSearch/Model/SearchParameters.swift @@ -26,9 +26,18 @@ public struct SearchParameters: Codable, Equatable { /// Limit length at which to crop specified attributes. public let cropLength: Int? + /// Marker in front and behind a cropped value. + public let cropMarker: String? + /// Which attributes to highlight. public let attributesToHighlight: [String]? + /// Tag in front of highlighted term(s). + public let highlightPreTag: String? + + /// Tag at the end of highlighted term(s). + public let highlightPostTag: String? + /// Filter on attributes values. public let filter: String? @@ -50,7 +59,10 @@ public struct SearchParameters: Codable, Equatable { attributesToRetrieve: [String]? = nil, attributesToCrop: [String]? = nil, cropLength: Int? = nil, + cropMarker: String? = nil, attributesToHighlight: [String]? = nil, + highlightPreTag: String? = nil, + highlightPostTag: String? = nil, filter: String? = nil, sort: [String]? = nil, facetsDistribution: [String]? = nil, @@ -61,7 +73,10 @@ public struct SearchParameters: Codable, Equatable { self.attributesToRetrieve = attributesToRetrieve self.attributesToCrop = attributesToCrop self.cropLength = cropLength + self.cropMarker = cropMarker self.attributesToHighlight = attributesToHighlight + self.highlightPreTag = highlightPreTag + self.highlightPostTag = highlightPostTag self.filter = filter self.sort = sort self.facetsDistribution = facetsDistribution @@ -89,7 +104,10 @@ public struct SearchParameters: Codable, Equatable { case attributesToRetrieve case attributesToCrop case cropLength + case cropMarker case attributesToHighlight + case highlightPreTag + case highlightPostTag case filter case sort case facetsDistribution diff --git a/Tests/MeiliSearchIntegrationTests/SearchTests.swift b/Tests/MeiliSearchIntegrationTests/SearchTests.swift index ab316f80..39693015 100644 --- a/Tests/MeiliSearchIntegrationTests/SearchTests.swift +++ b/Tests/MeiliSearchIntegrationTests/SearchTests.swift @@ -338,6 +338,34 @@ class SearchTests: XCTestCase { self.wait(for: [expectation], timeout: TESTS_TIME_OUT) } + // MARK: Crop Marker + + func testSearchCropMarker() { + let expectation = XCTestExpectation(description: "Search for Books with a custom crop marker") + + typealias MeiliResult = Result, Swift.Error> + let query = "Manuel" + let attributesToCrop = ["comment"] + let cropLength = 2 + let cropMarker = "(ꈍᴗꈍ)" + let searchParameters = SearchParameters(query: query, attributesToCrop: attributesToCrop, cropLength: cropLength, cropMarker: cropMarker) + + self.index.search(searchParameters) { (result: MeiliResult) in + switch result { + case .success(let documents): + let book: Book = documents.hits[0] + XCTAssertEqual("(ꈍᴗꈍ)Joaquim Manuel(ꈍᴗꈍ)", book.formatted!.comment!) + expectation.fulfill() + case .failure(let error): + print(error) + XCTFail("Failed to search with a custom crop marker") + expectation.fulfill() + } + } + + self.wait(for: [expectation], timeout: TESTS_TIME_OUT) + } + // MARK: Crop length func testSearchCropLength() { @@ -438,6 +466,34 @@ class SearchTests: XCTestCase { self.wait(for: [expectation], timeout: TESTS_TIME_OUT) } + // MARK: Attributes to highlight + + func testSearchPrePostHighlightTags() { + let expectation = XCTestExpectation(description: "Search for Books using custom pre and post highlight tags") + + typealias MeiliResult = Result, Swift.Error> + let query = "Joaquim Manuel de Macedo" + let attributesToHighlight = ["comment"] + let highlightPreTag = "(⊃。•́‿•̀。)⊃ " + let highlightPostTag = " ⊂(´• ω •`⊂)" + let parameters = SearchParameters(query: query, attributesToHighlight: attributesToHighlight, highlightPreTag: highlightPreTag, highlightPostTag: highlightPostTag) + + self.index.search(parameters) { (result: MeiliResult) in + switch result { + case .success(let documents): + let book = documents.hits[0] + XCTAssertTrue(book.formatted!.comment!.contains("(⊃。•́‿•̀。)⊃ Joaquim ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ Manuel ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ de ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ Macedo ⊂(´• ω •`⊂)")) + expectation.fulfill() + case .failure(let error): + dump(error) + XCTFail("Failed to search using custom pre and post highlight tags") + expectation.fulfill() + } + } + + self.wait(for: [expectation], timeout: TESTS_TIME_OUT) + } + // MARK: Attributes to retrieve func testSearchAttributesToRetrieve() { From 732ea78d65a1c4fd7173e60a11c8290dfcf45136 Mon Sep 17 00:00:00 2001 From: cvermand <33010418+bidoubiwa@users.noreply.github.com> Date: Wed, 4 May 2022 17:29:22 +0200 Subject: [PATCH 7/7] Ensure nested field support (#287) * Ensure nested field support * Remove dumps * Resolve linting issues --- .../SearchTests.swift | 56 +++++++++++++++++-- .../Support/NestedBook.swift | 40 +++++++++++++ 2 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 Tests/MeiliSearchIntegrationTests/Support/NestedBook.swift diff --git a/Tests/MeiliSearchIntegrationTests/SearchTests.swift b/Tests/MeiliSearchIntegrationTests/SearchTests.swift index 39693015..72423b27 100644 --- a/Tests/MeiliSearchIntegrationTests/SearchTests.swift +++ b/Tests/MeiliSearchIntegrationTests/SearchTests.swift @@ -2,8 +2,6 @@ import XCTest import Foundation -// swiftlint:disable force_unwrapping -// swiftlint:disable force_try private let books: [Book] = [ Book(id: 123, title: "Pride and Prejudice", comment: "A great book", genres: ["Classic Regency nove"]), Book(id: 456, title: "Le Petit Prince", comment: "A french book", genres: ["Novel"]), @@ -15,20 +13,31 @@ private let books: [Book] = [ Book(id: 1844, title: "A Moreninha", comment: "A Book from Joaquim Manuel de Macedo", genres: ["Novel"]) ] +// swiftlint:disable force_unwrapping +// swiftlint:disable force_try +private let nestedBooks: [NestedBook] = [ + NestedBook(id: 123, title: "Pride and Prejudice", info: InfoNested(comment: "A great book", reviewNb: 100), genres: ["Classic Regency nove"]), + NestedBook(id: 456, title: "Le Petit Prince", info: InfoNested(comment: "A french book", reviewNb: 100), genres: ["Novel"]), + NestedBook(id: 2, title: "Le Rouge et le Noir", info: InfoNested(comment: "Another french book", reviewNb: 100), genres: ["Bildungsroman"]) +] + class SearchTests: XCTestCase { private var client: MeiliSearch! private var index: Indexes! + private var nestedIndex: Indexes! private var session: URLSessionProtocol! private let uid: String = "books_test" + private let nested_uid: String = "nested_books_test" // MARK: Setup override func setUp() { super.setUp() - session = URLSession(configuration: .ephemeral) - client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session) + session = URLSession(configuration: .ephemeral) + client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session) index = self.client.index(self.uid) + nestedIndex = self.client.index(self.nested_uid) let addDocExpectation = XCTestExpectation(description: "Add documents") @@ -43,10 +52,21 @@ class SearchTests: XCTestCase { } } self.wait(for: [addDocExpectation], timeout: TESTS_TIME_OUT) + let addNestedDocExpectation = XCTestExpectation(description: "Add documents") + addDocuments(client: self.client, uid: self.nested_uid, dataset: nestedBooks, primaryKey: nil) { result in + switch result { + case .success: + addNestedDocExpectation.fulfill() + case .failure(let error): + dump(error) + XCTFail("Failed to create index") + addNestedDocExpectation.fulfill() + } + } + self.wait(for: [addNestedDocExpectation], timeout: TESTS_TIME_OUT) } // MARK: Basic search - func testBasicSearch() { let expectation = XCTestExpectation(description: "Search for Books with query") @@ -76,6 +96,32 @@ class SearchTests: XCTestCase { self.wait(for: [expectation], timeout: TESTS_TIME_OUT) } + // MARK: Nested search + func testNestedSearch() { + let expectation = XCTestExpectation(description: "Search in Nested Books") + + typealias MeiliResult = Result, Swift.Error> + let query = "A french book" + + self.nestedIndex.search(SearchParameters(query: query)) { (result: MeiliResult) in + switch result { + case .success(let response): + if response.hits.count > 0 { + XCTAssertEqual("A french book", response.hits[0].info.comment) + } else { + XCTFail("Failed to find hits in the response") + } + expectation.fulfill() + case .failure(let error): + dump(error) + XCTFail("Failed to search in nested books") + expectation.fulfill() + } + } + + self.wait(for: [expectation], timeout: TESTS_TIME_OUT) + } + func testBasicSearchWithNoQuery() { let expectation = XCTestExpectation(description: "Search for Books without query") diff --git a/Tests/MeiliSearchIntegrationTests/Support/NestedBook.swift b/Tests/MeiliSearchIntegrationTests/Support/NestedBook.swift new file mode 100644 index 00000000..3c22dafd --- /dev/null +++ b/Tests/MeiliSearchIntegrationTests/Support/NestedBook.swift @@ -0,0 +1,40 @@ +public struct NestedBook: Codable, Equatable { + let id: Int + let title: String + let info: InfoNested + let genres: [String]? + let formatted: FormattedNestedBook? + + enum CodingKeys: String, CodingKey { + case id + case title + case info + case genres + case formatted = "_formatted" + } + + init(id: Int, title: String, info: InfoNested, genres: [String] = [], formatted: FormattedNestedBook? = nil) { + self.id = id + self.title = title + self.info = info + self.genres = genres + self.formatted = formatted + } +} + +public struct InfoNested: Codable, Equatable { + let comment: String + let reviewNb: Int +} + +public struct FormattedNestedBook: Codable, Equatable { + let id: String + let title: String + let info: InfoNested + + init(id: String, title: String, info: InfoNested) { + self.id = id + self.title = title + self.info = info + } +}