private SearchDocument FromData(IData data, CultureInfo culture) { using (new DataScope(culture)) { string label = data.GetLabel(); if (string.IsNullOrEmpty(label)) { // Having a label is a requirement for a data item to be searchable return(null); } var docBuilder = new SearchDocumentBuilder(); docBuilder.SetDataType(_interfaceType); string documentId = GetDocumentId(data); if (InternalUrls.DataTypeSupported(_interfaceType) && (!_isPublishable || data.DataSourceId.PublicationScope == PublicationScope.Published)) { docBuilder.Url = InternalUrls.TryBuildInternalUrl(data.ToDataReference()); } docBuilder.CrawlData(data); var entityToken = GetConsoleEntityToken(data); if (entityToken == null) { Log.LogWarning(LogTitle, $"Failed to obtain an entity token for a data item of type '{data.DataSourceId.InterfaceType}'"); return(null); } return(docBuilder.BuildDocument(Name, documentId, label, null, entityToken)); } }
private SearchDocument FromPage(IPage page, EntityToken entityToken, Dictionary <Tuple <Guid, Guid>, List <IData> > allMetaData) { string label = page.MenuTitle; if (string.IsNullOrWhiteSpace(label)) { label = page.Title; } bool isPublished = page.DataSourceId.PublicationScope == PublicationScope.Published; string documentId = GetDocumentId(page); var docBuilder = new SearchDocumentBuilder(_docBuilderExtensions); docBuilder.SetDataType(typeof(IPage)); docBuilder.CrawlData(page); using (new DataConnection(page.DataSourceId.PublicationScope, page.DataSourceId.LocaleScope)) { if (isPublished) { docBuilder.Url = PageUrls.BuildUrl(page, UrlKind.Internal); } var placeholders = PageManager.GetPlaceholderContent(page.Id, page.VersionId); placeholders.ForEach(pl => docBuilder.CrawlData(pl, true)); List <IData> metaData; if (allMetaData != null) { allMetaData.TryGetValue(new Tuple <Guid, Guid>(page.Id, page.VersionId), out metaData); } else { metaData = GetMetaData(page.Id, page.VersionId, page.DataSourceId.PublicationScope, page.DataSourceId.LocaleScope); } try { metaData?.ForEach(pageMetaData => docBuilder.CrawlData(pageMetaData)); } catch (Exception ex) { Log.LogWarning(LogTitle, ex); } } if (!string.IsNullOrEmpty(page.UrlTitle) && !UrlFormattersPluginFacade.FormatUrl(page.Title, true).Equals(page.UrlTitle, StringComparison.OrdinalIgnoreCase) && !UrlFormattersPluginFacade.FormatUrl(page.Title, false).Equals(page.UrlTitle, StringComparison.OrdinalIgnoreCase)) { docBuilder.TextParts.Add(page.UrlTitle); } return(docBuilder.BuildDocument(Name, documentId, label, null, entityToken)); }
private SearchDocument FromMediaFile(IMediaFile mediaFile) { string label = mediaFile.Title; if (string.IsNullOrWhiteSpace(label)) { label = mediaFile.FileName; } string documentId = mediaFile.Id.ToString(); var docBuilder = new SearchDocumentBuilder(); docBuilder.SetDataType(typeof(IMediaFile)); docBuilder.CrawlData(mediaFile); return(docBuilder.BuildDocument(Name, documentId, label, null, mediaFile.GetDataEntityToken(), null)); }
private SearchDocument FromPage(IPage page, EntityToken entityToken) { string label = page.MenuTitle; if (string.IsNullOrWhiteSpace(label)) { label = page.Title; } bool isPublished = page.DataSourceId.PublicationScope == PublicationScope.Published; string documentId = GetDocumentId(page); var documentBuilder = new SearchDocumentBuilder(); documentBuilder.SetDataType(typeof(IPage)); documentBuilder.CrawlData(page); string url; using (new DataConnection(page.DataSourceId.PublicationScope, page.DataSourceId.LocaleScope)) { var placeholders = PageManager.GetPlaceholderContent(page.Id, page.VersionId); placeholders.ForEach(pl => documentBuilder.CrawlData(pl, true)); try { page.GetMetaData() .ForEach(pageMetaData => documentBuilder.CrawlData(pageMetaData)); } catch (Exception ex) { Log.LogWarning(LogTitle, ex); } url = isPublished ? PageUrls.BuildUrl(page, UrlKind.Internal) : null; } return(documentBuilder.BuildDocument(Name, documentId, label, null, entityToken, url)); }
private SearchDocument FromMediaFile(IMediaFile mediaFile) { string label = mediaFile.Title; if (string.IsNullOrWhiteSpace(label)) { label = mediaFile.FileName; } if (string.IsNullOrEmpty(label)) { Log.LogWarning(nameof(MediaLibraryDocumentSource), $"A media file has neither FileName nor Label fields specified, Id: '{mediaFile.Id}', StoreId: '{mediaFile.StoreId}'."); return(null); } var docBuilder = new SearchDocumentBuilder(_docBuilderExtensions); docBuilder.SetDataType(typeof(IMediaFile)); docBuilder.CrawlData(mediaFile); return(docBuilder.BuildDocument(Name, mediaFile.Id.ToString(), label, null, mediaFile.GetDataEntityToken())); }