protected List <CorpusSearchResultContract> GetCorpusSearchResultDataList(string highlightedText, long projectId, string highlightTag) { var result = new List <CorpusSearchResultContract>(); var index = highlightedText.IndexOf(highlightTag, StringComparison.Ordinal); do { var contextStructure = GetContextStructure(highlightedText, index, out index, highlightTag); if (contextStructure != null) { var corpusSearchResult = new CorpusSearchResultContract { ProjectId = projectId, PageResultContext = new CorpusSearchPageResultContract { ContextStructure = contextStructure }, }; result.Add(corpusSearchResult); } else { break; } index = highlightedText.IndexOf(highlightTag, index + highlightTag.Length, StringComparison.Ordinal); } while (index > 0); return(result); }
public void CorpusSearchResultContractDeserializationTest() { var notes = "<Notes xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><a:string>poznámka textová</a:string><a:string>cěstú</a:string></Notes>"; var stringResult = "<CorpusSearchResultContract xmlns=\"http://schemas.datacontract.org/2004/07/ITJakub.Shared.Contracts.Searching.Results\"><BookXmlId>{E494DBC5-F3C4-4841-B4D3-C52FE99839EB}</BookXmlId>" + notes + "<PageResultContext><ContextStructure><After>tvój.Protož konečně pravím to, že nikakež ode...</After><Before>...však s’ z břicha mého vyšel. Já jsem doma, ale ne </Before><Match>otec</Match></ContextStructure><PageName>1v</PageName><PageXmlId>t-1.body-1.div-1.div-1.p-1.pb-1</PageXmlId><VerseXmlId/><VerseName/></PageResultContext><VersionXmlId>0c6bfd7e-67d9-460d-89d0-90c069075969</VersionXmlId></CorpusSearchResultContract>"; var corpusResult = CorpusSearchResultContract.FromXml(stringResult); Assert.IsNotNull(corpusResult); }
public List <CorpusSearchResultContract> GetCorpusSearchResultByExternalIds(List <CorpusSearchResultData> list, ProjectTypeEnum projectType) { var projectExternalIds = list.Select(x => x.ProjectExternalId); var dbProjects = m_metadataRepository.InvokeUnitOfWork(x => x.GetMetadataByProjectExternalIds(projectExternalIds, projectType)); var bookDictionary = dbProjects.ToDictionary(x => x.Resource.Project.ExternalId); // Load all pages in one transaction var orderedPageResourceList = m_bookRepository.InvokeUnitOfWork(repository => { var result = new List <PageResource>(); foreach (var corpusSearchResultData in list) { var page = repository.GetPagesByTextExternalId(new [] { corpusSearchResultData.PageResultContext.TextExternalId }, corpusSearchResultData.ProjectExternalId, projectType); result.Add(page.First()); } return(result); }); // Process results var orderedResultList = new List <CorpusSearchResultContract>(); for (int i = 0; i < list.Count; i++) { var corpusResultData = list[i]; var pageInfo = orderedPageResourceList[i]; var projectMetadata = bookDictionary[corpusResultData.ProjectExternalId]; var pageContextContract = m_mapper.Map <PageWithContextContract>(pageInfo); pageContextContract.ContextStructure = corpusResultData.PageResultContext.ContextStructure; var corpusItemContract = new CorpusSearchResultContract { PageResultContext = pageContextContract, Author = projectMetadata.AuthorsLabel, BookId = projectMetadata.Resource.Project.Id, OriginDate = projectMetadata.OriginDate, RelicAbbreviation = projectMetadata.RelicAbbreviation, SourceAbbreviation = projectMetadata.SourceAbbreviation, Title = projectMetadata.Title, Notes = corpusResultData.Notes, BibleVerseResultContext = corpusResultData.BibleVerseResultContext, VerseResultContext = corpusResultData.VerseResultContext, }; orderedResultList.Add(corpusItemContract); } return(orderedResultList); }