Пример #1
0
        public SnapshotResourceContract GetSnapshotResourceFromPageIds(List <string> orderedPageIds)
        {
            StringBuilder snapshotBuilder = new StringBuilder();

            var pages     = new List <SnapshotPageResourceContract>();
            int pageIndex = 0;

            foreach (var pageId in orderedPageIds)
            {
                var textResource = m_textResourceManager.GetTextResource(pageId);

                var pageTextWithoutMarkdown = m_markdownToPlainTextConverter.Convert(textResource.PageText);

                var pageTextWithIndex = InsertPageIndexIntoPageText(pageTextWithoutMarkdown, pageIndex);
                var page = new SnapshotPageResourceContract {
                    Id = pageId, PageIndex = pageIndex
                };

                pages.Add(page);
                snapshotBuilder.Append(pageTextWithIndex);

                pageIndex++;
            }
            return(new SnapshotResourceContract {
                SnapshotText = snapshotBuilder.ToString(), Pages = pages
            });
        }
Пример #2
0
        public HitsWithPageContextResultContract ProcessSearchHitsWithPageContext(ISearchResponse <TextResourceContract> response, List <SnapshotPageResourceContract> pageList, string highlightTag, int start, int count)
        {
            if (!response.IsValid)
            {
                throw new FulltextDatabaseException(response.DebugInformation);
            }

            var sortedPageList = pageList.OrderBy(x => x.PageIndex);

            int startCounter = 0;

            var resultList = new List <PageResultContextData>();


            foreach (var page in sortedPageList)
            {
                foreach (var hit in response.Hits.Where(x => x.Id == page.Id))
                {
                    foreach (var value in hit.Highlights.Values)
                    {
                        foreach (var highlight in value.Highlights)
                        {
                            var highlightPlain = m_markdownToPlainTextConverter.Convert(highlight);

                            var numberOfOccurences = GetNumberOfHighlitOccurences(highlightPlain, highlightTag);

                            if (startCounter + numberOfOccurences <= start)
                            {
                                startCounter += numberOfOccurences;
                                continue;
                            }

                            var resultData = GetSearchHitsWithPageContextList(highlightPlain, hit.Id, highlightTag);

                            if (startCounter < start)
                            {
                                resultData.RemoveRange(0, start - startCounter);
                                startCounter += resultData.Count;
                            }

                            if (resultList.Count + resultData.Count > count)
                            {
                                resultData = resultData.GetRange(0, count - resultList.Count);
                            }

                            resultList.AddRange(resultData);

                            if (resultList.Count == count)
                            {
                                return new HitsWithPageContextResultContract {
                                           ResultList = resultList
                                }
                            }
                            ;
                        }
                    }
                }
            }
            return(new HitsWithPageContextResultContract {
                ResultList = resultList
            });
        }