コード例 #1
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            foreach (var index in SolrContentSearchManager.Cores)
            {
                this.AddCore(index, typeof(Dictionary <string, object>), string.Concat(SolrContentSearchManager.ServiceAddress, "/", index));
            }

            this.Container.AddFacility(this.SolrFacility);

            // Override default implementation registration with custom object.
            this.Container.Register(Component.For <ISolrDocumentSerializer <Dictionary <string, object> > >().ImplementedBy <SolrFieldBoostingDictionarySerializer>().OverridesExistingRegistration());
            this.Container.Register(Component.For <ISolrSchemaParser>().ImplementedBy <Sitecore.ContentSearch.SolrProvider.Parsers.SolrSchemaParser>().OverridesExistingRegistration());
            this.Container.Register(Component.For <ISolrCache>().ImplementedBy <HttpRuntimeCache>());
            this.Container.Register(Component.For <IHttpWebRequestFactory>().UsingFactoryMethod(() => SolrContentSearchManager.HttpWebRequestFactory));

            foreach (var connection in this.Container.ResolveAll <ISolrConnection>().OfType <SolrConnection>())
            {
                if (SolrContentSearchManager.EnableHttpCache)
                {
                    connection.Cache = this.Container.Resolve <ISolrCache>() ?? new NullCache();
                }

                connection.HttpWebRequestFactory = this.Container.Resolve <IHttpWebRequestFactory>();
            }

            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(this.Container));

            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }
コード例 #2
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            foreach (var index in SolrContentSearchManager.Cores)
            {
                this.AddCore(index, typeof(Dictionary <string, object>), string.Concat(SolrContentSearchManager.ServiceAddress, "/", index));
            }

            ObjectFactory.Initialize(c => c.IncludeRegistry(new SolrNetRegistry(this.Cores)));
            ObjectFactory.Configure(c => c.For(typeof(ISolrDocumentSerializer <Dictionary <string, object> >)).Use(typeof(SolrFieldBoostingDictionarySerializer)));
            ObjectFactory.Configure(c => c.For <ISolrSchemaParser>().Use <Sitecore.ContentSearch.SolrProvider.Parsers.SolrSchemaParser>());
            ObjectFactory.Configure(c => c.For <ISolrCache>().Use <HttpRuntimeCache>());
            ObjectFactory.Configure(c => c.For <IHttpWebRequestFactory>().Use(context => SolrContentSearchManager.HttpWebRequestFactory));

            foreach (var connection in ObjectFactory.GetAllInstances <ISolrConnection>().OfType <SolrConnection>())
            {
                if (SolrContentSearchManager.EnableHttpCache)
                {
                    connection.Cache = ObjectFactory.GetInstance <ISolrCache>() ?? new NullCache();
                }

                connection.HttpWebRequestFactory = ObjectFactory.GetInstance <IHttpWebRequestFactory>();
            }

            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => new StructureMapServiceLocator(ObjectFactory.Container));

            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }
コード例 #3
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }
            foreach (string coreId in SolrContentSearchManager.Cores)
            {
                this.AddCore(coreId, typeof(Dictionary <string, object>), string.Format("{0}/{1}", (object)SolrContentSearchManager.ServiceAddress, (object)coreId));
            }

            builder.RegisterModule((IModule) new SolrNetModule(this.Cores));
            RegistrationExtensions.RegisterType <SolrFieldBoostingDictionarySerializer>(this.builder).As <ISolrDocumentSerializer <Dictionary <string, object> > >();
            if (SolrContentSearchManager.EnableHttpCache)
            {
                RegistrationExtensions.RegisterType <HttpRuntimeCache>(this.builder).As <ISolrCache>();
                foreach (SolrServerElement solrServerElement in (ConfigurationElementCollection)this.Cores)
                {
                    ((IRegistrationBuilder <object, ConcreteReflectionActivatorData, SingleRegistrationStyle>)RegistrationExtensions.WithParameters <object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterType(this.builder, typeof(SolrConnection)).Named(solrServerElement.Id + (object)typeof(SolrConnection), typeof(ISolrConnection)), (IEnumerable <Parameter>) new NamedParameter[1]
                    {
                        new NamedParameter("serverURL", (object)solrServerElement.Url)
                    })).OnActivated((Action <IActivatedEventArgs <object> >)(args => ((SolrConnection)args.Instance).Cache = ResolutionExtensions.Resolve <ISolrCache>(args.Context)));
                }
            }
            this.container = this.builder.Build(ContainerBuildOptions.None);
            ServiceLocator.SetLocatorProvider((ServiceLocatorProvider)(() => (IServiceLocator) new AutofacServiceLocator((IComponentContext)this.container)));
            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }
コード例 #4
0
        public virtual void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }
            Operations.DocumentSerializer    = new SolrFieldBoostingDictionarySerializer(Operations.FieldSerializer);
            Operations.HttpWebRequestFactory = SolrContentSearchManager.HttpWebRequestFactory;
            Operations.SchemaParser          = new SolrSchemaParser();
            foreach (string core in SolrContentSearchManager.Cores)
            {
                AddCore(core, typeof(Dictionary <string, object>), $"{SolrContentSearchManager.ServiceAddress}/{core}");
            }
            if (SolrContentSearchManager.EnableHttpCache)
            {
                Operations.HttpCache = solrCache;
            }
            Operations.CoreAdmin = BuildCoreAdmin();

            _sharedServiceLocator.SetSitecoreServiceLocator(new DefaultServiceLocator <Dictionary <string, object> >(this.Operations));
            ServiceLocator.SetLocatorProvider(() => _sharedServiceLocator);

            SolrContentSearchManager.SolrAdmin = Operations.CoreAdmin;
            SolrContentSearchManager.Initialize();
        }
コード例 #5
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            _operations = new DefaultSolrLocator <Dictionary <string, object> >();

            // Override the document serializer to support boosting.
            _operations.DocumentSerializer = new SolrFieldBoostingDictionarySerializer(_operations.FieldSerializer);

            foreach (var index in SolrContentSearchManager.Cores)
            {
                AddCore(index, typeof(Dictionary <string, object>), $"{SolrContentSearchManager.ServiceAddress}/{index}");
            }

            if (SolrContentSearchManager.EnableHttpCache)
            {
                _operations.HttpCache = new HttpRuntimeCache();
            }

            _operations.RegisterCores();
            _operations.CoreAdmin = BuildCoreAdmin();

            //Register the service locator (yes, its a horrible pattern but this means we dont have to change anything internally in Sitecore for now).
            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => new DefaultServiceLocator <Dictionary <string, object> >(_operations));

            SolrContentSearchManager.SolrAdmin = _operations.CoreAdmin;
            SolrContentSearchManager.Initialize();
        }
コード例 #6
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Solr configuration is not enabled. Please check your settings and include files.</exception>
        /// <exception cref="InvalidOperationException">Solr configuration is not enabled. Please check your settings and include files.</exception>
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            foreach (string index in SolrContentSearchManager.Cores)
            {
                this.AddCore(index, typeof(Dictionary <string, object>), string.Concat(SolrContentSearchManager.ServiceAddress, "/", index));
            }

            this.Container = new SolrNetContainerConfiguration().ConfigureContainer(this.Cores, this.Container);
            this.Container.RegisterType(typeof(ISolrDocumentSerializer <Dictionary <string, object> >), typeof(SolrFieldBoostingDictionarySerializer));
            this.Container.RegisterType(typeof(ISolrSchemaParser), typeof(Sitecore.ContentSearch.SolrProvider.Parsers.SolrSchemaParser));
            this.Container.RegisterType(typeof(ISolrCache), typeof(HttpRuntimeCache));
            this.Container.RegisterType <IHttpWebRequestFactory>(new InjectionFactory(c => SolrContentSearchManager.HttpWebRequestFactory));

            List <ContainerRegistration> registrations = this.Container.Registrations.Where(r => r.RegisteredType == typeof(ISolrConnection)).ToList();

            if (registrations.Count > 0)
            {
                foreach (ContainerRegistration registration in registrations)
                {
                    SolrServerElement solrCore = this.Cores.FirstOrDefault(core => registration.Name == core.Id + registration.MappedToType.FullName);

                    if (solrCore == null)
                    {
                        Log.Error(
                            "The Solr Core configuration for the '"
                            + registration.Name
                            + "' Unity registration could not be found. The HTTP cache and HTTP web request factory for the Solr connection to the Core cannot be configured.",
                            this);
                        continue;
                    }

                    List <InjectionMember> injectionParameters = new List <InjectionMember>()
                    {
                        new InjectionConstructor(solrCore.Url),
                        new InjectionProperty("HttpWebRequestFactory", new ResolvedParameter <IHttpWebRequestFactory>()),
                        new InjectionProperty("Timeout", SolrContentSearchManager.ConnectionTimeout)
                    };

                    if (SolrContentSearchManager.EnableHttpCache)
                    {
                        injectionParameters.Add(new InjectionProperty("Cache", new ResolvedParameter <ISolrCache>()));
                    }

                    this.Container.RegisterType(typeof(ISolrConnection), typeof(SolrConnection), registration.Name, null, injectionParameters.ToArray());
                }
            }

            ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(this.Container));

            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }
コード例 #7
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            foreach (var index in SolrContentSearchManager.Cores)
            {
                this.AddCore(index, typeof(Dictionary <string, object>), string.Concat(SolrContentSearchManager.ServiceAddress, "/", index));
            }

            this.builder.RegisterModule(new SolrNetModule(this.Cores));
            this.builder.RegisterType <SolrFieldBoostingDictionarySerializer>().As <ISolrDocumentSerializer <Dictionary <string, object> > >();
            this.builder.RegisterType <SolrSchemaParser>().As <ISolrSchemaParser>();

            this.builder.Register(c => SolrContentSearchManager.HttpWebRequestFactory).As <IHttpWebRequestFactory>();
            this.builder.RegisterType <HttpRuntimeCache>().As <ISolrCache>();

            foreach (SolrServerElement core in this.Cores)
            {
                string coreConnectionId = core.Id + typeof(SolrConnection);
                var    parameters       = new[] { new NamedParameter("serverURL", core.Url) };
                var    properties       = new[] { new NamedParameter("Timeout", SolrContentSearchManager.ConnectionTimeout) };
                this.builder.RegisterType(typeof(SolrConnection))
                .Named(coreConnectionId, typeof(ISolrConnection))
                .WithParameters(parameters)
                .WithProperties(properties)
                .OnActivated(args =>
                {
                    if (SolrContentSearchManager.EnableHttpCache)
                    {
                        ((SolrConnection)args.Instance).Cache = args.Context.Resolve <ISolrCache>();
                    }
                    ((SolrConnection)args.Instance).HttpWebRequestFactory = args.Context.Resolve <IHttpWebRequestFactory>();
                });
            }

            this.container = this.builder.Build();

            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container));

            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }
コード例 #8
0
        public void Initialize()
        {
            if (!SolrContentSearchManager.IsEnabled)
            {
                throw new InvalidOperationException("Solr configuration is not enabled. Please check your settings and include files.");
            }

            foreach (var index in SolrContentSearchManager.Cores)
            {
                this.AddCore(index, typeof(Dictionary <string, object>), string.Concat(SolrContentSearchManager.ServiceAddress, "/", index));
            }

            kernel.Load(new SolrNetModule(this.Cores));
            kernel.Bind(typeof(ISolrDocumentResponseParser <Dictionary <string, object> >)).To(typeof(SolrDictionaryDocumentResponseParser));
            kernel.Rebind <ISolrDocumentSerializer <Dictionary <string, object> > >().To <SolrFieldBoostingDictionarySerializer>();
            kernel.Rebind <ISolrSchemaParser>().To <SolrSchemaParser>();
            kernel.Bind <IHttpWebRequestFactory>().ToMethod(x => SolrContentSearchManager.HttpWebRequestFactory);
            kernel.Bind <ISolrCache>().To <HttpRuntimeCache>();

            foreach (SolrServerElement core in this.Cores)
            {
                SolrServerElement closuredCore = core;
                var connection = this.kernel.Get <ISolrConnection>(bm => bm.Get <string>("CoreId") == closuredCore.Id) as SolrConnection;
                if (connection != null)
                {
                    if (SolrContentSearchManager.EnableHttpCache)
                    {
                        connection.Cache = this.kernel.Get <ISolrCache>() ?? new NullCache();
                    }

                    connection.HttpWebRequestFactory = this.kernel.Get <IHttpWebRequestFactory>();
                }
            }

            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(this.kernel));

            SolrContentSearchManager.SolrAdmin = this.BuildCoreAdmin();
            SolrContentSearchManager.Initialize();
        }