public void ConfigureSearch() { TdSearchContext.Configure(GetSearchConfiguration); TdSearchContext.Current.IndexManager.RunIndexMaintenanceAsync(); //register for static ticket changed event handler TdDomainContext.TicketsChanged += (sender, ticketChanges) => { // ReSharper disable once EmptyGeneralCatchClause try { var changes = ticketChanges as Ticket[] ?? ticketChanges.ToArray(); //deletes (such as the demo data manager removing everything) will fire // this, but ticketChanges will be empty in those cases if (changes.Any()) { //add to search index var searchItems = changes.ToSeachIndexItems().ToArray(); HostingEnvironment.QueueBackgroundWorkItem( async ct => await TdSearchContext.Current.IndexManager.AddItemsToIndexAsync(searchItems) .ConfigureAwait(false)); } } catch { //TODO: log this somewhere } }; }
public static async Task <IEnumerable <Ticket> > SearchAsync(this TdSearchContext manager, IQueryable <Ticket> ticketQuery, string searchText, int projectId) { var results = await manager.IndexSearcher.SearchAsync(searchText, projectId); return(from i in results join t in ticketQuery on i.Id equals t.TicketId orderby i.SearchScore descending select t); }
public static async Task <IEnumerable <Ticket> > SearchAsync(this TdSearchContext manager, IQueryable <Ticket> ticketQuery, string searchText, int projectId) { var results = await manager.IndexSearcher.SearchAsync(searchText, projectId); var inFilter = results.Select(r => r.Id).ToList(); return(from t in (from t in ticketQuery where inFilter.Contains(t.TicketId) select t).ToList() join i in results on t.TicketId equals i.Id orderby i.SearchScore descending select t); }