You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-31Lines changed: 30 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ A great new way to implement your searches on iOS using [Typesense](https://gith
7
7
Add `Typesense Swift` Swift Package to your project. You can refer [Apple's Documentation](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) to add Typesense Swift as a dependency to your iOS Project. You can also import Typesense into your own Swift Package by adding this line to dependencies array of `Package.swift`:
@@ -21,55 +21,54 @@ Add `Typesense Swift` Swift Package to your project. You can refer [Apple's Docu
21
21
Import Typesense onto your Swift Project:
22
22
23
23
```swift
24
-
import Typesense
24
+
import Typesense
25
25
```
26
26
27
27
Declare the Typesense nodes that are available as `Node` members:
28
28
29
29
```swift
30
-
let node1 =Node(host: "localhost", port: "8108", nodeProtocol: "http")
31
-
let node2 =Node(host: "super-awesome.search", port: "8080", nodeProtocol: "https") //and so on
30
+
let node1 =Node(host: "localhost", port: "8108", nodeProtocol: "http")
31
+
let node2 =Node(host: "super-awesome.search", port: "8080", nodeProtocol: "https") //and so on
32
32
```
33
33
34
34
Create a configuration and hence a client with the Nodes mentioned:
35
35
36
36
```swift
37
-
let myConfig =Configuration(nodes: [node1, node2], apiKey: "coolstuff")
38
-
39
-
let client =Client(config: myConfig)
37
+
let myConfig =Configuration(nodes: [node1, node2], apiKey: "coolstuff")
38
+
39
+
let client =Client(config: myConfig)
40
40
```
41
41
You can use Typesense parameters like `nearestNode` and `connectionTimeoutSeconds` while creating the configuration. You can also pass in a `logger` parameter to debug the code like this:
42
42
43
43
```swift
44
-
let myConfig =Configuration(nodes: [node1, node2], apiKey: "coolstuff", logger: Logger(debugMode: true))
44
+
let myConfig =Configuration(nodes: [node1, node2], apiKey: "coolstuff", logger: Logger(debugMode: true))
45
45
```
46
46
47
47
### Indexing documents
48
48
49
49
You can create a collection by first defining a collection schema:
let documentData =tryJSONEncoder().encode(document)
69
+
let (data, response) =tryawait client.collection(name: "schools").documents().create(document: documentData)
70
+
//or
71
+
let (data, response) =tryawait client.collection(name: "schools").documents().upsert(document: documentData)
73
72
```
74
73
You can perform CRUD actions to `Collections` and `Documents` that belong to a certain collection. You can also use `.importBatch()` on the `documents()` method to import and index a batch ofdocuments (in .jsonl format).
75
74
@@ -78,9 +77,9 @@ You can perform CRUD actions to `Collections` and `Documents` that belong to a c
78
77
Define your [search parameters](https://typesense.org/docs/0.22.1/api/documents.html#arguments) clearly and then perform the search operation by mentioning your Document Type:
79
78
80
79
```swift
81
-
let searchParameters =SearchParameters(q: "hog", queryBy: "school_name", filterBy: "num_students:>500", sortBy: "num_students:desc")
82
-
83
-
let (data, response) =tryawait client.collection(name: "schools").documents().search(searchParameters, for: School.self)
80
+
let searchParameters =SearchParameters(q: "hog", queryBy: "school_name", filterBy: "num_students:>500", sortBy: "num_students:desc")
81
+
82
+
let (data, response) =tryawait client.collection(name: "schools").documents().search(searchParameters, for: School.self)
84
83
```
85
84
This returns a `SearchResult` object as the data, which can be further parsed as desired.
86
85
@@ -89,7 +88,7 @@ This returns a `SearchResult` object as the data, which can be further parsed as
89
88
Issues and pull requests are welcome on GitHub at [Typesense Swift](https://github.com/typesense/typesense-swift). Do note that the Models used in the Swift client are generated by [Swagger-Codegen](https://github.com/swagger-api/swagger-codegen) and are automated to be modified in order to prevent major errors. So please do use the shell script that is provided in the repo to generate the models:
90
89
91
90
```shell
92
-
sh get-models.sh
91
+
sh get-models.sh
93
92
```
94
93
95
94
The generated Models (inside the Models directory) are to be used inside the Models directory of the source code as well. Models need to be generated as and when the [Typesense-Api-Spec](https://github.com/typesense/typesense-api-spec) is updated.
0 commit comments