#407 search within pages text
This commit is contained in:
parent
62787295a1
commit
e24d54be11
@ -2,6 +2,7 @@
|
||||
using RSecurityBackend.Models.Image;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace RMuseum.Models.PDFLibrary
|
||||
{
|
||||
@ -80,5 +81,11 @@ namespace RMuseum.Models.PDFLibrary
|
||||
/// </summary>
|
||||
public string PageText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// pdf book
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public PDFBook PDFBook { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -12785,6 +12785,11 @@
|
||||
page text
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.PDFLibrary.PDFPage.PDFBook">
|
||||
<summary>
|
||||
pdf book
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.PDFLibrary.PDFSource">
|
||||
<summary>
|
||||
PDF Source (Web Sites)
|
||||
@ -18684,6 +18689,23 @@
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.SearchPDFBookForPDFPagesTextAsync(RSecurityBackend.Models.Generic.PagingParameterModel,System.String)">
|
||||
<summary>
|
||||
search pdf books pages for a text
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.SearchPDFPagesTextAsync(RSecurityBackend.Models.Generic.PagingParameterModel,System.Int32,System.String)">
|
||||
<summary>
|
||||
search pdf pages
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="bookId">0 for all pdf books</param>
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:RMuseum.Services.Implementation.PDFLibraryService._context">
|
||||
<summary>
|
||||
Database Context
|
||||
@ -19925,6 +19947,23 @@
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.SearchPDFBookForPDFPagesTextAsync(RSecurityBackend.Models.Generic.PagingParameterModel,System.String)">
|
||||
<summary>
|
||||
search pdf books pages for a text
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.SearchPDFPagesTextAsync(RSecurityBackend.Models.Generic.PagingParameterModel,System.Int32,System.String)">
|
||||
<summary>
|
||||
search pdf pages
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="bookId">0 for all pdf books</param>
|
||||
<param name="term"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IPictureFileService">
|
||||
<summary>
|
||||
manipulating picture files
|
||||
|
||||
@ -396,5 +396,22 @@ namespace RMuseum.Services
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> SetPDFPageOCRInfoAsync(PDFPageOCRDataViewModel model);
|
||||
|
||||
/// <summary>
|
||||
/// search pdf books pages for a text
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="term"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>> SearchPDFBookForPDFPagesTextAsync(PagingParameterModel paging, string term);
|
||||
|
||||
/// <summary>
|
||||
/// search pdf pages
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="bookId">0 for all pdf books</param>
|
||||
/// <param name="term"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, PDFPage[] Items)>> SearchPDFPagesTextAsync(PagingParameterModel paging, int bookId, string term);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1291,14 +1291,13 @@ namespace RMuseum.Services.Implementation
|
||||
try
|
||||
{
|
||||
term = term.Trim().ApplyCorrectYeKe();
|
||||
|
||||
if (string.IsNullOrEmpty(term))
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), "خطای جستجوی عبارت خالی");
|
||||
}
|
||||
|
||||
term = term.Replace("", " ");//replace zwnj with space
|
||||
|
||||
if (string.IsNullOrEmpty(term) || term.Length < 2)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), "خطای طول عبارت جستجو");
|
||||
}
|
||||
|
||||
string searchConditions;
|
||||
if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))
|
||||
{
|
||||
@ -1637,6 +1636,128 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// search pdf books pages for a text
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="term"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>> SearchPDFBookForPDFPagesTextAsync(PagingParameterModel paging, string term)
|
||||
{
|
||||
try
|
||||
{
|
||||
term = term.Trim().ApplyCorrectYeKe();
|
||||
term = term.Replace("", " ");//replace zwnj with space
|
||||
|
||||
if (string.IsNullOrEmpty(term) || term.Length < 2)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), "خطای طول عبارت جستجو");
|
||||
}
|
||||
|
||||
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 ";
|
||||
}
|
||||
}
|
||||
//full text catalogue should be created manually
|
||||
|
||||
var source =
|
||||
_context.PDFBooks.AsNoTracking().Include(a => a.Pages)
|
||||
.Where(p =>
|
||||
p.Status == PublishStatus.Published
|
||||
&&
|
||||
p.Pages.Where(t => EF.Functions.Contains(t.PageText, searchConditions)).Any()
|
||||
).OrderBy(i => i.Title);
|
||||
|
||||
|
||||
(PaginationMetadata PagingMeta, PDFBook[] Items) paginatedResult =
|
||||
await QueryablePaginator<PDFBook>.Paginate(source, paging);
|
||||
|
||||
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>(paginatedResult);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Items)>((null, null), exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// search pdf pages
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="bookId">0 for all pdf books</param>
|
||||
/// <param name="term"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, PDFPage[] Items)>> SearchPDFPagesTextAsync(PagingParameterModel paging, int bookId, string term)
|
||||
{
|
||||
try
|
||||
{
|
||||
term = term.Trim().ApplyCorrectYeKe();
|
||||
term = term.Replace("", " ");//replace zwnj with space
|
||||
|
||||
if (string.IsNullOrEmpty(term) || term.Length < 2)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFPage[] Items)>((null, null), "خطای طول عبارت جستجو");
|
||||
}
|
||||
|
||||
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 ";
|
||||
}
|
||||
}
|
||||
//full text catalogue should be created manually
|
||||
|
||||
var source =
|
||||
_context.PDFPages.AsNoTracking()
|
||||
.Where(p =>
|
||||
(bookId == 0 || p.PDFBookId == bookId)
|
||||
&&
|
||||
EF.Functions.Contains(p.PageText, searchConditions)
|
||||
).OrderBy(i => i.PageNumber);
|
||||
|
||||
|
||||
(PaginationMetadata PagingMeta, PDFPage[] Items) paginatedResult =
|
||||
await QueryablePaginator<PDFPage>.Paginate(source, paging);
|
||||
|
||||
foreach (PDFPage page in paginatedResult.Items)
|
||||
{
|
||||
page.PDFBook = await _context.PDFBooks.AsNoTracking().Where(b => b.Id == page.PDFBookId).SingleAsync();
|
||||
}
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFPage[] Items)>(paginatedResult);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PDFPage[] Items)>((null, null), exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Database Context
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user