private ActionResult GetSearchCorpusInSnapshotResult(long snapshotId, BookPagedCorpusSearchInSnapshotRequestContract request)
        {
            var client = GetBookClient();
            var result = client.SearchCorpusInSnapshot(snapshotId, request);

            return(Json(new { results = result }));
        }
Example #2
0
 public IActionResult SearchCorpusInSnapshotResult(long snapshotId, [FromBody] BookPagedCorpusSearchInSnapshotRequestContract request)
 {
     try
     {
         var result = m_bookSearchManager.SearchCorpusInSnapshotByCriteria(snapshotId, request);
         return(Ok(result));
     }
     catch (ArgumentException exception)
     {
         return(BadRequest(exception.Message));
     }
     catch (HttpErrorCodeException exception)
     {
         return(StatusCode((int)exception.StatusCode, exception.Message));
     }
 }
Example #3
0
        public List <CorpusSearchResultContract> SearchCorpusInSnapshotByCriteria(long snapshotId, int start, int count, int contextLength, List <SearchCriteriaContract> searchCriterias)
        {
            var searchRequest = new BookPagedCorpusSearchInSnapshotRequestContract {
                Start = start, Count = count, ContextLength = contextLength, ConditionConjunction = searchCriterias
            };

            try
            {
                var result = m_client.Post <List <CorpusSearchResultContract> >($"bookpagedcorpus/snapshot/{snapshotId}/search", searchRequest);
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Example #4
0
        public List <CorpusSearchResultContract> SearchCorpusInSnapshotByCriteria(long snapshotId, BookPagedCorpusSearchInSnapshotRequestContract request)
        {
            m_authorizationManager.AuthorizeSnapshot(snapshotId);

            var processedCriterias   = GetAuthorizatedProcessedCriterias(request.ConditionConjunction);
            var nonMetadataCriterias = processedCriterias.NonMetadataCriterias;

            // Search in fulltext DB
            var snapshotInfo    = m_snapshotRepository.InvokeUnitOfWork(x => x.GetSnapshot(snapshotId));
            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(snapshotInfo.Project.ProjectType);
            var start           = m_corpusSearchManager.GetCorpusStart(request.Start);
            var count           = m_corpusSearchManager.GetCorpusCount(request.Count);
            var contextLength   = m_corpusSearchManager.GetContextLength(request.ContextLength);

            var result = fulltextStorage.SearchCorpusInSnapshotByCriteria(snapshotId, start, count, contextLength, nonMetadataCriterias);

            switch (result.SearchResultType)
            {
            case FulltextSearchResultType.ProjectId:
                return(m_corpusSearchManager.GetCorpusSearchResultByStandardIds(result.List));

            case FulltextSearchResultType.ProjectExternalId:
                return(m_corpusSearchManager.GetCorpusSearchResultByExternalIds(result.List, snapshotInfo.Project.ProjectType));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public ActionResult <List <CorpusSearchResultContract> > SearchCorpusSnapshot(long snapshotId, [FromBody] BookPagedCorpusSearchInSnapshotRequestContract searchRequest)
        {
            if (ContainsAnyUnsupportedCriteria(searchRequest))
            {
                return(BadRequest("Request contains unsupported criteria"));
            }

            var result = m_searchManager.SearchCorpusSnapshotByCriteria(snapshotId, searchRequest);

            return(result);
        }
Example #6
0
        public List <CorpusSearchResultContract> SearchCorpusInSnapshot(long snapshotId, BookPagedCorpusSearchInSnapshotRequestContract request)
        {
            try
            {
                var result = m_client.Post <List <CorpusSearchResultContract> >($"bookpagedcorpus/snapshot/{snapshotId}/search", request);
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Example #7
0
        public List <CorpusSearchResultContract> SearchCorpusSnapshotByCriteria(long snapshotId, BookPagedCorpusSearchInSnapshotRequestContract searchRequest)
        {
            var queriesBuilder = m_queriesBuilderFactory.Create(IndexType.Snapshot);
            var mustQuery      = queriesBuilder.GetSearchQuery(searchRequest.ConditionConjunction, SnapshotTextField);
            var filterQuery    = queriesBuilder.GetFilterByFieldSearchQuery(SnapshotIdField, snapshotId.ToString());

            var client = m_communicationProvider.GetElasticClient();


            var response = client.Search <SnapshotResourceContract>(s => s
                                                                    .Index(SnapshotIndex)
                                                                    .Type(SnapshotType)
                                                                    .Source(sf => sf
                                                                            .IncludeAll()
                                                                            .Excludes(i => i
                                                                                      .Fields(
                                                                                          f => f.SnapshotText
                                                                                          )
                                                                                      )
                                                                            )
                                                                    .Query(q => q
                                                                           .Bool(b => b
                                                                                 .Filter(filterQuery)
                                                                                 .Must(mustQuery)
                                                                                 )
                                                                           )
                                                                    .Highlight(h => h
                                                                               .PreTags(HighlightTag)
                                                                               .PostTags(HighlightTag)
                                                                               .Fields(f => f
                                                                                       .Field(SnapshotTextField)
                                                                                       .NumberOfFragments(FragmentsCount)
                                                                                       .FragmentSize(searchRequest.ContextLength)
                                                                                       .Type(HighlighterType)
                                                                                       )
                                                                               )
                                                                    );

            return(m_searchResultProcessor.ProcessSearchCorpusSnapshotByCriteria(response, HighlightTag, searchRequest.Start ?? DefaultStart, searchRequest.Count ?? DefaultSize));
        }