Skip to content

Commit ae8011d

Browse files
authored
Remove indenting in README code snippets
1 parent 3a83fe3 commit ae8011d

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

README.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ A great new way to implement your searches on iOS using [Typesense](https://gith
77
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`:
88

99
```swift
10-
...
11-
dependencies: [
12-
.package(url: "https://github.com/typesense/typesense-swift", .upToNextMajor(from: "0.1.0"),
13-
],
14-
...
10+
...
11+
dependencies: [
12+
.package(url: "https://github.com/typesense/typesense-swift", .upToNextMajor(from: "0.1.0"),
13+
],
14+
...
1515
```
1616

1717
## Usage
@@ -21,55 +21,54 @@ Add `Typesense Swift` Swift Package to your project. You can refer [Apple's Docu
2121
Import Typesense onto your Swift Project:
2222

2323
```swift
24-
import Typesense
24+
import Typesense
2525
```
2626

2727
Declare the Typesense nodes that are available as `Node` members:
2828

2929
```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
3232
```
3333

3434
Create a configuration and hence a client with the Nodes mentioned:
3535

3636
```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)
4040
```
4141
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:
4242

4343
```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))
4545
```
4646

4747
### Indexing documents
4848

4949
You can create a collection by first defining a collection schema:
5050

5151
```swift
52-
let myCoolSchema = CollectionSchema(name: "schools", fields: [Field(name: "school_name", type: "string"), Field(name: "num_students", type: "int32"), Field(name: "country", type: "string", facet: true)], defaultSortingField: "num_students")
52+
let myCoolSchema = CollectionSchema(name: "schools", fields: [Field(name: "school_name", type: "string"), Field(name: "num_students", type: "int32"), Field(name: "country", type: "string", facet: true)], defaultSortingField: "num_students")
5353

54-
let (data, response) = try await client.collections.create(schema: myCoolSchema)
54+
let (data, response) = try await client.collections.create(schema: myCoolSchema)
5555
```
5656

5757
Define the structure of your document as per your collection, and index it by inserting/upserting it to the collection:
5858

5959
```swift
60-
struct School: Codable {
61-
var id: String
62-
var school_name: String
63-
var num_students: Int
64-
var country: String
65-
}
66-
67-
let document = School(id: "7", school_name: "Hogwarts", num_students: 600, country: "United Kingdom")
68-
let documentData = try JSONEncoder().encode(document)
69-
let (data, response) = try await client.collection(name: "schools").documents().create(document: documentData)
70-
//or
71-
let (data, response) = try await client.collection(name: "schools").documents().upsert(document: documentData)
72-
60+
struct School: Codable {
61+
var id: String
62+
var school_name: String
63+
var num_students: Int
64+
var country: String
65+
}
66+
67+
let document = School(id: "7", school_name: "Hogwarts", num_students: 600, country: "United Kingdom")
68+
let documentData = try JSONEncoder().encode(document)
69+
let (data, response) = try await client.collection(name: "schools").documents().create(document: documentData)
70+
//or
71+
let (data, response) = try await client.collection(name: "schools").documents().upsert(document: documentData)
7372
```
7473
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 of documents (in .jsonl format).
7574

@@ -78,9 +77,9 @@ You can perform CRUD actions to `Collections` and `Documents` that belong to a c
7877
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:
7978

8079
```swift
81-
let searchParameters = SearchParameters(q: "hog", queryBy: "school_name", filterBy: "num_students:>500", sortBy: "num_students:desc")
82-
83-
let (data, response) = try await 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) = try await client.collection(name: "schools").documents().search(searchParameters, for: School.self)
8483
```
8584
This returns a `SearchResult` object as the data, which can be further parsed as desired.
8685

@@ -89,7 +88,7 @@ This returns a `SearchResult` object as the data, which can be further parsed as
8988
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:
9089

9190
```shell
92-
sh get-models.sh
91+
sh get-models.sh
9392
```
9493

9594
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

Comments
 (0)