Skip to content

Commit 96ab828

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #280
280: Changes related to the next Meilisearch release (v0.27.0) r=curquiza a=meili-bot Related to this issue: meilisearch/integration-guides#190 This PR: - gathers the changes related to the next Meilisearch release (v0.27.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v0.27.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.27.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents f4ad485 + 732ea78 commit 96ab828

File tree

7 files changed

+201
-15
lines changed

7 files changed

+201
-15
lines changed

.code-samples.meilisearch.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,21 @@ search_parameter_guide_retrieve_1: |-
719719
search_parameter_guide_crop_1: |-
720720
let searchParameters = SearchParameters(
721721
query: "shifu",
722-
attributesToCrop: "overview",
723-
cropLength: 10)
722+
attributesToCrop: ["overview"],
723+
cropLength: 5)
724+
client.index("movies").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
725+
switch result {
726+
case .success(let searchResult):
727+
print(searchResult)
728+
case .failure(let error):
729+
print(error)
730+
}
731+
}
732+
search_parameter_guide_crop_marker_1: |-
733+
let searchParameters = SearchParameters(
734+
query: "shifu",
735+
attributesToCrop: ["overview"],
736+
cropMarker: "[…]")
724737
client.index("movies").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
725738
switch result {
726739
case .success(let searchResult):
@@ -741,6 +754,20 @@ search_parameter_guide_highlight_1: |-
741754
print(error)
742755
}
743756
}
757+
search_parameter_guide_highlight_tag_1: |-
758+
let searchParameters = SearchParameters(
759+
query: "winter feast",
760+
attributesToHighlight: ["overview"],
761+
highlightPreTag: "<span class=\"highlight\">",
762+
highlightPostTag: "</span>")
763+
client.index("movies").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
764+
switch result {
765+
case .success(let searchResult):
766+
print(searchResult)
767+
case .failure(let error):
768+
print(error)
769+
}
770+
}
744771
search_parameter_guide_matches_1: |-
745772
let searchParameters = SearchParameters(
746773
query: "winter feast",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Since Meilisearch is typo-tolerant, the movie `philadelphia` is a valid search r
190190

191191
## 🤖 Compatibility with Meilisearch
192192

193-
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
193+
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
194194

195195
## 💡 Learn More
196196

Scripts/run-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
2-
docker run -d --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key=masterKey
2+
docker run -d --rm -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey
33
swift test

Sources/MeiliSearch/Model/SearchParameters.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ public struct SearchParameters: Codable, Equatable {
2626
/// Limit length at which to crop specified attributes.
2727
public let cropLength: Int?
2828

29+
/// Marker in front and behind a cropped value.
30+
public let cropMarker: String?
31+
2932
/// Which attributes to highlight.
3033
public let attributesToHighlight: [String]?
3134

35+
/// Tag in front of highlighted term(s).
36+
public let highlightPreTag: String?
37+
38+
/// Tag at the end of highlighted term(s).
39+
public let highlightPostTag: String?
40+
3241
/// Filter on attributes values.
3342
public let filter: String?
3443

@@ -50,7 +59,10 @@ public struct SearchParameters: Codable, Equatable {
5059
attributesToRetrieve: [String]? = nil,
5160
attributesToCrop: [String]? = nil,
5261
cropLength: Int? = nil,
62+
cropMarker: String? = nil,
5363
attributesToHighlight: [String]? = nil,
64+
highlightPreTag: String? = nil,
65+
highlightPostTag: String? = nil,
5466
filter: String? = nil,
5567
sort: [String]? = nil,
5668
facetsDistribution: [String]? = nil,
@@ -61,7 +73,10 @@ public struct SearchParameters: Codable, Equatable {
6173
self.attributesToRetrieve = attributesToRetrieve
6274
self.attributesToCrop = attributesToCrop
6375
self.cropLength = cropLength
76+
self.cropMarker = cropMarker
6477
self.attributesToHighlight = attributesToHighlight
78+
self.highlightPreTag = highlightPreTag
79+
self.highlightPostTag = highlightPostTag
6580
self.filter = filter
6681
self.sort = sort
6782
self.facetsDistribution = facetsDistribution
@@ -89,7 +104,10 @@ public struct SearchParameters: Codable, Equatable {
89104
case attributesToRetrieve
90105
case attributesToCrop
91106
case cropLength
107+
case cropMarker
92108
case attributesToHighlight
109+
case highlightPreTag
110+
case highlightPostTag
93111
case filter
94112
case sort
95113
case facetsDistribution

Tests/MeiliSearchIntegrationTests/DocumentsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class DocumentsTests: XCTestCase {
148148
case .success(let returnedMovies):
149149
let returnedMovie = returnedMovies[0]
150150
XCTAssertEqual(returnedMovies.count, 1)
151-
XCTAssertEqual(returnedMovie.id, 123)
152-
XCTAssertEqual(returnedMovie.title, "Pride and Prejudice")
151+
XCTAssertEqual(returnedMovie.id, 456)
152+
XCTAssertEqual(returnedMovie.title, "Le Petit Prince")
153153
XCTAssertEqual(returnedMovie.comment, nil)
154154
expectation.fulfill()
155155
case .failure:

Tests/MeiliSearchIntegrationTests/SearchTests.swift

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import XCTest
33
import Foundation
44

5-
// swiftlint:disable force_unwrapping
6-
// swiftlint:disable force_try
75
private let books: [Book] = [
86
Book(id: 123, title: "Pride and Prejudice", comment: "A great book", genres: ["Classic Regency nove"]),
97
Book(id: 456, title: "Le Petit Prince", comment: "A french book", genres: ["Novel"]),
@@ -15,20 +13,31 @@ private let books: [Book] = [
1513
Book(id: 1844, title: "A Moreninha", comment: "A Book from Joaquim Manuel de Macedo", genres: ["Novel"])
1614
]
1715

16+
// swiftlint:disable force_unwrapping
17+
// swiftlint:disable force_try
18+
private let nestedBooks: [NestedBook] = [
19+
NestedBook(id: 123, title: "Pride and Prejudice", info: InfoNested(comment: "A great book", reviewNb: 100), genres: ["Classic Regency nove"]),
20+
NestedBook(id: 456, title: "Le Petit Prince", info: InfoNested(comment: "A french book", reviewNb: 100), genres: ["Novel"]),
21+
NestedBook(id: 2, title: "Le Rouge et le Noir", info: InfoNested(comment: "Another french book", reviewNb: 100), genres: ["Bildungsroman"])
22+
]
23+
1824
class SearchTests: XCTestCase {
1925
private var client: MeiliSearch!
2026
private var index: Indexes!
27+
private var nestedIndex: Indexes!
2128
private var session: URLSessionProtocol!
2229
private let uid: String = "books_test"
30+
private let nested_uid: String = "nested_books_test"
2331

2432
// MARK: Setup
2533

2634
override func setUp() {
2735
super.setUp()
2836

29-
session = URLSession(configuration: .ephemeral)
30-
client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session)
37+
session = URLSession(configuration: .ephemeral)
38+
client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session)
3139
index = self.client.index(self.uid)
40+
nestedIndex = self.client.index(self.nested_uid)
3241

3342
let addDocExpectation = XCTestExpectation(description: "Add documents")
3443

@@ -43,10 +52,21 @@ class SearchTests: XCTestCase {
4352
}
4453
}
4554
self.wait(for: [addDocExpectation], timeout: TESTS_TIME_OUT)
55+
let addNestedDocExpectation = XCTestExpectation(description: "Add documents")
56+
addDocuments(client: self.client, uid: self.nested_uid, dataset: nestedBooks, primaryKey: nil) { result in
57+
switch result {
58+
case .success:
59+
addNestedDocExpectation.fulfill()
60+
case .failure(let error):
61+
dump(error)
62+
XCTFail("Failed to create index")
63+
addNestedDocExpectation.fulfill()
64+
}
65+
}
66+
self.wait(for: [addNestedDocExpectation], timeout: TESTS_TIME_OUT)
4667
}
4768

4869
// MARK: Basic search
49-
5070
func testBasicSearch() {
5171
let expectation = XCTestExpectation(description: "Search for Books with query")
5272

@@ -76,6 +96,32 @@ class SearchTests: XCTestCase {
7696
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
7797
}
7898

99+
// MARK: Nested search
100+
func testNestedSearch() {
101+
let expectation = XCTestExpectation(description: "Search in Nested Books")
102+
103+
typealias MeiliResult = Result<SearchResult<NestedBook>, Swift.Error>
104+
let query = "A french book"
105+
106+
self.nestedIndex.search(SearchParameters(query: query)) { (result: MeiliResult) in
107+
switch result {
108+
case .success(let response):
109+
if response.hits.count > 0 {
110+
XCTAssertEqual("A french book", response.hits[0].info.comment)
111+
} else {
112+
XCTFail("Failed to find hits in the response")
113+
}
114+
expectation.fulfill()
115+
case .failure(let error):
116+
dump(error)
117+
XCTFail("Failed to search in nested books")
118+
expectation.fulfill()
119+
}
120+
}
121+
122+
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
123+
}
124+
79125
func testBasicSearchWithNoQuery() {
80126
let expectation = XCTestExpectation(description: "Search for Books without query")
81127

@@ -87,7 +133,7 @@ class SearchTests: XCTestCase {
87133
XCTAssertEqual("", response.query)
88134
XCTAssertEqual(20, response.limit)
89135
XCTAssertEqual(books.count, response.hits.count)
90-
XCTAssertEqual("Alice In Wonderland", response.hits[0].title)
136+
XCTAssertEqual("Pride and Prejudice", response.hits[0].title)
91137
expectation.fulfill()
92138
case .failure(let error):
93139
dump(error)
@@ -326,7 +372,7 @@ class SearchTests: XCTestCase {
326372
XCTAssertEqual(documents.limit, limit)
327373
XCTAssertEqual(documents.hits.count, 1)
328374
let book: Book = documents.hits[0]
329-
XCTAssertEqual("Manuel de Macedo", book.formatted!.comment!)
375+
XCTAssertEqual("…Joaquim Manuel de Macedo", book.formatted!.comment!)
330376
expectation.fulfill()
331377
case .failure(let error):
332378
print(error)
@@ -338,6 +384,34 @@ class SearchTests: XCTestCase {
338384
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
339385
}
340386

387+
// MARK: Crop Marker
388+
389+
func testSearchCropMarker() {
390+
let expectation = XCTestExpectation(description: "Search for Books with a custom crop marker")
391+
392+
typealias MeiliResult = Result<SearchResult<Book>, Swift.Error>
393+
let query = "Manuel"
394+
let attributesToCrop = ["comment"]
395+
let cropLength = 2
396+
let cropMarker = "(ꈍᴗꈍ)"
397+
let searchParameters = SearchParameters(query: query, attributesToCrop: attributesToCrop, cropLength: cropLength, cropMarker: cropMarker)
398+
399+
self.index.search(searchParameters) { (result: MeiliResult) in
400+
switch result {
401+
case .success(let documents):
402+
let book: Book = documents.hits[0]
403+
XCTAssertEqual("(ꈍᴗꈍ)Joaquim Manuel(ꈍᴗꈍ)", book.formatted!.comment!)
404+
expectation.fulfill()
405+
case .failure(let error):
406+
print(error)
407+
XCTFail("Failed to search with a custom crop marker")
408+
expectation.fulfill()
409+
}
410+
}
411+
412+
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
413+
}
414+
341415
// MARK: Crop length
342416

343417
func testSearchCropLength() {
@@ -357,7 +431,7 @@ class SearchTests: XCTestCase {
357431
XCTAssertEqual(documents.hits.count, 2)
358432

359433
let moreninhaBook: Book = documents.hits.first(where: { book in book.id == 1844 })!
360-
XCTAssertEqual("A Book from", moreninhaBook.formatted!.comment!)
434+
XCTAssertEqual("A Book from Joaquim Manuel…", moreninhaBook.formatted!.comment!)
361435
expectation.fulfill()
362436
case .failure(let error):
363437
dump(error)
@@ -438,6 +512,34 @@ class SearchTests: XCTestCase {
438512
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
439513
}
440514

515+
// MARK: Attributes to highlight
516+
517+
func testSearchPrePostHighlightTags() {
518+
let expectation = XCTestExpectation(description: "Search for Books using custom pre and post highlight tags")
519+
520+
typealias MeiliResult = Result<SearchResult<Book>, Swift.Error>
521+
let query = "Joaquim Manuel de Macedo"
522+
let attributesToHighlight = ["comment"]
523+
let highlightPreTag = "(⊃。•́‿•̀。)⊃ "
524+
let highlightPostTag = " ⊂(´• ω •`⊂)"
525+
let parameters = SearchParameters(query: query, attributesToHighlight: attributesToHighlight, highlightPreTag: highlightPreTag, highlightPostTag: highlightPostTag)
526+
527+
self.index.search(parameters) { (result: MeiliResult) in
528+
switch result {
529+
case .success(let documents):
530+
let book = documents.hits[0]
531+
XCTAssertTrue(book.formatted!.comment!.contains("(⊃。•́‿•̀。)⊃ Joaquim ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ Manuel ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ de ⊂(´• ω •`⊂) (⊃。•́‿•̀。)⊃ Macedo ⊂(´• ω •`⊂)"))
532+
expectation.fulfill()
533+
case .failure(let error):
534+
dump(error)
535+
XCTFail("Failed to search using custom pre and post highlight tags")
536+
expectation.fulfill()
537+
}
538+
}
539+
540+
self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
541+
}
542+
441543
// MARK: Attributes to retrieve
442544

443545
func testSearchAttributesToRetrieve() {
@@ -757,7 +859,6 @@ class SearchTests: XCTestCase {
757859
XCTAssertEqual(documents.query, query)
758860
XCTAssertEqual(documents.limit, limit)
759861
XCTAssertEqual(documents.hits.count, 0)
760-
761862
let facetsDistribution = documents.facetsDistribution!
762863
XCTAssertEqual(["genres": [:]], facetsDistribution)
763864

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public struct NestedBook: Codable, Equatable {
2+
let id: Int
3+
let title: String
4+
let info: InfoNested
5+
let genres: [String]?
6+
let formatted: FormattedNestedBook?
7+
8+
enum CodingKeys: String, CodingKey {
9+
case id
10+
case title
11+
case info
12+
case genres
13+
case formatted = "_formatted"
14+
}
15+
16+
init(id: Int, title: String, info: InfoNested, genres: [String] = [], formatted: FormattedNestedBook? = nil) {
17+
self.id = id
18+
self.title = title
19+
self.info = info
20+
self.genres = genres
21+
self.formatted = formatted
22+
}
23+
}
24+
25+
public struct InfoNested: Codable, Equatable {
26+
let comment: String
27+
let reviewNb: Int
28+
}
29+
30+
public struct FormattedNestedBook: Codable, Equatable {
31+
let id: String
32+
let title: String
33+
let info: InfoNested
34+
35+
init(id: String, title: String, info: InfoNested) {
36+
self.id = id
37+
self.title = title
38+
self.info = info
39+
}
40+
}

0 commit comments

Comments
 (0)