public void CreatesEquivalentField(
            [EnumValues] SearchFieldDataType type,
            [Values] bool key,
            [Values] bool hidden,
            [Values] bool filterable,
            [Values] bool facetable,
            [Values] bool sortable)
        {
            SimpleFieldAttribute sut = new SimpleFieldAttribute
            {
                IsKey        = key,
                IsHidden     = hidden,
                IsFilterable = filterable,
                IsFacetable  = facetable,
                IsSortable   = sortable,
            };

            SearchField field = new SearchField("test", type);

            ((ISearchFieldAttribute)sut).SetField(field);

            Assert.AreEqual("test", field.Name);
            Assert.AreEqual(type, field.Type);
            Assert.AreEqual(key, field.IsKey ?? false);
            Assert.AreEqual(hidden, field.IsHidden ?? false);
            Assert.AreEqual(filterable, field.IsFilterable ?? false);
            Assert.AreEqual(facetable, field.IsFacetable ?? false);
            Assert.AreEqual(sortable, field.IsSortable ?? false);
        }
예제 #2
0
        public void CreatesEquivalentField(
            [EnumValues] SearchFieldDataType type,
            [Values] bool collection,
            [Values] bool key,
            [Values] bool hidden,
            [Values] bool filterable,
            [Values] bool facetable,
            [Values] bool sortable)
        {
            SimpleFieldAttribute sut = new SimpleFieldAttribute(type, collection)
            {
                IsKey        = key,
                IsHidden     = hidden,
                IsFilterable = filterable,
                IsFacetable  = facetable,
                IsSortable   = sortable,
            };

            SearchFieldDataType actualType = collection ? SearchFieldDataType.Collection(type) : type;

            Assert.AreEqual(actualType, sut.Type);

            SearchField field = ((ISearchFieldAttribute)sut).CreateField("test");

            Assert.AreEqual("test", field.Name);
            Assert.AreEqual(actualType, field.Type);
            Assert.AreEqual(key, field.IsKey);
            Assert.AreEqual(hidden, field.IsHidden);
            Assert.AreEqual(filterable, field.IsFilterable);
            Assert.AreEqual(facetable, field.IsFacetable);
            Assert.AreEqual(sortable, field.IsSortable);
        }
예제 #3
0
 public SearchFieldDefinition(
     string arg0,
     SearchFieldDataType arg1,
     string arg2,
     string arg3,
     string arg4,
     CheckUserRightsDelegate <TContext> arg5,
     ISqlExpressionModifier <TContext> arg6,
     SearchFieldOption arg7,
     SearchCriteriaComparison arg8,
     AggregateFunction arg9,
     string arg10,
     string[] arg11
     ) : base()
 {
     Field0  = arg0;
     Field1  = arg1;
     Field2  = arg2;
     Field3  = arg3;
     Field4  = arg4;
     Field5  = arg5;
     Field6  = arg6;
     Field7  = arg7;
     Field8  = arg8;
     Field9  = arg9;
     Field10 = arg10;
     Field11 = arg11;
 }
예제 #4
0
        public void UpdateImageIndex()
        {
            switch (SearchFieldDataType.ToString())
            {
            case "System.Int64":
            case "System.Decimal":
            case "System.Single":
            case "System.Double":
            case "System.Float":
                FieldImage = AddMissedValues ? "numeric_bordered.png" : "numeric.png";
                break;

            case "System.DateTime":
                FieldImage = AddMissedValues ? "date_bordered.png" : "date.png";
                break;

            case "System.Boolean":
                FieldImage = AddMissedValues ? "boolean_bordered.png" : "boolean.png";
                break;

            default:
                FieldImage = AddMissedValues ? "string_bordered.png" : "string.png";
                break;
            }
        }
예제 #5
0
        public void CreatesEquivalentField(
            [Values] bool collection,
            [Values] bool key,
            [Values] bool hidden,
            [Values] bool filterable,
            [Values] bool facetable,
            [Values] bool sortable,
            [Values(null, "AnalyzerName")] string analyzerName,
            [Values(null, "SearchAnalyzerName")] string searchAnalyzerName,
            [Values(null, "IndexAnalyzerName")] string indexAnalyzerName,
            [Values(null, new[] { "synonynMapName" })] string[] synonymMapNames)
        {
            SearchableFieldAttribute sut = new SearchableFieldAttribute(collection)
            {
                IsKey        = key,
                IsHidden     = hidden,
                IsFilterable = filterable,
                IsFacetable  = facetable,
                IsSortable   = sortable,
            };

            if (analyzerName != null)
            {
                sut.AnalyzerName = analyzerName;
            }

            if (searchAnalyzerName != null)
            {
                sut.SearchAnalyzerName = searchAnalyzerName;
            }

            if (indexAnalyzerName != null)
            {
                sut.IndexAnalyzerName = indexAnalyzerName;
            }

            if (synonymMapNames != null)
            {
                sut.SynonymMapNames = synonymMapNames;
            }

            SearchFieldDataType actualType = collection ? SearchFieldDataType.Collection(SearchFieldDataType.String) : SearchFieldDataType.String;

            Assert.AreEqual(actualType, sut.Type);

            SearchField field = ((ISearchFieldAttribute)sut).CreateField("test");

            Assert.AreEqual("test", field.Name);
            Assert.AreEqual(actualType, field.Type);
            Assert.AreEqual(key, field.IsKey);
            Assert.AreEqual(hidden, field.IsHidden);
            Assert.AreEqual(filterable, field.IsFilterable);
            Assert.AreEqual(facetable, field.IsFacetable);
            Assert.AreEqual(sortable, field.IsSortable);
            Assert.AreEqual(analyzerName, field.AnalyzerName?.ToString());
            Assert.AreEqual(searchAnalyzerName, field.SearchAnalyzerName?.ToString());
            Assert.AreEqual(indexAnalyzerName, field.IndexAnalyzerName?.ToString());
            Assert.AreEqual(synonymMapNames, field.SynonymMapNames);
        }
예제 #6
0
        private bool TryGetDataType(Type type, out SearchFieldDataType dt)
        {
            if (type == typeof(string))
            {
                dt = SearchFieldDataType.String;
                return(true);
            }

            if (type == typeof(DateTime) || type == typeof(DateTimeOffset))
            {
                dt = SearchFieldDataType.DateTimeOffset;
                return(true);
            }

            if (type == typeof(bool))
            {
                dt = SearchFieldDataType.Boolean;
                return(true);
            }

            if (type == typeof(int))
            {
                dt = SearchFieldDataType.Int32;
                return(true);
            }

            if (type == typeof(long))
            {
                dt = SearchFieldDataType.Int64;
                return(true);
            }

            if (type == typeof(decimal))
            {
                dt = SearchFieldDataType.Double;
                return(true);
            }

            if (type == typeof(double))
            {
                dt = SearchFieldDataType.Double;
                return(true);
            }

            if (type == typeof(float))
            {
                dt = SearchFieldDataType.Double;
                return(true);
            }

            if (type == typeof(Guid))
            {
                dt = SearchFieldDataType.String;
                return(true);
            }

            return(false);
        }
예제 #7
0
        private List <SearchField> GetTypeFields(Type sourceType, bool isTop)
        {
            var source = TypeAccessor.Create(sourceType);

            return(source.GetMembers().Select(x =>
            {
                if (x.GetAttribute(typeof(JsonIgnoreAttribute), false) != null)
                {
                    return null;
                }

                if (x.IsList())
                {
                    var argType = x.Type.GetGenericArguments()[0];

                    var complexCollection = new SearchField(x.Name, SearchFieldDataType.Collection(SearchFieldDataType.Complex));
                    GetTypeFields(argType, false).ForEach(complexCollection.Fields.Add);
                    return complexCollection;
                }

                SearchFieldDataType type;

                bool hasType = true;
                if (!TryGetDataType(x.Type, out type))
                {
                    if (x.Type.IsClass)
                    {
                        var complex = new SearchField(x.Name, SearchFieldDataType.Complex);
                        GetTypeFields(x.Type, false).ForEach(complex.Fields.Add);
                        return complex;
                    }

                    hasType = false;
                }

                if (!hasType)
                {
                    throw new ArgumentException($"Type of {x.Type.FullName} cannot be translated to Search Data-type.");
                }

                var isSearchable = x.Type == typeof(string);

                var isKey = isTop && x.GetAttribute(typeof(KeyAttribute), false) != null;
                var isFacetable = x.GetAttribute(typeof(IsFacetableAttribute), false) != null;
                var isFilterable = x.GetAttribute(typeof(IsFilterableAttribute), false) != null;

                var field = new SearchField(x.Name, type)
                {
                    IsKey = isKey,
                    IsSearchable = !isKey && isSearchable,
                    IsFacetable = isFacetable,
                    IsFilterable = isFilterable
                };

                return field;
            }).Where(field => field != null).ToList());
        }
        private static async Task CreateIndex(string searchServiceEndpoint, ILogger log)
        {
            log.LogInformation("init-accelerator: Creating index " + Constants.indexName);
            try
            {
                var         idxclient = new SearchIndexClient(new Uri(searchServiceEndpoint), new AzureKeyCredential(GetAppSetting("SearchServiceApiKey")));
                SearchIndex index     = new SearchIndex(Constants.indexName)
                {
                    Fields =
                    {
                        new SearchField("content",               SearchFieldDataType.String)
                        {
                            IsSearchable = true,                 IsSortable   = false, IsFilterable = false, IsFacetable  = false
                        },
                        new SearchField("metadata_storage_path", SearchFieldDataType.String)
                        {
                            IsSearchable = true,                 IsSortable   = false, IsFilterable = false, IsFacetable  = false
                        },
                        new SearchField("id",                    SearchFieldDataType.String)
                        {
                            IsKey = true,                        IsSearchable = true,  IsSortable   = false, IsFilterable = false,IsFacetable = false
                        },
                        new SearchField("metadata_storage_name", SearchFieldDataType.String)
                        {
                            IsSearchable = true,                 IsSortable   = false, IsFilterable = false, IsFacetable  = false
                        },
                        new SearchField("status",                SearchFieldDataType.String)
                        {
                            IsSearchable = false,                IsSortable   = false, IsFilterable = false, IsFacetable  = false
                        },
                        new SearchField("fileType",              SearchFieldDataType.String)
                        {
                            IsSearchable = true,                 IsSortable   = false, IsFilterable = true,  IsFacetable  = true
                        },
                        new SearchField("keyPhrases",            SearchFieldDataType.Collection(SearchFieldDataType.String))
                        {
                            IsSearchable = true,                 IsSortable   = false, IsFilterable = true,  IsFacetable  = true
                        }
                    }
                };

                var suggester = new SearchSuggester("sg", new[] { "keyPhrases" });
                index.Suggesters.Add(suggester);


                await idxclient.CreateIndexAsync(index);
            }
            catch (Exception e)
            {
                log.LogError("init-accelerator: Error while creating index " + e.Message);
                throw new Exception(e.Message);
            }
        }
예제 #9
0
 public FormulaFieldRegisterEntry(
     string arg0,
     SearchFieldDataType arg2,
     string arg3,
     bool arg5
     )
 {
     Field0 = arg0;
     Field2 = arg2;
     Field3 = arg3;
     Field5 = arg5;
 }
예제 #10
0
 public InnerSearchFieldDefinition(
     string arg0,
     string arg1,
     string arg2,
     CheckUserRightsDelegate <TContext> arg4,
     ISqlExpressionModifier <TContext> arg5,
     SearchFieldOption arg6,
     SearchCriteriaComparison arg7,
     AggregateFunction arg8,
     SearchFieldDataType arg9
     ) : base()
 {
 }
예제 #11
0
        private Task CreateIndexAsync(string indexName)
        {
            var suggester = new SearchSuggester("sg", new[] { "Name", "FacilityName" });

            var definition = new SearchIndex(indexName)
            {
                Fields = new List <SearchField>
                {
                    new SearchField("Id", SearchFieldDataType.String)
                    {
                        IsKey = true
                    },
                    new SearchField("FacilityId", SearchFieldDataType.Int32)
                    {
                        IsFilterable = true
                    },
                    new SearchField("Name", SearchFieldDataType.String)
                    {
                        IsSearchable = true, AnalyzerName = LexicalAnalyzerName.EnMicrosoft
                    },
                    new SearchField("Description", SearchFieldDataType.String)
                    {
                        IsSearchable = true, AnalyzerName = LexicalAnalyzerName.EnMicrosoft
                    },
                    new SearchField("FacilityName", SearchFieldDataType.String)
                    {
                        IsSearchable = true, AnalyzerName = LexicalAnalyzerName.EnMicrosoft
                    },
                    new SearchField("FacilityDescription", SearchFieldDataType.String)
                    {
                        IsSearchable = true, AnalyzerName = LexicalAnalyzerName.EnMicrosoft
                    },
                    new SearchField("Location", SearchFieldDataType.GeographyPoint)
                    {
                        IsFilterable = true
                    },
                    new SearchField("RoomCount", SearchFieldDataType.Int32)
                    {
                        IsFilterable = true
                    },
                    new SearchField("Images", SearchFieldDataType.Collection(SearchFieldDataType.String))
                    {
                        IsFilterable = false
                    }
                }
            };

            definition.Suggesters.Add(suggester);

            return(client.CreateOrUpdateIndexAsync(definition));
        }
예제 #12
0
 public CustomFormulaGenericDecimalPart(
     ICollection arg0,
     string arg1,
     bool arg2,
     AggregateFunction arg3,
     SearchFieldDataType arg4,
     AggregateFunction arg5,
     string arg6
     ) : base(arg0, arg1, arg2, arg3)
 {
     Field4 = arg4;
     Field5 = arg5;
     Field6 = arg6;
 }
예제 #13
0
 public SearchFieldRegisterEntry(
     string arg0,
     CreateSearchFieldDelegate <TContext, SearchCriteria> arg1,
     SearchFieldDataType arg2,
     CheckUserRightsDelegate <TContext> arg3,
     bool arg4
     )
 {
     Field0 = arg0;
     Field1 = arg1;
     Field2 = arg2;
     Field3 = arg3;
     Field4 = arg4;
 }
예제 #14
0
 public EnumSearchFieldDefinition(
     string arg0,
     SearchFieldDataType arg1,
     string arg2,
     string arg3,
     string arg4,
     CheckUserRightsDelegate <TContext> arg5,
     ISqlExpressionModifier <TContext> arg6,
     SearchFieldOption arg7,
     SearchCriteriaComparison arg8,
     AggregateFunction arg9,
     string arg10,
     string[] arg11
     ) : base(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)
 {
 }
        public SearchIndex CreateSearchIndexSchema(CustomTextSchema schema, string indexName, SelectedProjects selectedProjects)
        {
            // core fields
            var indexFields = new List <SearchField>
            {
                new SearchField("id", SearchFieldDataType.String)
                {
                    IsKey = true
                },
                new SearchField("document_name", SearchFieldDataType.String),
                new SearchField("document_uri", SearchFieldDataType.String)
            };

            // classifers
            if (selectedProjects.IsSelected_SingleClassificationProject)
            {
                var singleClassField = new SearchField(
                    Constants.SearchIndexSingleClassColumnName,
                    SearchFieldDataType.String);
                indexFields.Add(singleClassField);
            }
            if (selectedProjects.IsSelected_MultiClassificationProject)
            {
                var multiClassField = new SearchField(
                    Constants.SearchIndexMultiClassColumnName,
                    SearchFieldDataType.Collection(SearchFieldDataType.String));
                indexFields.Add(multiClassField);
            }

            // extractors
            if (selectedProjects.IsSelected_EntityRecognitionProject)
            {
                foreach (var entityName in schema.EntityNames)
                {
                    var entityField = new SearchField(
                        entityName,
                        SearchFieldDataType.Collection(SearchFieldDataType.String));
                    indexFields.Add(entityField);
                }
            }

            // return
            return(new SearchIndex(indexName)
            {
                Fields = indexFields
            });
        }
예제 #16
0
 /// <summary>
 /// Gets the data type of the field.
 /// </summary>
 /// <param name="type">The field data type.</param>
 /// <param name="collection">Whether the field is a collection of <paramref name="type"/>.</param>
 public SimpleFieldAttribute(SearchFieldDataType type, bool collection = false)
 {
     Type = collection ? SearchFieldDataType.Collection(type) : type;
 }
예제 #17
0
 public EntityAccessInfoListFieldDefinition(string identifier, string sqlExpression, string sortExpression,
                                            GetSqlExpressionDelegate getInnerSqlExpression         = null,
                                            CheckUserRightsDelegate <TContext> isAccessibleByUser  = null,
                                            ISqlExpressionModifier <TContext> accessRightsModifier = null, SearchFieldDataType dataType = null
                                            ) : base()
 {
     _getInnerSqlExpression = getInnerSqlExpression;
 }
예제 #18
0
 public static SearchIndex GetIndex(string name, string synonymMapName) =>
 new SearchIndex(name: name)
 {
     Fields = new List <SearchField>()
     {
         new SearchField("id", SearchFieldDataType.String)
         {
             IsSearchable = true, IsFilterable = true, IsHidden = false, IsSortable = true, IsFacetable = false, IsKey = true
         },
         new SearchField("fileName", SearchFieldDataType.String)
         {
             IsSearchable = false, IsFilterable = false, IsHidden = false, IsSortable = false, IsFacetable = false
         },
         new SearchField("metadata", SearchFieldDataType.String)
         {
             IsSearchable = false, IsFilterable = false, IsHidden = false, IsSortable = false, IsFacetable = false
         },
         new SearchField("text", SearchFieldDataType.String)
         {
             IsSearchable = true, IsFilterable = false, IsHidden = false, IsSortable = false, IsFacetable = false, SynonymMapNames = { synonymMapName }
         },
         new SearchField("entities", SearchFieldDataType.Collection(SearchFieldDataType.String))
         {
             IsSearchable = false, IsFilterable = true, IsHidden = false, IsSortable = false, IsFacetable = true
         },
         new SearchField("cryptonyms", SearchFieldDataType.Collection(SearchFieldDataType.String))
         {
             IsSearchable = false, IsFilterable = true, IsHidden = false, IsSortable = false, IsFacetable = true
         },
         new SearchField("demoBoost", SearchFieldDataType.Int32)
         {
             IsSearchable = false, IsFilterable = true, IsHidden = false, IsSortable = false, IsFacetable = false
         },
         new SearchField("demoInitialPage", SearchFieldDataType.Int32)
         {
             IsSearchable = false, IsFilterable = false, IsHidden = false, IsSortable = false, IsFacetable = false
         },
     },
     ScoringProfiles =
     {
         new ScoringProfile(name: "demoBooster")
         {
             FunctionAggregation = ScoringFunctionAggregation.Sum,
             Functions           =
             {
                 new MagnitudeScoringFunction(
                     fieldName: "demoBoost",
                     boost: 1000,
                     parameters: new MagnitudeScoringParameters(
                         boostingRangeStart: 0,
                         boostingRangeEnd: 100)
                 {
                     ShouldBoostBeyondRangeByConstant = true
                 })
                 {
                     Interpolation = ScoringFunctionInterpolation.Linear
                 }
             }
         }
     },
     CorsOptions = new CorsOptions(allowedOrigins: new List <string>()
     {
         "*"
     }),
     Suggesters =
     {
         new SearchSuggester(name: "sg-jfk", sourceFields: "entities")
     }
 };
예제 #19
0
        public static SearchField ToSearchField(this Azure.Search.Documents.Indexes.Models.SearchField field)
        {
            Type type;

            if (field.Type == SearchFieldDataType.Boolean)
            {
                type = typeof(Boolean);
            }
            else if (field.Type == SearchFieldDataType.DateTimeOffset)
            {
                type = typeof(DateTime);
            }
            else if (field.Type == SearchFieldDataType.Double)
            {
                type = typeof(double);
            }
            else if (field.Type == SearchFieldDataType.Int32)
            {
                type = typeof(Int32);
            }
            else if (field.Type == SearchFieldDataType.Int64)
            {
                type = typeof(Int64);
            }
            else if (field.Type == SearchFieldDataType.String)
            {
                type = typeof(string);
            }
            else if (field.Type == SearchFieldDataType.GeographyPoint)
            {
                type = typeof(GeographyPoint);
            }

            // Azure Search SearchFieldDataType objects don't follow value comparisons, so use overloaded string conversion operator to be a consistent representation
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.String).ToString())
            {
                type = typeof(string[]);
            }
            else if (field.Type == SearchFieldDataType.Complex)
            {
                type = typeof(string);
            }
            else if (field.Type == SearchFieldDataType.Collection(SearchFieldDataType.Complex))
            {
                type = typeof(string[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset).ToString())
            {
                type = typeof(DateTime[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.GeographyPoint).ToString())
            {
                type = typeof(Microsoft.Spatial.GeographyPoint[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.Double).ToString())
            {
                type = typeof(double[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.Boolean).ToString())
            {
                type = typeof(Boolean[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.Int64).ToString())
            {
                type = typeof(Int32[]);
            }
            else if (field.Type.ToString() == SearchFieldDataType.Collection(SearchFieldDataType.Int64).ToString())
            {
                type = typeof(Int64[]);
            }
            else
            {
                throw new ArgumentException($"Cannot map {field.Type} to a C# type");
            }
            return(new SearchField()
            {
                Name = field.Name,
                Type = type,
                IsFacetable = field.IsFacetable ?? false,
                IsFilterable = field.IsFilterable ?? false,
                IsKey = field.IsKey ?? false,
                IsHidden = field.IsHidden ?? false,
                IsSearchable = field.IsSearchable ?? false,
                IsSortable = field.IsSortable ?? false
            });
        }
예제 #20
0
        public void IsCollection(string value, bool expected)
        {
            SearchFieldDataType type = value;

            Assert.AreEqual(expected, type.IsCollection);
        }
예제 #21
0
        public void Collection(string value)
        {
            SearchFieldDataType type = SearchFieldDataType.Collection(value);

            Assert.AreEqual("Collection(Edm.String)", type.ToString());
        }