Skip to content

Commit

Permalink
all routes convered; add search example in readme; let's do a v0.0.3-a
Browse files Browse the repository at this point in the history
  • Loading branch information
ndudnicz committed Jun 2, 2020
1 parent 2acb7c0 commit ecc5da8
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 10 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
## 🔧 Installation
It's available as NuGet package :
```bash
dotnet add package MeilisearchDotnet --version 0.0.2-a
dotnet add package MeilisearchDotnet --version 0.0.3-a
```
[https://www.nuget.org/packages/MeilisearchDotnet](https://www.nuget.org/packages/MeilisearchDotnet)

Expand Down Expand Up @@ -110,6 +110,20 @@ namespace console
}
```

#### Search in index

```csharp
// MeiliSearch is typo-tolerant:
MeilisearchDotnet.Types.SearchResponse<Doc> result = await index.Search<Doc>("tpyaet");
// result => {
// "Hits": [{"key1": 222,"value": "tpayet"}],
// "Offset": 0,
// "Limit": 20,
// "ProcessingTimeMs": 1,
// "Query": "tpyaet"
// }
```

## ⚙️ Development Workflow

If you want to contribute, this sections describes the steps to follow.
Expand Down
115 changes: 110 additions & 5 deletions src/MeilisearchDotnet/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ string IndexUid
MeilisearchDotnet.Types.SearchRequest options = null
)
{
// TODO
string url = null;

if (options != null)
Expand All @@ -88,11 +87,20 @@ string IndexUid
{
url = "/indexes/" + Uid + "/search?q=" + query;
}


return await Get<MeilisearchDotnet.Types.SearchResponse<T>>(url);
}

/// <summary>
/// Find documents into an index
/// <summary>
public async Task<MeilisearchDotnet.Types.SearchResponse<T>> Find<T>(
string query,
MeilisearchDotnet.Types.SearchRequest options = null
)
{
return await Search<T>(query, options);
}

///
/// INDEX
///
Expand Down Expand Up @@ -173,7 +181,6 @@ string IndexUid
return await Put<MeilisearchDotnet.Types.EnqueuedUpdate>(url, payload);
}


/// <summary>
/// Get documents of an index
/// </summary>
Expand Down Expand Up @@ -412,7 +419,7 @@ public async Task<string> GetDistinctAttribute()
/// <summary>
/// Update the distinct-attribute
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> updateDistinctAttribute(string distinctAttribute)
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> UpdateDistinctAttribute(string distinctAttribute)
{
string url = "/indexes/" + Uid + "/settings/distinct-attribute";
string dataString = JsonSerializer.Serialize(distinctAttribute);
Expand All @@ -430,5 +437,103 @@ public async Task<string> GetDistinctAttribute()

return await Delete<MeilisearchDotnet.Types.EnqueuedUpdate>(url);
}

///
/// SEARCHABLE ATTRIBUTE
///

/// <summary>
/// Get the searchable-attributess
/// </summary>
public async Task<IEnumerable<string>> GetSearchableAttributes()
{
string url = "/indexes/" + Uid + "/settings/searchable-attributes";

return await Get<IEnumerable<string>>(url);
}

/// <summary>
/// Update the searchable-attributes
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> UpdateSearchableAttributes(IEnumerable<string> searchableAttributes)
{
string url = "/indexes/" + Uid + "/settings/searchable-attributes";
string dataString = JsonSerializer.Serialize(searchableAttributes);
StringContent payload = new StringContent(dataString, Encoding.UTF8, "application/x-www-form-urlencoded");

return await Post<MeilisearchDotnet.Types.EnqueuedUpdate>(url, payload);
}

/// <summary>
/// Reset the searchable-attributes
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> ResetSearchableAttributes()
{
string url = "/indexes/" + Uid + "/settings/searchable-attributes";

return await Delete<MeilisearchDotnet.Types.EnqueuedUpdate>(url);
}

///
/// DISPLAYED ATTRIBUTE
///

/// <summary>
/// Get the displayed-attributess
/// </summary>
public async Task<IEnumerable<string>> GetDisplayedAttributes()
{
string url = "/indexes/" + Uid + "/settings/displayed-attributes";

return await Get<IEnumerable<string>>(url);
}

/// <summary>
/// Update the displayed-attributes
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> UpdateDisplayedAttributes(IEnumerable<string> displayedAttributes)
{
string url = "/indexes/" + Uid + "/settings/displayed-attributes";
string dataString = JsonSerializer.Serialize(displayedAttributes);
StringContent payload = new StringContent(dataString, Encoding.UTF8, "application/x-www-form-urlencoded");

return await Post<MeilisearchDotnet.Types.EnqueuedUpdate>(url, payload);
}

/// <summary>
/// Reset the displayed-attributes
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> ResetDisplayedAttributes()
{
string url = "/indexes/" + Uid + "/settings/displayed-attributes";

return await Delete<MeilisearchDotnet.Types.EnqueuedUpdate>(url);
}

///
/// ACCEPT NEW FIELDS
///

/// <summary>
/// Get the displayed-attributess
/// </summary>
public async Task<bool> GetAcceptNewFields()
{
string url = "/indexes/" + Uid + "/settings/accept-new-fields";

return await Get<bool>(url);
}

/// <summary>
/// Update the displayed-attributes
/// </summary>
public async Task<MeilisearchDotnet.Types.EnqueuedUpdate> UpdateDisplayedAttributes(bool acceptNewFields)
{
string url = "/indexes/" + Uid + "/settings/accept-new-fields";
string dataString = JsonSerializer.Serialize(acceptNewFields);
StringContent payload = new StringContent(dataString, Encoding.UTF8, "application/x-www-form-urlencoded");

return await Post<MeilisearchDotnet.Types.EnqueuedUpdate>(url, payload);
}
}
}
1 change: 0 additions & 1 deletion src/MeilisearchDotnet/MeiliHttpClientWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text.Json;
using System.Net.Http;
using System.Threading.Tasks;
using MeilisearchDotnet.Exceptions;
Expand Down
2 changes: 0 additions & 2 deletions src/MeilisearchDotnet/Meilisearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class Meilisearch : MeiliHttpClientWrapper
// Avoid useless api calls by storing indexes we already know
public Dictionary<string, MeilisearchDotnet.Index> Indexes { get; set; }

// TODO: add StringBuilder object ??

public Meilisearch(string host, string apiKey) : base(host, apiKey)
{
Host = host;
Expand Down
2 changes: 1 addition & 1 deletion src/MeilisearchDotnet/meilisearch-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Library</OutputType>
<RootNamespace>meilisearch-dotnet</RootNamespace>
<PackageId>MeilisearchDotnet</PackageId>
<Version>0.0.2-a</Version>
<Version>0.0.3-a</Version>
<Authors>ndudnicz</Authors>
<Description>
WIP MeiliSearchDotnet is a client for MeiliSearch written in .NET standard 2.0. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box.
Expand Down

0 comments on commit ecc5da8

Please sign in to comment.