示例#1
0
 /// <summary>
 /// The create search context.
 /// </summary>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <returns>
 /// The <see cref="IProviderSearchContext"/>.
 /// </returns>
 public override IProviderSearchContext CreateSearchContext(Sitecore.ContentSearch.Security.SearchSecurityOptions options = Sitecore.ContentSearch.Security.SearchSecurityOptions.EnableSecurityCheck)
 {
     return(new AzureSearchWithSpatialContext(this, options));
 }
示例#2
0
        public override TElement MapToType <TElement>(Document document, Sitecore.ContentSearch.Linq.Methods.SelectMethod selectMethod, IEnumerable <IFieldQueryTranslator> virtualFieldProcessors, Sitecore.ContentSearch.Security.SearchSecurityOptions securityOptions)
        {
            // if the result type is not IStandardTemplateItem, use the default functionality
            if (!typeof(IStandardTemplateItem).IsAssignableFrom(typeof(TElement)))
            {
                return(base.MapToType <TElement>(document, selectMethod, virtualFieldProcessors, securityOptions));
            }

            // initializers can't really support sub-selects of objects. Error if that's what's being used.
            if (selectMethod != null)
            {
                throw new NotSupportedException("Using Select on a Synthesis object type is supported. Convert the query to a list or array before selecting, then select using LINQ to objects.");
            }

            var fields = ExtractFieldsFromDocument(document, virtualFieldProcessors);

            ShortID templateId;

            if (!fields.ContainsKey("_template") || !ShortID.TryParse(fields["_template"], out templateId))
            {
                templateId = ID.Null.ToShortID();
            }

            var result = Initializers.GetInitializer(templateId.ToID()).CreateInstanceFromSearch(fields);

            if (result is TElement)
            {
                return((TElement)result);
            }

            return(default(TElement));
        }