-
Notifications
You must be signed in to change notification settings - Fork 28
chore(guides): some missing snippets + guides #4477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7051d8c
chore: some missing snippets
Fluf22 ef3d1e6
chore: better templates
Fluf22 0c155ef
chore: better templates
Fluf22 cd620b8
chore: better templates
Fluf22 7d7c925
chore(python): headers type
Fluf22 f16f483
guides: half of them
Fluf22 5a96981
fix: some
Fluf22 af858d4
fix: others
Fluf22 46805f7
fix: lasts
Fluf22 75dddaf
fix: last last
Fluf22 9bc5f00
chore: better templates
Fluf22 ae838b5
chore: better templates
Fluf22 a374850
guides: less than half of the remaining half
Fluf22 116d599
guides: js
Fluf22 4f785c8
guides: go
Fluf22 6ca86eb
guides: php
Fluf22 95b5246
guides: python
Fluf22 bd53908
guides: ruby
Fluf22 0153b36
guides: swift
Fluf22 713b352
guides: js fix
Fluf22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
templates/csharp/guides/search/globalAlgoliaUserID.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace Algolia; | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Net.Http; | ||
| using System.Collections.Generic; | ||
|
|
||
| {{> snippets/import}} | ||
|
|
||
| class GlobalAlgoliaUserID | ||
| { | ||
| async Task Main(string[] args) | ||
| { | ||
| var client = new SearchClient( | ||
| new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY") | ||
| { | ||
| DefaultHeaders = new Dictionary<string, string> { { "X-Algolia-UserToken", "test-user-123" } } | ||
| } | ||
| ); | ||
| Console.WriteLine(client); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| namespace Algolia; | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Net.Http; | ||
| using System.Collections.Generic; | ||
|
|
||
| {{> snippets/import}} | ||
|
|
||
| class McmSearchWithout { | ||
|
|
||
| private static string GetAppIdFor(string user) { | ||
| return ""; // Implement your own logic here | ||
| } | ||
|
|
||
| private static string GetIndexingApiKeyFor(string user) { | ||
| return ""; // Implement your own logic here | ||
| } | ||
|
|
||
| async Task Main(string[] args) | ||
| { | ||
|
|
||
| // Fetch from your own data storage and with your own code | ||
| // the associated application ID and API key for this user | ||
| var appId = GetAppIdFor("user42"); | ||
| var apiKey = GetIndexingApiKeyFor("user42"); | ||
|
|
||
| var client = new SearchClient(new SearchConfig(appId, apiKey)); | ||
| var searchParams = new SearchParams(new SearchParamsObject | ||
| { | ||
| Query = "<YOUR_SEARCH_QUERY>", | ||
| FacetFilters = new FacetFilters([new FacetFilters("user:user42"), new FacetFilters("user:public")]) | ||
| } | ||
| ); | ||
|
|
||
| {{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}}; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
templates/csharp/guides/search/saveImageClassifications.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| namespace Algolia; | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Net.Http; | ||
| using System.Collections.Generic; | ||
|
|
||
| {{> snippets/import}} | ||
|
|
||
| class SaveImageClassifications { | ||
|
|
||
| class Image | ||
| { | ||
| public required string ImageUrl { get; set; } | ||
| public required string ObjectId { get; set; } | ||
| public required List<Dictionary<string, object>> Objects { get; set; } | ||
| } | ||
|
|
||
| // Retrieve labels | ||
| async Task<Image> GetImageLabels(string imageURL, string objectID, float scoreLimit) | ||
| { | ||
| // Implement your image classification logic here | ||
| return await Task.Run(() => new Image | ||
| { | ||
| ImageUrl = "", | ||
| ObjectId = "", | ||
| Objects = [] | ||
| }); | ||
| } | ||
|
|
||
| async Task Main(string[] args) | ||
| { | ||
|
|
||
| try { | ||
| // API key ACL should include editSettings / addObject | ||
| {{> snippets/init}} | ||
|
|
||
| var hits = await client.BrowseObjectsAsync<Image>( | ||
| "<YOUR_INDEX_NAME>", | ||
| new BrowseParamsObject() | ||
| ); | ||
|
|
||
| var records = hits | ||
| .Select(hit => GetImageLabels(hit.ImageUrl, hit.ObjectId, 0.5f)) | ||
| .Select(src => src.Result) | ||
| .ToList(); | ||
|
|
||
| // Update records with image classifications | ||
| {{#dynamicSnippet}}partialUpdatesRecords{{/dynamicSnippet}}; | ||
| } catch (Exception e) { | ||
| Console.WriteLine(e.Message); | ||
| } | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
templates/csharp/guides/search/saveImageClassificationsAndSettings.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| namespace Algolia; | ||
|
|
||
| using System; | ||
| using System.Text.Json; | ||
| using System.Net.Http; | ||
| using System.Collections.Generic; | ||
|
|
||
| {{> snippets/import}} | ||
|
|
||
| class SaveImageClassificationsAndSettings { | ||
|
|
||
| class Image | ||
| { | ||
| public required string ImageUrl { get; set; } | ||
| public required string ObjectId { get; set; } | ||
| public required List<Dictionary<string, object>> Objects { get; set; } | ||
| } | ||
|
|
||
| // Retrieve labels | ||
| async Task<Image> GetImageLabels(string imageURL, string objectID, float scoreLimit) | ||
| { | ||
| // Implement your image classification logic here | ||
| return await Task.Run(() => new Image | ||
| { | ||
| ImageUrl = "", | ||
| ObjectId = "", | ||
| Objects = [] | ||
| }); | ||
| } | ||
|
|
||
| async Task Main(string[] args) | ||
| { | ||
|
|
||
| try { | ||
| // API key ACL should include editSettings / addObject | ||
| {{> snippets/init}} | ||
|
|
||
| var hits = await client.BrowseObjectsAsync<Image>( | ||
| "<YOUR_INDEX_NAME>", | ||
| new BrowseParamsObject() | ||
| ); | ||
|
|
||
| var images = hits.ToList(); | ||
| var records = images | ||
| .Select(hit => GetImageLabels(hit.ImageUrl, hit.ObjectId, 0.5f)) | ||
| .Select(src => src.Result) | ||
| .ToList(); | ||
|
|
||
| // Update records with image classifications | ||
| {{#dynamicSnippet}}partialUpdatesRecords{{/dynamicSnippet}}; | ||
|
|
||
| List<string> facets = []; | ||
| List<string> attributes = []; | ||
|
|
||
| foreach (var image in images) | ||
| { | ||
| foreach (var obj in image.Objects) | ||
| { | ||
| foreach (var key in obj.Keys) | ||
| { | ||
| if (obj[key] is IEnumerable<object>) | ||
| { | ||
| facets.Add($"searchable(objects.{key}.label)"); | ||
| facets.Add($"searchable(objects.{key}.score)"); | ||
| attributes.Add($"objects.{key}.label"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var currentSettings = {{#dynamicSnippet}}getSettings{{/dynamicSnippet}}; | ||
|
|
||
| var settings = new IndexSettings | ||
| { | ||
| SearchableAttributes = currentSettings.SearchableAttributes.Concat(attributes).ToList(), | ||
| AttributesForFaceting = currentSettings.AttributesForFaceting.Concat(facets).ToList() | ||
| }; | ||
|
|
||
| {{#dynamicSnippet}}setSettings{{/dynamicSnippet}}; | ||
| } catch (Exception e) { | ||
| Console.WriteLine(e.Message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because ultimately we always use it as a dict, it's never treated like it can be
NoneSo setting it to an empty dict from the beginning ease the DX