public void ShouldBeAbleToCreateSearchConnection() { using (var connection = NSonicFactory.Search(Hostname, Port, Secret)) { Assert.IsNotNull(connection); } }
public void VerifyFunctionality() { using var control = NSonicFactory.Control(Hostname, Port, Secret); control.Connect(); control.Info(); control.Trigger("consolidate"); using var search = NSonicFactory.Search(Hostname, Port, Secret); search.Connect(); search.Query("ContentIndex", "default", "example"); search.Suggest("ContentIndex", "default", "example"); search.Query("ContentIndex", "default", "example"); search.Query("ContentIndex", "default", "example"); search.Query("ContentIndex", "default", "example"); search.Suggest("ContentIndex", "default", "example"); search.Suggest("ContentIndex", "default", "example"); search.Suggest("ContentIndex", "default", "example"); using var ingest = NSonicFactory.Ingest(Hostname, Port, Secret); ingest.Connect(); ingest.Push("messages", "user:1", "conversation:1", "This is an example push.", locale: "SWE"); ingest.Pop("messages", "user:1", "conversation:1", "This is an example push."); ingest.Count("messages", "user:1"); ingest.FlushCollection("messages"); ingest.FlushBucket("messages", "user:1"); ingest.FlushObject("messages", "user:1", "conversation:1"); }
static void Main(string[] args) { var hostname = "localhost"; var port = 1491; var secret = "SecretPassword"; try { using (var control = NSonicFactory.Control(hostname, port, secret)) { control.Connect(); var info = control.Info(); Console.WriteLine($"INFO: {info}"); control.Trigger("consolidate"); } using (var search = NSonicFactory.Search(hostname, port, secret)) { search.Connect(); var queryResults = search.Query("messages", "user:1", "s"); Console.WriteLine($"QUERY: {string.Join(", ", queryResults)}"); var suggestResults = search.Suggest("messages", "user:1", "s"); Console.WriteLine($"SUGGEST: {string.Join(", ", suggestResults)}"); } using (var ingest = NSonicFactory.Ingest(hostname, port, secret)) { ingest.Connect(); ingest.Push("messages", "user:1", "conversation:1", "This is an example push.", locale: null); var popResult = ingest.Pop("messages", "user:1", "conversation:1", "This is an example push."); Console.WriteLine($"POP: {popResult}"); var countResult = ingest.Count("messages", "user:1"); Console.WriteLine($"COUNT: {countResult}"); var flushCollectionResult = ingest.FlushCollection("messages"); Console.WriteLine($"FLUSHC: {flushCollectionResult}"); var flushBucketResult = ingest.FlushBucket("messages", "user:1"); Console.WriteLine($"FLUSHB: {flushBucketResult}"); var flushObjectResult = ingest.FlushObject("messages", "user:1", "conversation:1"); Console.WriteLine($"FLUSHO: {flushObjectResult}"); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
public async Task VerifyFunctionalityAsync() { using (var control = NSonicFactory.Control(Hostname, Port, Secret)) { await control.ConnectAsync(); await control.InfoAsync(); await control.TriggerAsync("consolidate"); } using (var search = NSonicFactory.Search(Hostname, Port, Secret)) { await search.ConnectAsync(); await search.QueryAsync("messages", "user:1", "s"); await search.SuggestAsync("messages", "user:1", "s"); await search.QueryAsync("ContentIndex", "default", "example"); await search.SuggestAsync("ContentIndex", "default", "example"); await search.QueryAsync("ContentIndex", "default", "example"); await search.QueryAsync("ContentIndex", "default", "example"); await search.QueryAsync("ContentIndex", "default", "example"); await search.SuggestAsync("ContentIndex", "default", "example"); await search.SuggestAsync("ContentIndex", "default", "example"); await search.SuggestAsync("ContentIndex", "default", "example"); } using (var ingest = NSonicFactory.Ingest(Hostname, Port, Secret)) { await ingest.ConnectAsync(); await ingest.PushAsync("messages", "user:1", "conversation:1", "This is an example push.", locale : "SWE"); await ingest.PopAsync("messages", "user:1", "conversation:1", "This is an example push."); await ingest.CountAsync("messages", "user:1"); await ingest.FlushCollectionAsync("messages"); await ingest.FlushBucketAsync("messages", "user:1"); await ingest.FlushObjectAsync("messages", "user:1", "conversation:1"); } }
/// <summary> /// 私聊搜索返回值: 群组Id:消息Id /// 群聊搜索返回值: 群组Id:消息Id /// </summary> /// <param name="searchOption"></param> /// <returns></returns> public async Task <SearchOption> Search(SearchOption searchOption) { using (var sonicSearchConnection = NSonicFactory.Search(Env.SonicHostname, Env.SonicPort, Env.SonicSecret)) { await sonicSearchConnection.ConnectAsync(); var sonicQuery = await sonicSearchConnection.QueryAsync(searchOption.ChatId.ToString(), Env.SonicCollection, searchOption.Search, limit : searchOption.Take, offset : searchOption.Skip); if (sonicQuery.Length == searchOption.Take) { var sonicQueryCount = await sonicSearchConnection.QueryAsync(Env.SonicCollection, searchOption.ChatId.ToString(), searchOption.Search, limit : searchOption.Take, offset : searchOption.Skip + searchOption.Take); searchOption.Count = sonicQueryCount.Length + sonicQuery.Length + searchOption.Skip; } else { searchOption.Count = sonicQuery.Length + searchOption.Skip; } var Messages = new HashSet <Message>(new MessageComparer()); foreach (var e in sonicQuery) { var tmp = e.Split(":"); long groupid, messageid; if (long.TryParse(tmp[0], out groupid) && long.TryParse(tmp[1], out messageid)) { Messages.Add(new Message() { Id = 0, GroupId = groupid, MessageId = messageid, Content = Encoding.UTF8.GetString(await Cache.GetAsync($"{groupid}:{messageid}")) }); } } searchOption.Messages = new List <Message>(Messages); return(searchOption); } }