public HitsWithPageContextResultContract SearchHitsWithPageContext(long snapshotId, int start, int count, int contextLength, List <SearchCriteriaContract> criteria) { var searchRequest = new SearchHitsRequestContract { Start = start, Count = count, ContextLength = contextLength, ConditionConjunction = criteria }; try { var result = m_client.Post <HitsWithPageContextResultContract>($"text/snapshot/{snapshotId}/search-context", searchRequest); return(result); } catch (HttpRequestException e) { if (m_logger.IsErrorEnabled()) { m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e); } throw; } }
public IActionResult SearchHitsResultCount(long projectId, [FromBody] SearchHitsRequestContract request) { try { var resultCount = m_bookHitSearchManager.SearchHitsResultCount(projectId, request); return(Ok(resultCount)); } catch (ArgumentException exception) { return(BadRequest(exception.Message)); } catch (HttpErrorCodeException exception) { return(StatusCode((int)exception.StatusCode, exception.Message)); } }
public long SearchHitsResultCount(long projectId, SearchHitsRequestContract request) { try { var result = m_client.Post <long>($"book/{projectId}/hit/search-count", request); return(result); } catch (HttpRequestException e) { if (m_logger.IsErrorEnabled()) { m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e); } throw; } }
public long SearchHitsResultCount(long projectId, SearchHitsRequestContract request) { m_authorizationManager.AuthorizeBook(projectId, PermissionFlag.ShowPublished); var fulltextConditions = ExtractFulltextConditions(request.ConditionConjunction); if (fulltextConditions.Count == 0) { throw new MainServiceException(MainServiceErrorCode.NoSupportedSearch, "No supported search criteria was specified" ); } var projectIdentification = m_bookRepository.InvokeUnitOfWork(x => x.GetProjectIdentification(projectId)); var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectIdentification.ProjectType); var fulltextResultCount = fulltextStorage.SearchHitsResultCount(fulltextConditions, projectIdentification); return(fulltextResultCount); }
public ActionResult <HitsWithPageContextResultContract> SearchHitsWithPageContext(long snapshotId, [FromBody] SearchHitsRequestContract searchHitsRequestContract) { if (ContainsAnyUnsupportedCriteria(searchHitsRequestContract)) { return(BadRequest("Request contains unsupported criteria")); } var result = m_searchManager.SearchHitsWithPageContext(snapshotId, searchHitsRequestContract); return(result); }
public List <PageResultContextContract> SearchHitsWithPageContext(long projectId, SearchHitsRequestContract request) { m_authorizationManager.AuthorizeBook(projectId, PermissionFlag.ShowPublished); var fulltextConditions = ExtractFulltextConditions(request.ConditionConjunction); if (fulltextConditions.Count == 0) { throw new MainServiceException(MainServiceErrorCode.NoSupportedSearch, "No supported search criteria was specified" ); } var projectIdentification = m_bookRepository.InvokeUnitOfWork(x => x.GetProjectIdentification(projectId)); var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectIdentification.ProjectType); var start = PagingHelper.GetStart(request.Start); var count = PagingHelper.GetCount(request.Count); var fulltextResult = fulltextStorage.SearchHitsWithPageContext(start, count, request.ContextLength, fulltextConditions, projectIdentification); switch (fulltextResult.SearchResultType) { case PageSearchResultType.TextId: return(ConvertSearchResultsByStandardId(fulltextResult.ResultList)); case PageSearchResultType.TextExternalId: return(ConvertSearchResultsByExternalId(projectId, fulltextResult.ResultList)); default: throw new ArgumentOutOfRangeException(); } }
public HitsWithPageContextResultContract SearchHitsWithPageContext(long snapshotId, SearchHitsRequestContract searchRequest) { var pageList = GetSnapshotPages(snapshotId); var client = m_communicationProvider.GetElasticClient(); var queriesBuilder = m_queriesBuilderFactory.Create(IndexType.Page); var filterQuery = queriesBuilder.GetFilterByIdSearchQuery(pageList.Select(x => x.Id).ToList()); var mustQuery = queriesBuilder.GetSearchQuery(searchRequest.ConditionConjunction, PageTextField); var pageResponse = client.Search <TextResourceContract>(s => s .Index(PageIndex) .Type(PageType) .Source(sf => sf.Excludes(i => i.Field(f => f.PageText))) .Query(q => q .Bool(b => b .Filter(filterQuery) .Must(mustQuery) ) ) .Highlight(h => h .PreTags(HighlightTag) .PostTags(HighlightTag) .Fields(f => f .Field(PageTextField) .NumberOfFragments(FragmentsCount) .FragmentSize(searchRequest.ContextLength) .Type(HighlighterType) ) ) .Size(DefaultSize) //WORKAROUND get all hits and create paging manually, so specify big enough number ); return(m_searchResultProcessor.ProcessSearchHitsWithPageContext(pageResponse, pageList, HighlightTag, searchRequest.Start ?? DefaultStart, searchRequest.Count ?? DefaultSize)); }