Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:R4RAPI.Controllers.ResourcesController"/> class.
 /// </summary>
 /// <param name="environment">Environment.</param>
 /// <param name="logger">Logger.</param>
 /// /// <param name="apiOptionsAccessor">API Options.</param>
 /// <param name="queryService">Query service.</param>
 /// <param name="aggService">Agg service.</param>
 /// <param name="urlHelper">URL helper.</param>
 public ResourcesController(
     IHostingEnvironment environment,
     ILogger <ResourcesController> logger,
     IOptions <R4RAPIOptions> apiOptionsAccessor,
     IResourceQueryService queryService,
     IResourceAggregationService aggService,
     IUrlHelper urlHelper)
 {
     _environment  = environment;
     _logger       = logger;
     _apiOptions   = apiOptionsAccessor.Value.IsValid() ? apiOptionsAccessor.Value : throw new Exception("R4RAPIOptions is misconfigured.");
     _queryService = queryService;
     _aggService   = aggService;
     _urlHelper    = urlHelper;
 }
        /// <summary>
        /// Helper method to create a mocked up CGBBIndexOptions object.
        /// </summary>
        /// <returns></returns>
        protected IOptions <R4RAPIOptions> GetMockConfig()
        {
            var options = new R4RAPIOptions
            {
                AliasName       = "r4r_v1",
                AvailableFacets = new Dictionary <string, R4RAPIOptions.FacetConfig> {
                    {
                        "toolTypes", new R4RAPIOptions.FacetConfig {
                            FilterName       = "toolTypes",
                            Label            = "Tool Types",
                            FacetType        = R4RAPIOptions.FacetTypes.Single,
                            IncludeInDefault = true
                        }
                    },
                    {
                        "toolSubtypes", new R4RAPIOptions.FacetConfig {
                            FilterName       = "toolSubtypes",
                            Label            = "Tool Sub-Types",
                            FacetType        = R4RAPIOptions.FacetTypes.Multiple,
                            IncludeInDefault = true,
                            RequiresFilter   = "toolTypes"
                        }
                    },
                    {
                        "researchAreas", new R4RAPIOptions.FacetConfig {
                            FilterName       = "researchAreas",
                            Label            = "Research Areas",
                            FacetType        = R4RAPIOptions.FacetTypes.Multiple,
                            IncludeInDefault = true
                        }
                    },
                    {
                        "researchTypes", new R4RAPIOptions.FacetConfig {
                            FilterName       = "researchTypes",
                            Label            = "Research Types",
                            FacetType        = R4RAPIOptions.FacetTypes.Multiple,
                            IncludeInDefault = true
                        }
                    },
                    {
                        "docs", new R4RAPIOptions.FacetConfig {
                            FilterName       = "docs",
                            Label            = "Division, Offices, and Centers",
                            FacetType        = R4RAPIOptions.FacetTypes.Multiple,
                            IncludeInDefault = false
                        }
                    }
                },
                AvailableFields = new string[]
                {
                    "id",
                    "title",
                    "website",
                    "body",
                    "description",
                    "toolTypes",
                    "researchAreas",
                    "researchTypes",
                    "resourceAccess",
                    "docs",
                    "pocs"
                },
                AvailableFullTextFields = new Dictionary <string, R4RAPIOptions.FullTextFieldConfig> {
                    {
                        "title", new R4RAPIOptions.FullTextFieldConfig {
                            FieldName  = "title._fulltext",
                            Boost      = 1,
                            MatchTypes = new string[] { "common", "match", "match_phrase" }
                        }
                    },
                    {
                        "body", new R4RAPIOptions.FullTextFieldConfig {
                            FieldName  = "body._fulltext",
                            Boost      = 1,
                            MatchTypes = new string[] { "common", "match", "match_phrase" }
                        }
                    },
                    {
                        "pocs.lastname", new R4RAPIOptions.FullTextFieldConfig {
                            FieldName  = "pocs.lastname._fulltext",
                            Boost      = 1,
                            MatchTypes = new string[] { "match" }
                        }
                    },
                    {
                        "pocs.firstname", new R4RAPIOptions.FullTextFieldConfig {
                            FieldName  = "pocs.firstname._fulltext",
                            Boost      = 1,
                            MatchTypes = new string[] { "match" }
                        }
                    },
                    {
                        "pocs.middlename", new R4RAPIOptions.FullTextFieldConfig {
                            FieldName  = "pocs.middlename._fulltext",
                            Boost      = 1,
                            MatchTypes = new string[] { "match" }
                        }
                    }
                }
            };

            Moq.Mock <IOptions <R4RAPIOptions> > config = new Mock <IOptions <R4RAPIOptions> >();
            config
            .SetupGet(o => o.Value)
            .Returns(options);

            return(config.Object);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:R4RAPI.Services.ESResourceServiceBase"/> class.
 /// </summary>
 /// <param name="client">An instance of a <see cref="T:Nest.ElasticClient"/>Client.</param>
 /// <param name="apiOptionsAccessor">API options accessor.</param>
 /// <param name="logger">Logger.</param>
 public ESResourceServiceBase(IElasticClient client, IOptions <R4RAPIOptions> apiOptionsAccessor, ILogger logger)
 {
     this._elasticClient = client;
     this._apiOptions    = apiOptionsAccessor.Value.IsValid() ? apiOptionsAccessor.Value : throw new Exception("R4RAPIOptions is misconfigured.");
     this._logger        = logger;
 }