From fd475b06cee08e997348546594433f8687fd25a8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 9 Apr 2020 14:50:54 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/SearchController.cs | 3 +- server/AyaNova/biz/BizObject.cs | 2 + server/AyaNova/biz/IBizObject.cs | 10 ++--- server/AyaNova/biz/ISearchAbleObject.cs | 17 +++++++++ server/AyaNova/biz/Search.cs | 38 ++++++++++++++++--- server/AyaNova/biz/UserBiz.cs | 2 +- server/AyaNova/biz/WidgetBiz.cs | 18 +++++++-- 7 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 server/AyaNova/biz/ISearchAbleObject.cs diff --git a/server/AyaNova/Controllers/SearchController.cs b/server/AyaNova/Controllers/SearchController.cs index 39f84c4f..2e7f20f2 100644 --- a/server/AyaNova/Controllers/SearchController.cs +++ b/server/AyaNova/Controllers/SearchController.cs @@ -91,7 +91,8 @@ namespace AyaNova.Api.Controllers return NotFound(); } - var res = await Search.GetInfoAsync(ct, UserTranslationIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), phrase, ayaType, id); + var res = await Search.GetInfoAsync(ct, UserTranslationIdFromContext.Id(HttpContext.Items), + UserRolesFromContext.Roles(HttpContext.Items),UserIdFromContext.Id(HttpContext.Items), phrase, ayaType, id); return Ok(ApiOkResponse.Response(res, true)); } diff --git a/server/AyaNova/biz/BizObject.cs b/server/AyaNova/biz/BizObject.cs index 48b28f6d..7ef2e2e1 100644 --- a/server/AyaNova/biz/BizObject.cs +++ b/server/AyaNova/biz/BizObject.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; +using System.Threading.Tasks; using AyaNova.Biz; namespace AyaNova.Biz @@ -83,6 +84,7 @@ namespace AyaNova.Biz return sb.ToString(); } + #endregion error handling }//eoc diff --git a/server/AyaNova/biz/IBizObject.cs b/server/AyaNova/biz/IBizObject.cs index ea1bf9a9..36946fe7 100644 --- a/server/AyaNova/biz/IBizObject.cs +++ b/server/AyaNova/biz/IBizObject.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -using System.Collections.Immutable; -using AyaNova.Biz; -using AyaNova.Models; + namespace AyaNova.Biz { @@ -19,7 +17,6 @@ namespace AyaNova.Biz /// List Errors { get; } - /// /// Is true if there are errors /// @@ -30,9 +27,6 @@ namespace AyaNova.Biz /// bool PropertyHasErrors(string propertyName); - - - /// /// /// @@ -50,6 +44,8 @@ namespace AyaNova.Biz + + } } \ No newline at end of file diff --git a/server/AyaNova/biz/ISearchAbleObject.cs b/server/AyaNova/biz/ISearchAbleObject.cs new file mode 100644 index 00000000..5ea94ef0 --- /dev/null +++ b/server/AyaNova/biz/ISearchAbleObject.cs @@ -0,0 +1,17 @@ +using AyaNova.Models; +using System.Threading.Tasks; +namespace AyaNova.Biz +{ + /// + /// Interface for biz objects that support searching + /// + internal interface ISearchAbleObject + { + + //get all text for the object that would have been indexed for search + //called by search::GetInfoAsync as a result of a user requesting a search result sumary + Task GetSearchResultSummary(long id); + + } + +} \ No newline at end of file diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index c9321a6a..93d73864 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -273,7 +273,7 @@ namespace AyaNova.Biz #region Get info (excerpt) public static async Task GetInfoAsync(AyContext ct, long translationId, - AuthorizationRoles currentUserRoles, string phrase, AyaType ayaType, long id) + AuthorizationRoles currentUserRoles, long userId, string phrase, AyaType ayaType, long id) { //escape literal percentage signs first just in case they are searching for 50% off or something //https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE @@ -285,9 +285,21 @@ namespace AyaNova.Biz //BREAK SEARCH PHRASE INTO SEPARATE TERMS var PhraseItems = await BreakSearchPhraseAsync(translationId, phrase); - PhraseItems.ToArray(); - + + //get text + ISearchAbleObject o = (ISearchAbleObject)BizObjectFactory.GetBizObject(ayaType, ct, userId, currentUserRoles); + + //get extract + var searchParams = await o.GetSearchResultSummary(id); + + //extract and rank here + ExtractAndRank er = new ExtractAndRank(); + er.Process(searchParams, PhraseItems.ToArray()); + // sr.Extract = er.Extract; + // sr.Rank = er.Ranking; + + return er.Extract; } @@ -415,12 +427,16 @@ namespace AyaNova.Biz /// /// Do the extraction and ranking /// - /// + /// /// - public void Process(string rawText, string[] searchTerms) + public void Process(SearchIndexProcessObjectParameters searchObjectParams, string[] searchTerms) { + ranking = 0; extract = ""; + + string rawText = string.Join(" ", searchObjectParams.Words); + //System.Diagnostics.Debug.Assert(rawText!=null && rawText!="","EXTRACT AND RANK","EMPTY RAWTEXT, CHECK OBJECTS GetSearchResult() CODE TO ENSURE IT'S GOT THE correct SP (CHECK THE SP IF NOT)"); if (rawText == null || rawText == "") return; this.rawtext = rawText; @@ -581,6 +597,7 @@ namespace AyaNova.Biz #region ProcessKeywords into Database //Class to hold process input parameters + //also used for getting summary search results public class SearchIndexProcessObjectParameters { public long TranslationId { get; set; } @@ -598,8 +615,17 @@ namespace AyaNova.Biz TranslationId = translationId; ObjectId = objectID; ObjectType = objectType; - // Name = name; + + } + + //format used for getsummmary by biz objects + public SearchIndexProcessObjectParameters() + { + Words = new List(); + TranslationId = 0; + ObjectId = 0; + ObjectType = 0; } public SearchIndexProcessObjectParameters AddText(string s) diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index d6fb10c9..5b49f9e9 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -14,7 +14,7 @@ namespace AyaNova.Biz { - internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object + internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object, ISearchAbleObject { public bool SeedOrImportRelaxedRulesMode { get; set; } diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index 2730a1ad..d8b9813a 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -9,7 +9,7 @@ using AyaNova.Models; namespace AyaNova.Biz { - internal class WidgetBiz : BizObject, IJobObject + internal class WidgetBiz : BizObject, IJobObject, ISearchAbleObject { internal WidgetBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) @@ -106,12 +106,12 @@ namespace AyaNova.Biz bool NotUnique = true; long l = 1; do - { + { newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255); - NotUnique = await ct.Widget.AnyAsync(m => m.Name == newUniqueName); + NotUnique = await ct.Widget.AnyAsync(m => m.Name == newUniqueName); } while (NotUnique); - outObj.Name = newUniqueName; + outObj.Name = newUniqueName; outObj.Id = 0; @@ -211,6 +211,14 @@ namespace AyaNova.Biz await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams); } + public async Task GetSearchResultSummary(long id) + { + var obj = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id); + var SearchParams = new Search.SearchIndexProcessObjectParameters(); + SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Serial).AddText(obj.Tags).AddCustomFields(obj.CustomFields); + + return SearchParams; + } //////////////////////////////////////////////////////////////////////////////////////////////// //DELETE @@ -345,6 +353,8 @@ namespace AyaNova.Biz } + + //Other job handlers here...