C# 使用Algolia C为镶嵌面添加属性#
我想为刻面添加一个属性:C# 使用Algolia C为镶嵌面添加属性#,c#,algolia,C#,Algolia,我想为刻面添加一个属性:ApprovalFL。当我在Algolia仪表板中添加facet时,它可以正常工作,直到我不得不重新编制索引,最终由于某种原因删除了仪表板中的facet。我在想,也许在代码中添加属性可以解决这个问题。我在这里找到了有关此步骤的文档: 以下是他们提供的C#示例: index.SetSettings( JObject.Parse(@"{""attributesForFaceting"":[""author"",""filterOnly(category)"",""sear
ApprovalFL
。当我在Algolia仪表板中添加facet时,它可以正常工作,直到我不得不重新编制索引,最终由于某种原因删除了仪表板中的facet。我在想,也许在代码中添加属性可以解决这个问题。我在这里找到了有关此步骤的文档:
以下是他们提供的C#示例:
index.SetSettings(
JObject.Parse(@"{""attributesForFaceting"":[""author"",""filterOnly(category)"",""searchable(publisher)""]}")
);
如果我理解正确,则需要将此代码放入我的后端重新索引代码(可在我的AdminController.cs
中找到):
顺便问一下,为什么要重新编制索引?最佳做法是只在最初设置索引。对于使用C#.NET的用户,只需将其添加到您的
Global.asax.cs
中即可。例如,对于我:
var songIndexHelper = new IndexHelper<SongAlgoliaModel>(algoliaClient, "Song", "SongID");
songIndexHelper.SetSettings(JObject.Parse(@"{""attributesForFaceting"":[""ApprovalFL""]}"));
var songIndexHelper=newindexhelper(algoliaClient,“Song”,“SongID”);
songIndexHelper.SetSettings(JObject.Parse(@“{”attributesForFaceting”“:[“ApprovalFL”“]}”);
嘿,丹尼尔,这是因为用户一直在添加新歌,我希望它们在上线时可以搜索。这有意义吗?是否有更好的方法更新搜索结果?是的,确切地说,您可以将Algolia与歌曲添加模块集成,或者有一个后台工作,定期检查新歌并将其处理为索引。现在,通过处理索引,您可以使用API推送数据,请参阅。无论何时添加新歌,都不需要重新创建索引,这是低效的。
public static SongAlgoliaModel BuildAlgoliaSongModel(Song song)
{
var model = new SongAlgoliaModel();
var album = EntityDataAccess.GetAlbumByID(song.AlbumID);
model.AccountImageURL = album.AccountInfo.ImageURL;
model.AccountInfoID = album.AccountInfoID;
model.AccountType = album.AccountInfo.CreatorFL == true ? "Creator" : "Artist";
model.AlbumID = song.AlbumID;
model.AlbumName = album.AlbumName;
model.ApprovalFL = song.ApprovalFL;
model.Artist = album.AccountInfo.DisplayName;
model.BPM = song.BPM;
model.Duration = song.Duration;
model.FeaturedArtist = song.Artist;
model.FreeFL = album.FreeFL;
model.ImageURL = album.ImageURL;
model.iTunesURL = album.iTunesURL;
model.LabelName = album.LabelName;
model.LicenseFL = album.LicenseFL;
model.SongID = song.SongID;
model.Title = song.Title;
model.UploadDate = song.UploadDate;
model.URL = song.URL;
model.UserID = album.AccountInfo.UserID;
return model;
}
public static List<SongAlgoliaModel> BuildAlgoliaSongModels(AccountInfo accountInfo)
{
var list = new List<SongAlgoliaModel>();
var songs = EntityDataAccess.GetSongsByUserID(accountInfo.UserID).Where(x => x.ApprovalFL == true).ToList();
foreach(var item in songs)
{
var model = new SongAlgoliaModel();
model.AccountImageURL = item.Album.AccountInfo.ImageURL;
model.AccountInfoID = item.Album.AccountInfoID;
model.AccountType = item.Album.AccountInfo.CreatorFL == true ? "Creator" : "Artist";
model.AlbumID = item.AlbumID;
model.AlbumName = item.Album.AlbumName;
model.ApprovalFL = item.ApprovalFL;
model.Artist = item.Album.AccountInfo.DisplayName;
model.BPM = item.BPM;
model.Duration = item.Duration;
model.FeaturedArtist = item.Artist;
model.FreeFL = item.Album.FreeFL;
model.ImageURL = item.Album.ImageURL;
model.iTunesURL = item.Album.iTunesURL;
model.LabelName = item.Album.LabelName;
model.LicenseFL = item.Album.LicenseFL;
model.SongID = item.SongID;
model.Title = item.Title;
model.UploadDate = item.UploadDate;
model.URL = item.URL;
model.UserID = item.Album.AccountInfo.UserID;
list.Add(model);
}
return list;
}
var songIndexHelper = new IndexHelper<SongAlgoliaModel>(algoliaClient, "Song", "SongID");
songIndexHelper.SetSettings(JObject.Parse(@"{""attributesForFaceting"":[""ApprovalFL""]}"));