Skip to content

Commit

Permalink
Ready for Packaging and release.
Browse files Browse the repository at this point in the history
  • Loading branch information
satish860 committed Jun 23, 2020
1 parent 968303e commit 2adbbd7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ var movies = await this.index.Search<Movie>("ironman");
```

#### Custom Search
```c#
var movies = await this.index.Search<Movie>("ironman", new SearchQuery {Limit = 100});
```

⚙️ Development Workflow
If you want to contribute, this sections describes the steps to follow.

### Tests

```bash
# Tests
docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics
dotnet restore
dotnet test
```

### Release

TODO

```xml
<Version>x.x.x</Version>
```

## 🤖 Compatibility with MeiliSearch

This package works for MeiliSearch >=0.10.x
13 changes: 10 additions & 3 deletions src/Meilisearch/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,23 @@ public async Task<UpdateStatus> UpdateDocuments(IEnumerable<object> documents)
{
Need to support partial update of document. Would be nice if Patch can be supported.
} */

/// <summary>
/// Search documents with a default Search Query
/// </summary>
/// <param name="query">Query Parameter with Search</param>
/// <param name="searchattributes">Attributes to search.</param>
/// <typeparam name="T">Type parameter to return</typeparam>
/// <returns>Enumerable of items</returns>
public async Task<SearchResult<T>> Search<T>(string query)
public async Task<SearchResult<T>> Search<T>(string query,SearchQuery searchattributes = default(SearchQuery))
{
var searchResults = await this._client.GetFromJsonAsync<SearchResult<T>>($"/indexes/{Uid}/search?q={query}");
string uri = $"/indexes/{Uid}/search?q={query}";
if (searchattributes != null)
{
uri = QueryHelpers.AddQueryString(uri, searchattributes.AsDictionary());
}

var searchResults = await this._client.GetFromJsonAsync<SearchResult<T>>(uri);
return searchResults;
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/Meilisearch/SearchQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Meilisearch
{
/// <summary>
/// Search Query for Meilisearch class
/// </summary>
public class SearchQuery
{
/// <summary>
/// Offset for the Query.
/// </summary>
public int? Offset { get; set; }

/// <summary>
/// Limit the number of results.
/// </summary>
public int? Limit { get; set; }

/// <summary>
/// Filters to search the query.
/// </summary>
public string Filter { get; set; }

/// <summary>
/// Attributes to retrieve.
/// </summary>
public string AttributesToRetrieve { get; set; }

/// <summary>
/// Attributes to crop.
/// </summary>
public string attributesToCrop { get; set; }

/// <summary>
/// Length used to crop field values
/// </summary>
public int? cropLength { get; set; }

/// <summary>
/// Attributes whose values will contain highlighted matching terms
/// </summary>
public string AttributesToHighlight { get; set; }

/// <summary>
/// Defines whether an object that contains information about the matches should be returned or not
/// </summary>
public string Matches { get; set; }
}
}
7 changes: 7 additions & 0 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ public async Task Should_Be_to_Search_A_Index_Document()
var movies = await this.index.Search<Movie>("ironman");
movies.Hits.Should().NotBeEmpty();
}

[Fact]
public async Task Should_Be_able_to_Send_Different_Parameters()
{
var movies = await this.index.Search<Movie>("ironman", new SearchQuery {Limit = 100});
movies.Hits.Should().NotBeEmpty();
}
}
}

0 comments on commit 2adbbd7

Please sign in to comment.