Skip to content

Commit

Permalink
implements upsert document
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen committed Nov 29, 2020
1 parent 1033051 commit 06dda53
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- [x] Create collection
- [x] Create document
- [ ] Upsert document
- [x] Upsert document
- [ ] Update document
- [ ] Bulk documents
- [x] Search collection
Expand Down Expand Up @@ -62,7 +62,6 @@ await typesenseClient.CreateCollection(schema);
## Index document

``` c#

var address = new Address
{
Id = 1,
Expand All @@ -73,6 +72,19 @@ var address = new Address
await typesenseClient.CreateDocument("Addresses", address);
```

## Upsert document

``` c#
var address = new Address
{
Id = 1,
HouseNumber = 2,
AccessAddress = "Smedgade 25B"
};

await typesenseClient.UpsertDocument("Addresses", address);
```

## Search document in collection

``` c#
Expand Down
3 changes: 3 additions & 0 deletions examples/Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ async static Task Main(string[] args)
await typesenseClient.CreateDocument("Addresses", houseThree);
await typesenseClient.CreateDocument("Addresses", houseFour);

await typesenseClient.UpsertDocument("Addresses", houseOne);
await typesenseClient.UpsertDocument("Addresses", houseTwo);

var query = new SearchParameters
{
Text = "Smed",
Expand Down
5 changes: 5 additions & 0 deletions src/Typesense/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public async Task CreateDocument(string schema, object document)
await Post($"/collections/{schema}/documents", document);
}

public async Task UpsertDocument(string collection, object document)
{
await Post($"/collections/{collection}/documents?action=upsert", document);
}

public async Task<SearchResult<T>> Search<T>(string schema, SearchParameters searchParameters)
{
var parameters = CreateUrlSearchParameters(searchParameters);
Expand Down
1 change: 1 addition & 0 deletions src/Typesense/ITypesenseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface ITypesenseClient
{
Task CreateCollection(Schema schema);
Task CreateDocument(string schema, object document);
Task UpsertDocument(string collection, object document);
Task<SearchResult<T>> Search<T>(string schema, SearchParameters searchParameters);
Task<T> RetrieveDocument<T>(string collection, string id);
Task<Collection> RetrieveCollection(string schema);
Expand Down

0 comments on commit 06dda53

Please sign in to comment.