/// <summary> /// Add SolrExpress framework services in DI container /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="builder">Options builder action</param> /// <returns>Configured DocumentCollectionOptionsBuilder</returns> public static DocumentCollectionBuilder <TDocument> AddSolrExpress <TDocument>(this IServiceCollection services, Action <DocumentCollectionBuilder <TDocument> > builder) where TDocument : IDocument { Checker.IsNull(builder); var builderObj = new DocumentCollectionBuilder <TDocument>(); builderObj.Engine = new NetCoreEngine(services); builder.Invoke(builderObj); var documentCollection = builderObj.Create(); var expressionCache = new ExpressionCache <TDocument>(); var expressionBuilder = new ExpressionBuilder <TDocument>(expressionCache); documentCollection .Engine .AddSingleton <DocumentCollectionOptions <TDocument>, DocumentCollectionOptions <TDocument> >(builderObj.Options) .AddSingleton <ISearchParameterBuilder <TDocument>, SearchParameterBuilder <TDocument> >() .AddSingleton <IExpressionCache <TDocument>, ExpressionCache <TDocument> >(expressionCache) .AddSingleton <IExpressionBuilder <TDocument>, ExpressionBuilder <TDocument> >(expressionBuilder) .AddSingleton <IEngine, NetCoreEngine>((NetCoreEngine)builderObj.Engine) .AddSingleton <ISearchParameterBuilder <TDocument>, SearchParameterBuilder <TDocument> >() .AddTransient <IDocumentCollection <TDocument>, DocumentCollection <TDocument> >(documentCollection) .AddTransient <ISolrSearch <TDocument>, SolrSearch <TDocument> >() .AddTransient <ISolrAtomicUpdate <TDocument>, SolrAtomicUpdate <TDocument> >(); ExpressionCacheWarmup.Load(expressionBuilder); return(builderObj); }
// This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { var techProducts = new DocumentCollectionBuilder <TechProduct>() .AddSolrExpress() .UseOptions(new DocumentCollectionOptions <TechProduct>() { CheckAnyParameter = true, FailFast = true }) .UseHostAddress("http://localhost:8983/solr/gettingstarted") .UseSolr5() .Create(); services.AddSingleton <IDocumentCollection <TechProduct> >(q => techProducts); services.AddMvc(); }
public static DocumentCollectionBuilder <TDocument> UseSolr4 <TDocument>(this DocumentCollectionBuilder <TDocument> builder) where TDocument : IDocument { builder .Engine #if NETCORE .AddSingleton <IEngine, NetCoreEngine>((NetCoreEngine)builder.Engine) #else .AddSingleton <IEngine, NetFrameworkEngine>((NetFrameworkEngine)builder.Engine) #endif .AddSingleton <ISolrConnection, SolrConnection>() .AddTransient <IAnyParameter <TDocument>, AnyParameter <TDocument> >() .AddTransient <IFacetFieldParameter <TDocument>, FacetFieldParameter <TDocument> >() .AddTransient <IFacetLimitParameter <TDocument>, FacetLimitParameter <TDocument> >() .AddTransient <IFacetQueryParameter <TDocument>, FacetQueryParameter <TDocument> >() .AddTransient <IFacetRangeParameter <TDocument>, FacetRangeParameter <TDocument> >() .AddTransient <IFacetSpatialParameter <TDocument>, FacetSpatialParameter <TDocument> >() .AddTransient <IFieldsParameter <TDocument>, FieldListParameter <TDocument> >() .AddTransient <IFilterParameter <TDocument>, FilterQueryParameter <TDocument> >() .AddTransient <ILimitParameter <TDocument>, RowsParameter <TDocument> >() .AddTransient <IMinimumShouldMatchParameter <TDocument>, MinimumShouldMatchParameter <TDocument> >() .AddTransient <IOffsetParameter <TDocument>, StartParameter <TDocument> >() .AddTransient <IQueryFieldParameter <TDocument>, QueryFieldParameter <TDocument> >() .AddTransient <IQueryParameter <TDocument>, QueryParameter <TDocument> >() .AddTransient <ISortParameter <TDocument>, SortParameter <TDocument> >() .AddTransient <IRandomSortParameter <TDocument>, RandomSortParameter <TDocument> >() .AddTransient <ISpatialFilterParameter <TDocument>, SpatialFilterParameter <TDocument> >() .AddTransient <IBoostParameter <TDocument>, BoostParameter <TDocument> >() .AddTransient <IDocumentResult <TDocument>, DocumentResult <TDocument> >() .AddTransient <IFacetFieldResult <TDocument>, FacetFieldResult <TDocument> >() .AddTransient <IFacetQueryResult <TDocument>, FacetQueryResult <TDocument> >() .AddTransient <IFacetRangeResult <TDocument>, FacetRangeResult <TDocument> >() .AddTransient <IInformationResult <TDocument>, InformationResult <TDocument> >() .AddTransient <IAtomicUpdate <TDocument>, AtomicUpdate <TDocument> >() .AddTransient <IAtomicDelete <TDocument>, AtomicDelete <TDocument> >() .AddTransient <ISearchParameterCollection <TDocument>, SearchParameterCollection <TDocument> >() .AddTransient <ISystemParameter <TDocument>, SystemParameter <TDocument> >(); return(builder); }
/// <summary> /// Default constructor of class /// </summary> public IntegrationTests() { var options = new DocumentCollectionOptions <TechProductDocument> { FailFast = false }; #if NETCORE var serviceCollection = new ServiceCollection(); serviceCollection.AddSolrExpress <TechProductDocument>(builder => builder .UseOptions(options) .UseHostAddress("http://localhost:8983/solr/collection1") .UseSolr4()); this._serviceProvider = serviceCollection.BuildServiceProvider(); #else this._documentCollectionBuilder = new DocumentCollectionBuilder <TechProductDocument>() .AddSolrExpress() .UseOptions(options) .UseHostAddress("http://localhost:8983/solr/collection1") .UseSolr4(); #endif }
public static void Main(string[] args) { IDocumentCollection <TechProduct> techProducts; // Emulating not use of Net Core DI services #if NET40 || NET45 techProducts = new DocumentCollectionBuilder <TechProduct>() .AddSolrExpress() .UseHostAddress("http://localhost:8983/solr/techproducts") .UseSolr5() .Create(); #else // Emulating use of Net Core DI services var serviceCollection = new ServiceCollection(); serviceCollection.AddSolrExpress <TechProduct>(builder => builder .UseHostAddress("http://localhost:8983/solr/techproducts") .UseSolr5()); var serviceProvider = serviceCollection.BuildServiceProvider(); techProducts = serviceProvider.GetRequiredService <IDocumentCollection <TechProduct> >(); #endif IEnumerable <TechProduct> documents; IEnumerable <FacetKeyValue <string> > facetFields; var select = techProducts .Select() .QueryAll() .Limit(3) .FacetField(q => q.Manufacturer) .FacetField(q => q.InStock) .FacetRange("Price", q => q.Price, "10", "10", "100") .FacetRange("Popularity", q => q.Popularity, "1", "1", "10") .FacetRange("ManufacturedateIn", q => q.ManufacturedateIn, "+1MONTH", "NOW-10YEARS", "NOW") .FacetQuery("StoreIn1000km", new Spatial <TechProduct>(SolrSpatialFunctionType.Geofilt, q => q.StoredAt, new GeoCoordinate(35.0752M, -97.032M), 1000M)); select .Execute() .Document(out documents) .FacetField(out facetFields); foreach (var document in documents) { var json = JsonConvert.SerializeObject(document, Formatting.Indented); Console.WriteLine(json); Console.WriteLine(new string('-', 50)); } foreach (var facetField in facetFields) { var json = JsonConvert.SerializeObject(facetField, Formatting.Indented); Console.WriteLine(json); Console.WriteLine(new string('-', 50)); } Console.Read(); }