Beispiel #1
0
        public List <CorpusSearchResultContract> SearchCorpusByCriteria(CorpusSearchRequestContract request, ProjectTypeContract projectType)
        {
            var processedCriterias = GetAuthorizatedProcessedCriterias(request.ConditionConjunction);

            var nonMetadataCriterias = processedCriterias.NonMetadataCriterias;

            var projectIdentificatorList = GetProjectIdentificatorList(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectType);

            if (projectIdentificatorList.Count == 0)
            {
                return(new List <CorpusSearchResultContract>());
            }

            // Search in fulltext DB
            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectType);
            var start           = m_corpusSearchManager.GetCorpusStart(request.Start);
            var count           = m_corpusSearchManager.GetCorpusCount(request.Count);
            var result          = fulltextStorage.SearchCorpusByCriteria(start, count, request.ContextLength, request.Sort, request.SortDirection, nonMetadataCriterias, projectIdentificatorList);

            var projectTypeEnum = m_mapper.Map <ProjectTypeEnum>(projectType);

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

            case FulltextSearchResultType.ProjectExternalId:
                return(m_corpusSearchManager.GetCorpusSearchResultByExternalIds(result.List, projectTypeEnum));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        public List <CorpusSearchResultContract> SearchCorpusByCriteria(CorpusSearchRequestContract searchRequest)
        {
            var filterQuery =
                m_queriesBuilder.GetFilterSearchQuery(searchRequest.ConditionConjunction, SnapshotIdField);
            var mustQuery = m_queriesBuilder.GetSearchQuery(searchRequest.ConditionConjunction, SnapshotTextField);

            var client = m_communicationProvider.GetElasticClient();

            /*
             * var responseCount = client.Search<SnapshotResourceContract>(s => s
             *  .Index(SnapshotIndex)
             *  .Type(SnapshotType)
             *  .From(0)
             *  .Size(0)
             *  .Query(q => q
             *      .Bool(b => b
             *          .Filter(filterQuery)
             *          .Must(mustQuery)
             *      )
             *  )
             * );
             */
            var index    = searchRequest.Start / searchRequest.Count;
            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)
                                                                                 )
                                                                           )
                                                                    .From(index ?? SearchManager.DefaultStart)
                                                                    .Size(1)
                                                                    .Highlight(h => h
                                                                               .PreTags(SearchManager.HighlightTag)
                                                                               .PostTags(SearchManager.HighlightTag)
                                                                               .Fields(f => f
                                                                                       .Field(SnapshotTextField)
                                                                                       .NumberOfFragments(SearchManager.FragmentsCount)
                                                                                       .FragmentSize(SearchManager.FragmentSize)
                                                                                       .Type(SearchManager.HighlighterType)
                                                                                       )
                                                                               )
                                                                    );

            return(m_searchResultProcessor.ProcessSearchCorpusByCriteria(response, SearchManager.HighlightTag));
        }
Beispiel #3
0
        public ActionResult <long> SearchCorpusResultCount([FromBody] CorpusSearchRequestContract searchRequest)
        {
            if (ContainsAnyUnsupportedCriteria(searchRequest))
            {
                return(BadRequest("Request contains unsupported criteria"));
            }

            var result = m_searchManager.SearchCorpusByCriteriaCount(searchRequest);

            return(result.Count);
        }
        public long SearchCorpusCount(CorpusSearchRequestContract request, ProjectTypeContract projectType)
        {
            try
            {
                var result = m_client.Post <long>($"corpus/search-count?projectType={projectType}", request);
                return(result);
            }
            catch (HttpRequestException e)
            {
                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e);
                }

                throw;
            }
        }
Beispiel #5
0
        public long SearchCorpusByCriteriaCount(CorpusSearchRequestContract request, ProjectTypeContract projectType)
        {
            var processedCriterias = GetAuthorizatedProcessedCriterias(request.ConditionConjunction);

            var nonMetadataCriterias = processedCriterias.NonMetadataCriterias;

            var projectIdentificatorList = GetProjectIdentificatorList(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectType);

            if (projectIdentificatorList.Count == 0)
            {
                return(0);
            }

            // Search in fulltext DB
            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectType);
            var resultCount     = fulltextStorage.SearchCorpusByCriteriaCount(nonMetadataCriterias, projectIdentificatorList);

            return(resultCount);
        }
        public List <CorpusSearchResultContract> SearchCorpusByCriteria(int start, int count, int contextLength, List <SearchCriteriaContract> searchCriterias)
        {
            var searchRequest = new CorpusSearchRequestContract {
                Start = start, Count = count, ContextLength = contextLength, ConditionConjunction = searchCriterias
            };

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

                throw;
            }
        }
Beispiel #7
0
        public IActionResult SearchCorpusResultCount([FromBody] CorpusSearchRequestContract request, [FromQuery] ProjectTypeContract?projectType)
        {
            if (projectType == null)
            {
                return(Error($"Required parameter {nameof(projectType)} is not specified"));
            }

            try
            {
                var result = m_bookSearchManager.SearchCorpusByCriteriaCount(request, projectType.Value);
                return(Ok(result));
            }
            catch (ArgumentException exception)
            {
                return(BadRequest(exception.Message));
            }
            catch (HttpErrorCodeException exception)
            {
                return(StatusCode((int)exception.StatusCode, exception.Message));
            }
        }