docs: #288 trying SQL full text search
This commit is contained in:
parent
3844987bfe
commit
ff169b2af2
@ -13142,21 +13142,22 @@
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.Search(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
Search
|
||||
You need to run this scripts manually on the database before using this method:
|
||||
|
||||
CREATE FULLTEXT CATALOG [GanjoorPoemPlainTextCatalog] WITH ACCENT_SENSITIVITY = OFF
|
||||
ALTER TABLE [dbo].[GanjoorPoems] ADD CONSTRAINT [PK_GanjoorPoems] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[Id] ASC
|
||||
) WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY]
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="term"></param>
|
||||
<param name="poetId"></param>
|
||||
<param name="catId"></param>
|
||||
<returns></returns>
|
||||
<summary>
|
||||
Search
|
||||
You need to run this scripts manually on the database before using this method:
|
||||
|
||||
CREATE FULLTEXT CATALOG [GanjoorPoemPlainTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT
|
||||
|
||||
CREATE FULLTEXT INDEX ON [dbo].[GanjoorPoems](
|
||||
[PlainText] LANGUAGE 'English')
|
||||
KEY INDEX [PK_GanjoorPoems]ON ([GanjoorPoemPlainTextCatalog], FILEGROUP [PRIMARY])
|
||||
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="term"></param>
|
||||
<param name="poetId"></param>
|
||||
<param name="catId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdatePageAsync(System.Int32,System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorModifyPageViewModel)">
|
||||
<summary>
|
||||
|
||||
@ -3202,18 +3202,73 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
term = term.Replace("", " ");//replace zwnj with space
|
||||
|
||||
string searchConditions;
|
||||
if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))
|
||||
{
|
||||
searchConditions = term.Replace("\"", "").Replace("'", "");
|
||||
searchConditions = $"\"{searchConditions}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] words = term.Replace("\"", "").Replace("'", "").Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
searchConditions = "";
|
||||
string emptyOrAnd = "";
|
||||
foreach (string word in words)
|
||||
{
|
||||
searchConditions += $" {emptyOrAnd} \"*{word}*\" ";
|
||||
emptyOrAnd = " AND ";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
CREATE FULLTEXT CATALOG RArtifactMasterRecord
|
||||
|
||||
GO
|
||||
|
||||
CREATE FULLTEXT INDEX ON [dbo].[Artifacts](
|
||||
[Name] LANGUAGE 'English',
|
||||
[NameInEnglish] LANGUAGE 'English',
|
||||
[Description] LANGUAGE 'English',
|
||||
[DescriptionInEnglish] LANGUAGE 'English'
|
||||
)
|
||||
KEY INDEX [PK_Artifacts]ON ([RArtifactMasterRecord], FILEGROUP [PRIMARY])
|
||||
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
|
||||
|
||||
GO
|
||||
|
||||
CREATE FULLTEXT INDEX ON [dbo].[Items](
|
||||
[Name] LANGUAGE 'English',
|
||||
[NameInEnglish] LANGUAGE 'English',
|
||||
[Description] LANGUAGE 'English',
|
||||
[DescriptionInEnglish] LANGUAGE 'English'
|
||||
)
|
||||
KEY INDEX [PK_Items]ON ([RArtifactMasterRecord], FILEGROUP [PRIMARY])
|
||||
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
|
||||
|
||||
GO
|
||||
|
||||
CREATE FULLTEXT INDEX ON [dbo].[TagValues](
|
||||
[Value] LANGUAGE 'English',
|
||||
[ValueInEnglish] LANGUAGE 'English'
|
||||
)
|
||||
KEY INDEX [PK_TagValues]ON ([RArtifactMasterRecord], FILEGROUP [PRIMARY])
|
||||
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
|
||||
|
||||
*/
|
||||
|
||||
var source =
|
||||
_context.Artifacts.AsNoTracking().Include(a => a.Tags).Include(a => a.CoverImage)
|
||||
.Where(p =>
|
||||
p.Name.Contains(term)
|
||||
EF.Functions.Contains(p.Name, searchConditions)
|
||||
||
|
||||
p.NameInEnglish.Contains(term)
|
||||
EF.Functions.Contains(p.NameInEnglish, searchConditions)
|
||||
||
|
||||
p.Description.Contains(term)
|
||||
EF.Functions.Contains(p.Description, searchConditions)
|
||||
||
|
||||
p.DescriptionInEnglish.Contains(term)
|
||||
EF.Functions.Contains(p.DescriptionInEnglish, searchConditions)
|
||||
||
|
||||
p.Tags.Where(t => t.Value.Contains(term) || t.ValueInEnglish.Contains(term)).Any()
|
||||
p.Tags.Where(t => EF.Functions.Contains(t.Value, searchConditions) || EF.Functions.Contains(t.ValueInEnglish, searchConditions)).Any()
|
||||
);
|
||||
|
||||
|
||||
@ -3241,18 +3296,37 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
term = term.Replace("", " ");//replace zwnj with space
|
||||
|
||||
string searchConditions;
|
||||
if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))
|
||||
{
|
||||
searchConditions = term.Replace("\"", "").Replace("'", "");
|
||||
searchConditions = $"\"{searchConditions}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] words = term.Replace("\"", "").Replace("'", "").Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
searchConditions = "";
|
||||
string emptyOrAnd = "";
|
||||
foreach (string word in words)
|
||||
{
|
||||
searchConditions += $" {emptyOrAnd} \"*{word}*\" ";
|
||||
emptyOrAnd = " AND ";
|
||||
}
|
||||
}
|
||||
|
||||
var source =
|
||||
_context.Items.AsNoTracking().Include(a => a.Tags).Include(a => a.Images)
|
||||
.Where(p =>
|
||||
p.Name.Contains(term)
|
||||
EF.Functions.Contains(p.Name, searchConditions)
|
||||
||
|
||||
p.NameInEnglish.Contains(term)
|
||||
EF.Functions.Contains(p.NameInEnglish, searchConditions)
|
||||
||
|
||||
p.Description.Contains(term)
|
||||
EF.Functions.Contains(p.Description, searchConditions)
|
||||
||
|
||||
p.DescriptionInEnglish.Contains(term)
|
||||
EF.Functions.Contains(p.DescriptionInEnglish, searchConditions)
|
||||
||
|
||||
p.Tags.Where(t => t.Value.Contains(term) || t.ValueInEnglish.Contains(term)).Any()
|
||||
p.Tags.Where(t => EF.Functions.Contains(t.Value, searchConditions) || EF.Functions.Contains(t.ValueInEnglish, searchConditions)).Any()
|
||||
);
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user