Example #1
0
        private ResultSearchCriteriaContract GetFilteredResultSearchCriterias(IList <SearchCriteriaContract> searchCriterias)
        {
            ResultRestrictionCriteriaContract resultRestrictionCriteriaContract = null;
            ResultCriteriaContract            resultCriteriaContract            = null;

            RegexCriteriaBuilder.ConvertWildcardToRegex(searchCriterias);
            var filteredCriterias = new List <SearchCriteriaContract>();

            foreach (var searchCriteriaContract in searchCriterias)
            {
                if (m_searchCriteriaDirector.IsCriteriaSupported(searchCriteriaContract))
                {
                    filteredCriterias.Add(RegexCriteriaBuilder.ConvertToRegexCriteria(searchCriteriaContract));
                }
                else if (searchCriteriaContract.Key == CriteriaKey.ResultRestriction)
                {
                    resultRestrictionCriteriaContract = (ResultRestrictionCriteriaContract)searchCriteriaContract;
                }
                else if (searchCriteriaContract.Key == CriteriaKey.Result)
                {
                    resultCriteriaContract = (ResultCriteriaContract)searchCriteriaContract;
                }
            }

            return(new ResultSearchCriteriaContract
            {
                ConjunctionSearchCriterias = filteredCriterias,
                ResultSpecifications = resultCriteriaContract,
                ResultBooks = resultRestrictionCriteriaContract != null
                    ? resultRestrictionCriteriaContract.ResultBooks
                    : null,
            });
        }
Example #2
0
        public int GetCorpusSearchResultsCount(IEnumerable <SearchCriteriaContract> searchCriterias)
        {
            var criterias = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(criterias);

            var filteredCriterias    = FilterSearchCriterias(criterias);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;
            var creator = new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery,
                                                         filteredCriterias.MetadataParameters);
            var databaseSearchResult = m_bookVersionRepository.SearchByCriteriaQuery(creator);

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

            if (nonMetadataCriterias.All(x => x.Key == CriteriaKey.Result))
            {
                // Search only in SQL
                return(databaseSearchResult.Count);
            }

            // Fulltext search
            var resultContract = new ResultRestrictionCriteriaContract
            {
                ResultBooks = databaseSearchResult
            };

            nonMetadataCriterias.Add(resultContract);

            return(m_searchServiceClient.GetCorpusSearchResultsCount(nonMetadataCriterias));
        }
Example #3
0
        public int SearchHeadwordByCriteriaResultsCount(IEnumerable <SearchCriteriaContract> searchCriterias,
                                                        DictionarySearchTarget searchTarget)
        {
            var criterias = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(criterias);

            var filteredCriterias    = FilterSearchCriterias(criterias);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;
            var creator = new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery, filteredCriterias.MetadataParameters);

            // Only SQL search
            if (searchTarget == DictionarySearchTarget.Headword)
            {
                var query = GetSingleHeadwordQuery(filteredCriterias.MetadataCriterias);
                if (query == null)
                {
                    return(0);
                }

                creator.SetHeadwordQueryParameter(query);

                var resultCount = m_bookVersionRepository.GetSearchHeadwordCount(creator);
                return(resultCount);
            }

            // Advanced search
            var databaseSearchResult = m_bookVersionRepository.SearchByCriteriaQuery(creator);

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

            if (nonMetadataCriterias.All(x => x.Key == CriteriaKey.Result))
            {
                // Search only in SQL
                var headwordQueryCreator = new HeadwordCriteriaQueryCreator();
                headwordQueryCreator.AddCriteria(filteredCriterias.MetadataCriterias);
                var bookGuidList = databaseSearchResult.Select(x => x.Guid);
                var resultCount  = m_bookVersionRepository.GetHeadwordCountBySearchCriteria(bookGuidList, headwordQueryCreator);
                return(resultCount);
            }

            // Fulltext search
            var resultContract = new ResultRestrictionCriteriaContract
            {
                ResultBooks = databaseSearchResult
            };
            var headwordContracts = filteredCriterias.MetadataCriterias.Where(x => x.Key == CriteriaKey.Headword);

            nonMetadataCriterias.Add(resultContract);
            nonMetadataCriterias.AddRange(headwordContracts);

            return(m_searchServiceClient.ListSearchDictionariesResultsCount(nonMetadataCriterias));
        }
Example #4
0
        public AudioBookSearchResultContractList GetAudioBookSearchResults(IEnumerable <SearchCriteriaContract> searchCriterias)
        {
            var criterias = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(criterias);

            var filteredCriterias    = FilterSearchCriterias(criterias);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;

            if (nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().FirstOrDefault() == null)
            {
                var databaseSearchResult =
                    m_bookVersionRepository.SearchByCriteriaQuery(new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery,
                                                                                                 filteredCriterias.MetadataParameters));

                if (databaseSearchResult.Count == 0)
                {
                    return(new AudioBookSearchResultContractList());
                }

                var resultContract = new ResultRestrictionCriteriaContract
                {
                    ResultBooks = databaseSearchResult
                };
                nonMetadataCriterias.Add(resultContract);
            }

            // Search only in SQL
            var resultRestriction   = nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().First();
            var guidListRestriction = resultRestriction.ResultBooks.Select(x => x.Guid).ToList();
            var resultBookVersions  = m_bookVersionRepository.GetBookVersionDetailsByGuid(guidListRestriction);

            var audibookList = new List <AudioBookSearchResultContract>();

            foreach (var bookVersion in resultBookVersions)
            {
                var fullBookRecordings = m_bookVersionRepository.GetFullBookRecordings(bookVersion.Id);

                var audioBook = Mapper.Map <AudioBookSearchResultContract>(bookVersion);
                audioBook.FullBookRecordings = Mapper.Map <IList <RecordingContract> >(fullBookRecordings);

                audibookList.Add(audioBook);
            }

            var resultList = new AudioBookSearchResultContractList
            {
                Results = audibookList
            };

            return(resultList);
        }
Example #5
0
        private void UpdateCriteriaWithBookVersionRestriction(List <SearchCriteriaContract> criteria,
                                                              IList <ProjectIdentificationResult> projects)
        {
            var resultBooks = projects.Select(x => new BookVersionPairContract
            {
                Guid      = x.ProjectExternalId,
                VersionId = x.BookVersionExternalId,
            }).ToList();

            var bookVersionRestrictionCriteria = new ResultRestrictionCriteriaContract
            {
                ResultBooks = resultBooks,
            };

            criteria.Add(bookVersionRestrictionCriteria);
        }
Example #6
0
        public CorpusSearchResultContractList GetCorpusSearchResults(IEnumerable <SearchCriteriaContract> searchCriterias)
        {
            var criterias = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(criterias);

            var filteredCriterias    = FilterSearchCriterias(criterias);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;

            if (nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().FirstOrDefault() == null)
            {
                var databaseSearchResult =
                    m_bookVersionRepository.SearchByCriteriaQuery(new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery,
                                                                                                 filteredCriterias.MetadataParameters));

                if (databaseSearchResult.Count == 0)
                {
                    return(new CorpusSearchResultContractList());
                }

                var resultContract = new ResultRestrictionCriteriaContract
                {
                    ResultBooks = databaseSearchResult
                };
                nonMetadataCriterias.Add(resultContract);
            }

            if (filteredCriterias.NonMetadataCriterias.All(x => x.Key == CriteriaKey.ResultRestriction || x.Key == CriteriaKey.Result))
            {
                // Search only in SQL
                var resultRestriction   = nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().First();
                var guidListRestriction = resultRestriction.ResultBooks.Select(x => x.Guid).ToList();
                var resultBookVersions  = m_bookVersionRepository.GetBookVersionDetailsByGuid(guidListRestriction);
                var results             = Mapper.Map <IList <CorpusSearchResultContract> >(resultBookVersions);
                var resultList          = new CorpusSearchResultContractList
                {
                    SearchResults = results
                };

                return(resultList);
            }

            // Fulltext search
            var searchResults = m_searchServiceClient.GetCorpusSearchResults(nonMetadataCriterias);

            var guidList = searchResults.SearchResults.Select(x => x.BookXmlId).ToList();
            var result   = m_bookVersionRepository.GetBookVersionDetailsByGuid(guidList);

            var resultDictionary = result.ToDictionary(x => x.Book.Guid);

            var searchResultFullContext = new List <CorpusSearchResultContract>();

            foreach (var searchResult in searchResults.SearchResults)
            {
                var localResult = Mapper.Map <CorpusSearchResultContract>(resultDictionary[searchResult.BookXmlId]);
                localResult.Notes              = searchResult.Notes;
                localResult.PageResultContext  = searchResult.PageResultContext;
                localResult.VerseResultContext = searchResult.VerseResultContext;
                searchResultFullContext.Add(localResult);
            }

            var searchList = new CorpusSearchResultContractList
            {
                SearchResults = searchResultFullContext
            };

            return(searchList);
        }
Example #7
0
        public HeadwordListContract SearchHeadwordByCriteria(IEnumerable <SearchCriteriaContract> searchCriterias, DictionarySearchTarget searchTarget)
        {
            var criterias = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(criterias);

            var filteredCriterias = FilterSearchCriterias(criterias);
            var resultCriteria    = filteredCriterias.ResultCriteria;
            var creator           = new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery, filteredCriterias.MetadataParameters);

            // Only SQL search
            if (searchTarget == DictionarySearchTarget.Headword)
            {
                if (resultCriteria.Start == null || resultCriteria.Count == null)
                {
                    return(null);
                }

                var query = GetSingleHeadwordQuery(filteredCriterias.MetadataCriterias);
                if (query == null)
                {
                    return(new HeadwordListContract());
                }

                creator.SetHeadwordQueryParameter(query);

                var databaseHeadwords = m_bookVersionRepository.SearchHeadwordByCriteria(creator, resultCriteria.Start.Value, resultCriteria.Count.Value);

                return(ConvertHeadwordSearchToContract(databaseHeadwords));
            }

            // Advanced search
            var databaseSearchResult = m_bookVersionRepository.SearchByCriteriaQuery(creator);

            if (databaseSearchResult.Count == 0)
            {
                return new HeadwordListContract
                       {
                           BookList     = new Dictionary <string, DictionaryContract>(),
                           HeadwordList = new List <HeadwordContract>()
                       }
            }
            ;

            if (filteredCriterias.NonMetadataCriterias.All(x => x.Key == CriteriaKey.Result))
            {
                // Search only in SQL
                if (resultCriteria.Start == null || resultCriteria.Count == null)
                {
                    return(null);
                }

                var headwordQueryCreator = new HeadwordCriteriaQueryCreator();

                headwordQueryCreator.AddCriteria(filteredCriterias.MetadataCriterias);
                var bookGuidList    = databaseSearchResult.Select(x => x.Guid);
                var resultHeadwords = m_bookVersionRepository.GetHeadwordListBySearchCriteria(bookGuidList, headwordQueryCreator,
                                                                                              resultCriteria.Start.Value, resultCriteria.Count.Value);
                return(ConvertHeadwordSearchToContract(resultHeadwords));
            }

            // Fulltext search
            var resultRestrictionContract = new ResultRestrictionCriteriaContract
            {
                ResultBooks = databaseSearchResult
            };
            var headwordContracts    = filteredCriterias.MetadataCriterias.Where(x => x.Key == CriteriaKey.Headword);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;

            nonMetadataCriterias.Add(resultRestrictionContract);
            nonMetadataCriterias.AddRange(headwordContracts);

            var resultContract = m_searchServiceClient.ListSearchDictionariesResults(nonMetadataCriterias);

            // fill book info
            var bookInfoList      = m_bookVersionRepository.GetBookVersionsByGuid(resultContract.BookList.Keys.ToList());
            var bookInfoContracts = Mapper.Map <IList <DictionaryContract> >(bookInfoList);
            var bookDictionary    = bookInfoContracts.ToDictionary(x => x.BookXmlId, x => x);

            resultContract.BookList = bookDictionary;

            return(resultContract);
        }
Example #8
0
        public IEnumerable <SearchResultContract> SearchByCriteria(IEnumerable <SearchCriteriaContract> searchCriterias)
        {
            var searchCriteriaContracts = searchCriterias.ToList();

            m_authorizationManager.AuthorizeCriteria(searchCriteriaContracts);

            var filteredCriterias    = FilterSearchCriterias(searchCriteriaContracts);
            var nonMetadataCriterias = filteredCriterias.NonMetadataCriterias;
            var resultCriteria       = filteredCriterias.ResultCriteria;

            var queryCreator = new SearchCriteriaQueryCreator(filteredCriterias.ConjunctionQuery, filteredCriterias.MetadataParameters);

            if (nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().FirstOrDefault() == null)
            {
                var databaseSearchResult = m_bookVersionRepository.SearchByCriteriaQuery(queryCreator);

                if (databaseSearchResult.Count == 0)
                {
                    return(new List <SearchResultContract>());
                }

                var resultContract = new ResultRestrictionCriteriaContract
                {
                    ResultBooks = databaseSearchResult
                };
                nonMetadataCriterias.Add(resultContract);
            }

            var resultCriteriaContract = nonMetadataCriterias.OfType <ResultCriteriaContract>().FirstOrDefault();

            Dictionary <long, List <PageDescriptionContract> > bookTermResults = null;
            Dictionary <long, long> bookTermResultsCount = null;

            if (filteredCriterias.NonMetadataCriterias.All(x => x.Key == CriteriaKey.ResultRestriction || x.Key == CriteriaKey.Result))
            {
                // Search only in SQL
                var resultRestriction   = nonMetadataCriterias.OfType <ResultRestrictionCriteriaContract>().First();
                var guidListRestriction = resultRestriction.ResultBooks.Select(x => x.Guid).ToList();
                var resultBookVersions  = m_bookVersionRepository.GetBookVersionDetailsByGuid(guidListRestriction, resultCriteria.Start,
                                                                                              resultCriteria.Count, resultCriteria.Sorting, resultCriteria.Direction);
                var pageCounts = m_bookVersionRepository.GetBooksPageCountByGuid(guidListRestriction)
                                 .ToDictionary(x => x.BookId, x => x.Count);


                if (resultCriteriaContract != null && resultCriteriaContract.TermsSettingsContract != null)
                {
                    var termQueryCreator = new TermCriteriaQueryCreator();
                    termQueryCreator.AddCriteria(filteredCriterias.MetadataCriterias);

                    var booksTermResults = m_bookVersionRepository.GetBooksTermResults(guidListRestriction, termQueryCreator);
                    bookTermResults =
                        booksTermResults.GroupBy(x => x.BookId, x => new PageDescriptionContract {
                        PageName = x.PageName, PageXmlId = x.PageXmlId
                    })
                        .ToDictionary(x => x.Key, x => x.ToList());

                    var booksTermResultsCount = m_bookVersionRepository.GetBooksTermResultsCount(guidListRestriction, termQueryCreator);
                    bookTermResultsCount = booksTermResultsCount.ToDictionary(x => x.BookId, x => x.PagesCount);
                }

                var resultContractList = Mapper.Map <IList <SearchResultContract> >(resultBookVersions);

                foreach (var resultContract in resultContractList)
                {
                    resultContract.PageCount = pageCounts[resultContract.BookId];

                    if (bookTermResults != null)
                    {
                        List <PageDescriptionContract> pageDescriptionContracts;
                        long termResultsCount;
                        resultContract.TermsPageHits = bookTermResults.TryGetValue(resultContract.BookId, out pageDescriptionContracts)
                            ? pageDescriptionContracts
                            : new List <PageDescriptionContract>();
                        resultContract.TermsPageHitsCount = bookTermResultsCount.TryGetValue(resultContract.BookId, out termResultsCount)
                            ? Convert.ToInt32(termResultsCount)
                            : 0;
                    }
                }

                return(resultContractList);
            }

            // Fulltext search
            var searchResults = m_searchServiceClient.ListSearchEditionsResults(nonMetadataCriterias);

            var guidList = searchResults.SearchResults.Select(x => x.BookXmlId).ToList();
            var result   = m_bookVersionRepository.GetBookVersionDetailsByGuid(guidList);
            var resultPageCountDictionary = m_bookVersionRepository.GetBooksPageCountByGuid(guidList)
                                            .ToDictionary(x => x.BookId, x => x.Count);

            var resultDictionary = result.ToDictionary(x => x.Book.Guid);


            if (resultCriteriaContract != null && resultCriteriaContract.TermsSettingsContract != null)
            {
                var termQueryCreator = new TermCriteriaQueryCreator();
                termQueryCreator.AddCriteria(filteredCriterias.MetadataCriterias);

                var booksTermResults = m_bookVersionRepository.GetBooksTermResults(guidList, termQueryCreator);
                bookTermResults =
                    booksTermResults.GroupBy(x => x.BookId, x => new PageDescriptionContract {
                    PageName = x.PageName, PageXmlId = x.PageXmlId
                })
                    .ToDictionary(x => x.Key, x => x.ToList());

                var booksTermResultsCount = m_bookVersionRepository.GetBooksTermResultsCount(guidList, termQueryCreator);
                bookTermResultsCount = booksTermResultsCount.ToDictionary(x => x.BookId, x => x.PagesCount);
            }

            var searchResultFullContext = new List <SearchResultContract>();


            foreach (var searchResult in searchResults.SearchResults)
            {
                var localResult = Mapper.Map <SearchResultContract>(resultDictionary[searchResult.BookXmlId]);
                localResult.TotalHitCount = searchResult.TotalHitCount;
                localResult.Results       = searchResult.Results;
                localResult.PageCount     = resultPageCountDictionary[localResult.BookId];

                if (bookTermResults != null)
                {
                    List <PageDescriptionContract> pageDescriptionContracts;
                    long termResultsCount;
                    localResult.TermsPageHits = bookTermResults.TryGetValue(localResult.BookId, out pageDescriptionContracts)
                        ? pageDescriptionContracts
                        : new List <PageDescriptionContract>();
                    localResult.TermsPageHitsCount = bookTermResultsCount.TryGetValue(localResult.BookId, out termResultsCount)
                        ? Convert.ToInt32(termResultsCount)
                        : 0;
                }

                searchResultFullContext.Add(localResult);
            }

            return(searchResultFullContext);
        }