This commit is contained in:
@@ -91,7 +91,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
return NotFound();
|
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));
|
return Ok(ApiOkResponse.Response(res, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Immutable;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
@@ -83,6 +84,7 @@ namespace AyaNova.Biz
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion error handling
|
#endregion error handling
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using AyaNova.Biz;
|
|
||||||
using AyaNova.Models;
|
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
@@ -19,7 +17,6 @@ namespace AyaNova.Biz
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
List<ValidationError> Errors { get; }
|
List<ValidationError> Errors { get; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is true if there are errors
|
/// Is true if there are errors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -30,9 +27,6 @@ namespace AyaNova.Biz
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool PropertyHasErrors(string propertyName);
|
bool PropertyHasErrors(string propertyName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -50,6 +44,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
17
server/AyaNova/biz/ISearchAbleObject.cs
Normal file
17
server/AyaNova/biz/ISearchAbleObject.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using AyaNova.Models;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace AyaNova.Biz
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for biz objects that support searching
|
||||||
|
/// </summary>
|
||||||
|
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<Search.SearchIndexProcessObjectParameters> GetSearchResultSummary(long id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -273,7 +273,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
#region Get info (excerpt)
|
#region Get info (excerpt)
|
||||||
public static async Task<string> GetInfoAsync(AyContext ct, long translationId,
|
public static async Task<string> 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
|
//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
|
//https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE
|
||||||
@@ -285,9 +285,21 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//BREAK SEARCH PHRASE INTO SEPARATE TERMS
|
//BREAK SEARCH PHRASE INTO SEPARATE TERMS
|
||||||
var PhraseItems = await BreakSearchPhraseAsync(translationId, phrase);
|
var PhraseItems = await BreakSearchPhraseAsync(translationId, phrase);
|
||||||
|
|
||||||
PhraseItems.ToArray();
|
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
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do the extraction and ranking
|
/// Do the extraction and ranking
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rawText"></param>
|
/// <param name="searchObjectParams"></param>
|
||||||
/// <param name="searchTerms"></param>
|
/// <param name="searchTerms"></param>
|
||||||
public void Process(string rawText, string[] searchTerms)
|
public void Process(SearchIndexProcessObjectParameters searchObjectParams, string[] searchTerms)
|
||||||
{
|
{
|
||||||
|
|
||||||
ranking = 0;
|
ranking = 0;
|
||||||
extract = "";
|
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)");
|
//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;
|
if (rawText == null || rawText == "") return;
|
||||||
this.rawtext = rawText;
|
this.rawtext = rawText;
|
||||||
@@ -581,6 +597,7 @@ namespace AyaNova.Biz
|
|||||||
#region ProcessKeywords into Database
|
#region ProcessKeywords into Database
|
||||||
|
|
||||||
//Class to hold process input parameters
|
//Class to hold process input parameters
|
||||||
|
//also used for getting summary search results
|
||||||
public class SearchIndexProcessObjectParameters
|
public class SearchIndexProcessObjectParameters
|
||||||
{
|
{
|
||||||
public long TranslationId { get; set; }
|
public long TranslationId { get; set; }
|
||||||
@@ -598,8 +615,17 @@ namespace AyaNova.Biz
|
|||||||
TranslationId = translationId;
|
TranslationId = translationId;
|
||||||
ObjectId = objectID;
|
ObjectId = objectID;
|
||||||
ObjectType = objectType;
|
ObjectType = objectType;
|
||||||
// Name = name;
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//format used for getsummmary by biz objects
|
||||||
|
public SearchIndexProcessObjectParameters()
|
||||||
|
{
|
||||||
|
Words = new List<string>();
|
||||||
|
TranslationId = 0;
|
||||||
|
ObjectId = 0;
|
||||||
|
ObjectType = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchIndexProcessObjectParameters AddText(string s)
|
public SearchIndexProcessObjectParameters AddText(string s)
|
||||||
|
|||||||
@@ -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; }
|
public bool SeedOrImportRelaxedRulesMode { get; set; }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using AyaNova.Models;
|
|||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class WidgetBiz : BizObject, IJobObject
|
internal class WidgetBiz : BizObject, IJobObject, ISearchAbleObject
|
||||||
{
|
{
|
||||||
|
|
||||||
internal WidgetBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
internal WidgetBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
@@ -106,12 +106,12 @@ namespace AyaNova.Biz
|
|||||||
bool NotUnique = true;
|
bool NotUnique = true;
|
||||||
long l = 1;
|
long l = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
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);
|
} while (NotUnique);
|
||||||
|
|
||||||
outObj.Name = newUniqueName;
|
outObj.Name = newUniqueName;
|
||||||
|
|
||||||
|
|
||||||
outObj.Id = 0;
|
outObj.Id = 0;
|
||||||
@@ -211,6 +211,14 @@ namespace AyaNova.Biz
|
|||||||
await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
|
await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Search.SearchIndexProcessObjectParameters> 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
|
//DELETE
|
||||||
@@ -345,6 +353,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Other job handlers here...
|
//Other job handlers here...
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user