private static void CreateIndex(SearchServiceClient serviceClient) { var indexDefinition = new Index { Name = IndexName, Fields = new[] { new Field("topicID", DataType.String) { IsKey = true, IsSearchable = false }, new Field("forumID", DataType.Int32) { IsFilterable = true, IsSearchable = false }, new Field("title", DataType.String) { IsSearchable = true, IsSortable = true }, new Field("lastPostTime", DataType.DateTimeOffset) { IsSortable = true, IsSearchable = false }, new Field("startedByName", DataType.String) { IsSortable = true, IsSearchable = true }, new Field("replies", DataType.Int32) { IsSortable = true, IsSearchable = false }, new Field("views", DataType.Int32) { IsSortable = true, IsSearchable = false }, new Field("isClosed", DataType.Boolean) { IsSortable = false, IsSearchable = false }, new Field("isPinned", DataType.Boolean) { IsSortable = false, IsSearchable = false }, new Field("urlName", DataType.String) { IsSortable = false, IsSearchable = false }, new Field("lastPostName", DataType.String) { IsSortable = false, IsSearchable = false }, new Field("posts", DataType.Collection(DataType.String)) { IsSortable = false, IsSearchable = true } } }; serviceClient.Indexes.Create(indexDefinition); }
private static void CreateBookableIndex(SearchServiceClient serviceClient) { var definition = new Index() { Name = "bookable", Fields = new[] { new Field("Id", DataType.String) { IsKey = true }, new Field("Name", DataType.String) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("Tags", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, } }; serviceClient.Indexes.Create(definition); }
public static DataType ToAzureDataType(this Type type) { if (type == typeof(string)) { return(DataType.String); } if (type == typeof(bool)) { return(DataType.Boolean); } if (type == typeof(HexBigInteger)) { return(DataType.String); } if (type == typeof(BigInteger)) { return(DataType.String); } if (type.IsArray) { return(DataType.Collection(type.GetElementType().ToAzureDataType())); } if (type.IsListOfT()) { return(DataType.Collection(type.GetGenericArguments()[0].ToAzureDataType())); } return(DataType.String); }
private async static Task CreateItemsIndexAsync() { // Create the Azure Search index based on the included schema try { var definition = new Index() { Name = m_ItemsIndexName, Fields = new[] { new Field("Id", DataType.String) { IsKey = true, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("Tags", DataType.Collection(DataType.String)) { IsKey = false, IsSearchable = true, IsFilterable = true, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("SourceUrl", DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("Title", DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("ThumbnailUrl", DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("Description", DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("EntryType", DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("Language", DataType.String) { IsKey = false, IsSearchable = true, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, new Field("FruitionTime", DataType.Double) { IsKey = false, IsSearchable = false, IsFilterable = true, IsSortable = true, IsFacetable = false, IsRetrievable = true }, new Field("Category", DataType.String) { IsKey = false, IsSearchable = true, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }, } }; await m_SearchClient.Indexes.CreateAsync(definition); } catch (Exception ex) { Console.WriteLine("Error creating index: {0}", ex.Message); } }
/// <summary> /// Creates the index of the search. /// </summary> /// <param name="searchIndex">Index of the search.</param> /// <param name="serviceClient">The service client.</param> private static void CreateSearchIndex(string searchIndex, ISearchServiceClient serviceClient) { var definition = new Index { Name = searchIndex, Fields = new[] { new Field("blogId", DataType.String) { IsKey = true }, new Field("title", DataType.String) { IsSearchable = true, IsFilterable = true }, new Field("searchTags", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true } } }; serviceClient.Indexes.Create(definition); }
public DataType GetType(string type) { switch (type) { case "System.List": return(DataType.Collection(DataType.String)); case "System.Double": return(DataType.Double); case "System.Boolean": return(DataType.Boolean); case "System.DateTime": return(DataType.DateTimeOffset); case "GeographyPoint": return(DataType.GeographyPoint); case "System.Int32": return(DataType.Int32); case "System.Int64": return(DataType.Int64); case "System.String": case "System.GUID": default: return(DataType.String); } }
public void CanUseAllAnalyzerNamesInIndexDefinition() { Run(() => { SearchServiceClient client = Data.GetSearchServiceClient(); Index index = new Index() { Name = SearchTestUtilities.GenerateName(), Fields = new[] { new Field("id", DataType.String) { IsKey = true } }.ToList() }; AnalyzerName[] allAnalyzers = GetAllExtensibleEnumValues <AnalyzerName>(); for (int i = 0; i < allAnalyzers.Length; i++) { string fieldName = String.Format("field{0}", i); DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String); index.Fields.Add(new Field(fieldName, fieldType, allAnalyzers[i])); } client.Indexes.Create(index); }); }
public void SearchableCollectionFactoryMethodSetsAllProperties() { var expectedField = new Field("test", DataType.Collection(DataType.String)) { IsKey = true, IsRetrievable = true, IsSearchable = true, IsFilterable = true, IsSortable = false, IsFacetable = true, Analyzer = AnalyzerName.StandardAsciiFoldingLucene, SearchAnalyzer = null, IndexAnalyzer = null, SynonymMaps = new[] { "map" } }; var actualField = Field.NewSearchableCollection( name: expectedField.Name, analyzerName: expectedField.Analyzer.Value, isKey: expectedField.IsKey.Value, isRetrievable: expectedField.IsRetrievable.Value, isFilterable: expectedField.IsFilterable.Value, isFacetable: expectedField.IsFacetable.Value, synonymMaps: expectedField.SynonymMaps); Assert.Equal(expectedField, actualField, new DataPlaneModelComparer <Field>()); }
public static void CreateIndex(SearchServiceClient serviceClient, string indexName) { if (serviceClient.Indexes.Exists(indexName)) { serviceClient.Indexes.Delete(indexName); } var definition = new Index() { Name = indexName, Fields = new[] { new Field("fileId", DataType.String) { IsKey = true }, new Field("summary", DataType.String) { IsSearchable = true, IsFilterable = false, IsSortable = false, IsFacetable = false }, new Field("keyPhrases", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true } } }; serviceClient.Indexes.Create(definition); }
private Task CreateIndexAsync(string indexName) { var suggester = new Suggester { Name = "sg", //SearchMode = "analyzingInfixMatching", SourceFields = new List <string> { "Name", "FacilityName" } }; var definition = new Index { Name = indexName, Fields = new List <Field> { new Field("Id", DataType.String) { IsKey = true }, new Field("FacilityId", DataType.Int32) { IsFilterable = true }, new Field("Name", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true }, new Field("Description", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true }, new Field("FacilityName", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true }, new Field("FacilityDescription", DataType.String, AnalyzerName.EnMicrosoft) { IsSearchable = true }, new Field("Location", DataType.GeographyPoint) { IsFilterable = true }, new Field("RoomCount", DataType.Int32) { IsFilterable = true }, new Field("Images", DataType.Collection(DataType.String)) { IsFilterable = false } }, Suggesters = new List <Suggester> { suggester } }; return(client.Indexes.CreateAsync(definition)); }
public void CanBuildComplexFieldViaFactoryMethod() { var field = Field.NewComplex("test", isCollection: true, fields: new[] { subField }); AssertIsComplex(field, "test", DataType.Collection(DataType.Complex)); Assert.Collection(field.Fields, f => Assert.Same(subField, f)); }
public static Index CreateTestIndex(string indexName) => // This is intentionally a different index definition than the one returned by IndexManagementTests.CreateTestIndex(). // That index is meant to exercise serialization of the index definition itself, while this one is tuned // more for exercising document serialization, indexing, and querying operations. Also, the fields of this index should // exactly match the properties of the Hotel test model class. new Index() { Name = indexName, Fields = new[] { Field.New("hotelId", DataType.String, isKey: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("hotelName", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: false), Field.NewSearchableString("description", AnalyzerName.EnLucene), Field.NewSearchableString("descriptionFr", AnalyzerName.FrLucene), Field.New("category", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("tags", DataType.Collection(DataType.String), isSearchable: true, isFilterable: true, isFacetable: true), Field.New("parkingIncluded", DataType.Boolean, isFilterable: true, isSortable: true, isFacetable: true), Field.New("smokingAllowed", DataType.Boolean, isFilterable: true, isSortable: true, isFacetable: true), Field.New("lastRenovationDate", DataType.DateTimeOffset, isFilterable: true, isSortable: true, isFacetable: true), Field.New("rating", DataType.Int32, isFilterable: true, isSortable: true, isFacetable: true), Field.New("location", DataType.GeographyPoint, isFilterable: true, isSortable: true), Field.NewComplex("address", isCollection: false, fields: new[] { Field.New("streetAddress", DataType.String, isSearchable: true), Field.New("city", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("stateProvince", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("country", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("postalCode", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true) }), Field.NewComplex("rooms", isCollection: true, fields: new[] { Field.NewSearchableString("description", AnalyzerName.EnLucene), Field.NewSearchableString("descriptionFr", AnalyzerName.FrLucene), Field.New("type", DataType.String, isSearchable: true, isFilterable: true, isFacetable: true), Field.New("baseRate", DataType.Double, isFilterable: true, isFacetable: true), Field.New("bedOptions", DataType.String, isSearchable: true, isFilterable: true, isFacetable: true), Field.New("sleepsCount", DataType.Int32, isFilterable: true, isFacetable: true), Field.New("smokingAllowed", DataType.Boolean, isFilterable: true, isFacetable: true), Field.New("tags", DataType.Collection(DataType.String), isSearchable: true, isFilterable: true, isFacetable: true) }) }, Suggesters = new[] { new Suggester( name: "sg", sourceFields: new[] { "description", "hotelName" }) }, ScoringProfiles = new[] { new ScoringProfile("nearest") { FunctionAggregation = ScoringFunctionAggregation.Sum, Functions = new[] { new DistanceScoringFunction("location", 2, new DistanceScoringParameters("myloc", 100)) } } } };
private static DataType GetDataType(Type propertyType, string propertyName) { if (propertyType == typeof(string)) { return(DataType.String); } if (propertyType.IsConstructedGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(GetDataType(propertyType.GenericTypeArguments[0], propertyName)); } if (propertyType == typeof(int)) { return(DataType.Int32); } if (propertyType == typeof(long)) { return(DataType.Int64); } if (propertyType == typeof(double)) { return(DataType.Double); } if (propertyType == typeof(bool)) { return(DataType.Boolean); } if (propertyType == typeof(DateTimeOffset) || propertyType == typeof(DateTime)) { return(DataType.DateTimeOffset); } if (propertyType == typeof(GeographyPoint)) { return(DataType.GeographyPoint); } Type elementType = GetElementTypeIfIEnumerable(propertyType); if (elementType != null) { return(DataType.Collection(GetDataType(elementType, propertyName))); } TypeInfo ti = propertyType.GetTypeInfo(); var listElementTypes = ti .ImplementedInterfaces .Select(GetElementTypeIfIEnumerable) .Where(p => p != null) .ToList(); if (listElementTypes.Count == 1) { return(DataType.Collection(GetDataType(listElementTypes[0], propertyName))); } throw new ArgumentException( $"Property {propertyName} has unsupported type {propertyType}", nameof(propertyType)); }
public static async Task <Index> GetBaseIndex(string name) { var analyzerName = AnalyzerName.StandardLucene; return(await Task.FromResult(new Index { Name = name, Fields = new List <Field> { new Field("created_at", DataType.DateTimeOffset) { IsFilterable = true, IsRetrievable = true }, new Field("id_str", analyzerName), new Field("id", analyzerName), new Field("text", analyzerName), new Field("rid", analyzerName) { IsKey = true }, new Field("people", DataType.Collection(DataType.String), analyzerName), new Field("organizations", DataType.Collection(DataType.String), analyzerName), new Field("locations", DataType.Collection(DataType.String), analyzerName), new Field("keyphrases", DataType.Collection(DataType.String), analyzerName), new Field("language", analyzerName), new Field("user", DataType.Complex, new List <Field> { new Field("id", DataType.Int64), new Field("id_str", analyzerName), new Field("name", analyzerName), new Field("screen_name", analyzerName), new Field("location", analyzerName), new Field("url", analyzerName), new Field("description", analyzerName) }), new Field("entities", DataType.Complex, new List <Field> { new Field("hashtags", DataType.Collection(DataType.Complex), new List <Field> { new Field("indicies", analyzerName), new Field("text", analyzerName), }), new Field("user_mentions", DataType.Collection(DataType.Complex), new List <Field> { new Field("id", DataType.Int64), new Field("id_str", analyzerName), new Field("indicies", DataType.Collection(DataType.Int64)), new Field("name", analyzerName), new Field("screen_name", analyzerName), }) }), new Field("symbols", DataType.Collection(DataType.String), analyzerName), new Field("urls", DataType.Collection(DataType.String), analyzerName) } })); }
private static void CreateHotelsIndex(SearchServiceClient serviceClient) { var definition = new Index() { Name = "hotels", Fields = new[] { new Field("hotelId", DataType.String) { IsKey = true, IsFilterable = true }, new Field("baseRate", DataType.Double) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("description", DataType.String) { IsSearchable = true }, new Field("description_fr", AnalyzerName.FrLucene), new Field("hotelName", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true }, new Field("category", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("tags", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("parkingIncluded", DataType.Boolean) { IsFilterable = true, IsFacetable = true }, new Field("smokingAllowed", DataType.Boolean) { IsFilterable = true, IsFacetable = true }, new Field("lastRenovationDate", DataType.DateTimeOffset) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("rating", DataType.Int32) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("location", DataType.GeographyPoint) { IsFilterable = true, IsSortable = true } } }; serviceClient.Indexes.Create(definition); }
/// <summary> /// Get a Search Index for the Hotels sample data. /// /// This index is tuned more for exercising document serialization, /// indexing, and querying operations. Also, the fields of this index /// should exactly match the properties of the Hotel test model class /// below. /// </summary> /// <param name="name"></param> /// <returns></returns> private static Microsoft.Azure.Search.Models.Index GetHotelIndex(string name) => new Microsoft.Azure.Search.Models.Index() { Name = name, Fields = new[] { Field.New("hotelId", DataType.String, isKey: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("hotelName", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: false), Field.NewSearchableString("description", AnalyzerName.EnLucene), Field.NewSearchableString("descriptionFr", AnalyzerName.FrLucene), Field.New("category", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("tags", DataType.Collection(DataType.String), isSearchable: true, isFilterable: true, isFacetable: true), Field.New("parkingIncluded", DataType.Boolean, isFilterable: true, isSortable: true, isFacetable: true), Field.New("smokingAllowed", DataType.Boolean, isFilterable: true, isSortable: true, isFacetable: true), Field.New("lastRenovationDate", DataType.DateTimeOffset, isFilterable: true, isSortable: true, isFacetable: true), Field.New("rating", DataType.Int32, isFilterable: true, isSortable: true, isFacetable: true), Field.New("location", DataType.GeographyPoint, isFilterable: true, isSortable: true), Field.NewComplex("address", isCollection: false, fields: new[] { Field.New("streetAddress", DataType.String, isSearchable: true), Field.New("city", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("stateProvince", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("country", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true), Field.New("postalCode", DataType.String, isSearchable: true, isFilterable: true, isSortable: true, isFacetable: true) }), Field.NewComplex("rooms", isCollection: true, fields: new[] { Field.NewSearchableString("description", AnalyzerName.EnLucene), Field.NewSearchableString("descriptionFr", AnalyzerName.FrLucene), Field.New("type", DataType.String, isSearchable: true, isFilterable: true, isFacetable: true), Field.New("baseRate", DataType.Double, isFilterable: true, isFacetable: true), Field.New("bedOptions", DataType.String, isSearchable: true, isFilterable: true, isFacetable: true), Field.New("sleepsCount", DataType.Int32, isFilterable: true, isFacetable: true), Field.New("smokingAllowed", DataType.Boolean, isFilterable: true, isFacetable: true), Field.New("tags", DataType.Collection(DataType.String), isSearchable: true, isFilterable: true, isFacetable: true) }) }, Suggesters = new[] { new Suggester( name: "sg", sourceFields: new[] { "description", "hotelName" }) }, ScoringProfiles = new[] { new ScoringProfile("nearest") { FunctionAggregation = ScoringFunctionAggregation.Sum, Functions = new[] { new DistanceScoringFunction("location", 2, new DistanceScoringParameters("myloc", 100)) } } } };
public override void Initialize(MockContext context) { base.Initialize(context); SearchServiceClient searchClient = this.GetSearchServiceClient(); TargetIndexName = SearchTestUtilities.GenerateName(); DataSourceName = SearchTestUtilities.GenerateName(); var index = new Index( TargetIndexName, new[] { new Field("feature_id", DataType.String) { IsKey = true }, new Field("feature_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("feature_class", DataType.String), new Field("state", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("county_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("elevation", DataType.Int32) { IsFilterable = true }, new Field("map_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("history", DataType.Collection(DataType.String)) { IsSearchable = true } }); searchClient.Indexes.Create(index); var dataSource = DataSource.AzureSql( name: DataSourceName, sqlConnectionString: AzureSqlReadOnlyConnectionString, tableOrViewName: AzureSqlTestTableName); searchClient.DataSources.Create(dataSource); }
public static Field ToAzureField(this SearchField f) { return(new Field(f.Name.ToAzureFieldName(), f.IsCollection ? DataType.Collection(f.DataType.ToAzureDataType()) : f.DataType.ToAzureDataType()) { IsKey = f.IsKey, IsFilterable = f.IsFilterable, IsSortable = f.IsSortable, IsSearchable = f.IsSearchable, IsFacetable = f.IsFacetable, }); }
public static SearchField ToSearchField(this Field field) { Type type; if (field.Type == DataType.Boolean) { type = typeof(Boolean); } else if (field.Type == DataType.DateTimeOffset) { type = typeof(DateTime); } else if (field.Type == DataType.Double) { type = typeof(double); } else if (field.Type == DataType.Int32) { type = typeof(Int32); } else if (field.Type == DataType.Int64) { type = typeof(Int64); } else if (field.Type == DataType.String) { type = typeof(string); } else if (field.Type == DataType.GeographyPoint) { type = typeof(Microsoft.Spatial.GeographyPoint); } // Azure Search DataType objects don't follow value comparisons, so use overloaded string conversion operator to be a consistent representation else if ((string)field.Type == (string)DataType.Collection(DataType.String)) { type = typeof(string[]); } else { throw new ArgumentException($"Cannot map {field.Type} to a C# type"); } return(new SearchField() { Name = field.Name, Type = type, IsFacetable = field.IsFacetable, IsFilterable = field.IsFilterable, IsKey = field.IsKey, IsRetrievable = field.IsRetrievable, IsSearchable = field.IsSearchable, IsSortable = field.IsSortable }); }
public void ToAzureField_ConvertsToCollectionDataType() { var eventSearchField = new SearchField("FieldA.Val") { DataType = typeof(string), IsCollection = true }; var azureField = eventSearchField.ToAzureField(); Assert.Equal(DataType.Collection(DataType.String), azureField.Type); }
public static void ResetIndexes() { SearchServiceClient serviceClient = GetServiceClient(); if (serviceClient.Indexes.Exists(doc_index)) { serviceClient.Indexes.Delete(doc_index); } var definition = new Index() { Name = doc_index, Fields = new[] { new Field("docId", DataType.String) { IsKey = true, IsFilterable = true }, new Field("clientId", DataType.String) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("docFileName", DataType.String) { IsFilterable = true, IsSearchable = true, IsSortable = true }, new Field("docUrl", DataType.String) { IsFilterable = true, IsSortable = true }, new Field("content", DataType.String) { IsSearchable = true, Analyzer = AnalyzerName.EnMicrosoft }, new Field("categories", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("insertDate", DataType.DateTimeOffset) { IsFilterable = true, IsSortable = true, IsFacetable = true } } }; serviceClient.Indexes.Create(definition); }
public void CanUseAllAnalyzerNamesInIndexDefinition() { Run(() => { SearchServiceClient client = Data.GetSearchServiceClient(); Index index = new Index() { Name = SearchTestUtilities.GenerateName(), Fields = new[] { new Field("id", DataType.String) { IsKey = true } }.ToList() }; AnalyzerName[] allAnalyzers = GetAllExtensibleEnumValues <AnalyzerName>(); int fieldNumber = 0; // All analyzer names can be set on the analyzer property. for (int i = 0; i < allAnalyzers.Length; i++) { DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String); index.Fields.Add(new Field($"field{fieldNumber++}", fieldType, allAnalyzers[i])); } // Only non-language analyzer names can be set on the searchAnalyzer and indexAnalyzer properties. // ASSUMPTION: Only language analyzers end in .lucene or .microsoft. var allNonLanguageAnalyzers = allAnalyzers.Where(a => !a.ToString().EndsWith(".lucene") && !a.ToString().EndsWith(".microsoft")).ToArray(); for (int i = 0; i < allNonLanguageAnalyzers.Length; i++) { DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String); var field = new Field($"field{fieldNumber++}", fieldType) { IsSearchable = true, SearchAnalyzer = allNonLanguageAnalyzers[i], IndexAnalyzer = allNonLanguageAnalyzers[i] }; index.Fields.Add(field); } client.Indexes.Create(index); }); }
private static Index GetDefinition(Type type) { var properties = type.GetProperties().OrderBy(x => x.MetadataToken).ToArray(); var fields = new List <Field>(); foreach (var propertyInfo in properties) { var attributes = propertyInfo.CustomAttributes.ToArray(); if (attributes.All(x => x.AttributeType != typeof(JsonIgnoreAttribute))) { DataType dataType; if (propertyInfo.PropertyType.IsArray) { if (!TypeMapping.TryGetValue(propertyInfo.PropertyType.GetElementType(), out var arrayElementType)) { throw new ArgumentException($"{propertyInfo.PropertyType.Name} is not supported"); } dataType = DataType.Collection(arrayElementType); } else { if (!TypeMapping.TryGetValue(propertyInfo.PropertyType, out dataType)) { throw new ArgumentException($"{propertyInfo.PropertyType.Name} is not supported"); } } var jsonProperty = propertyInfo.GetCustomAttribute <JsonPropertyAttribute>(); var field = new Field { Name = jsonProperty != null ? jsonProperty.PropertyName : propertyInfo.Name, Type = dataType, IsKey = attributes.Any(x => x.AttributeType.Name == "KeyAttribute"), IsSearchable = attributes.Any(x => x.AttributeType == typeof(IsSearchableAttribute)), IsFilterable = attributes.Any(x => x.AttributeType == typeof(IsFilterableAttribute)), IsFacetable = attributes.Any(x => x.AttributeType == typeof(IsFacetableAttribute)), IsSortable = attributes.Any(x => x.AttributeType == typeof(IsSortableAttribute)), }; fields.Add(field); } } return(new Index() { Name = type.Name.ToLowerInvariant(), Fields = fields.ToArray() }); }
public void Create() { Index index; var iRepository = new SearchRepository.IndexRepository(); var indexAdd = new Index() { Name = "telindex", //please be aware index name should contain only lowercase letters Fields = new[] { new Field("telNo", DataType.String) { IsKey = true }, // Id (IsKey = true) field should be edm.string !! new Field("firstName", DataType.String) { IsSearchable = true, IsFilterable = true }, new Field("lastName", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("telType", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("tags", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("locationMargin", DataType.Double) { IsSortable = true, IsFilterable = true }, new Field("isPersonal", DataType.Boolean) { IsFilterable = true, IsFacetable = true } } }; Task.Run(async() => { index = await iRepository.CreateAsync(indexAdd); Assert.IsNotNull(index); }).GetAwaiter().GetResult(); }
public AzureSearchService(IOptions <SiteSettings> ss, ILogger log) { if (ss.Value.SearchApiKey == null) { throw new ArgumentNullException("AppSettings:SearchApiKey is not set"); } this._serviceClient = new SearchServiceClient(ss.Value.SearchName, new SearchCredentials(ss.Value.SearchApiKey)); this._log = log; this._index = new Index() { Name = _buildIndexName, Fields = new[] { new Field("Id", DataType.String) { IsKey = true }, new Field("Title", DataType.String) { IsSearchable = true }, new Field("Parts", DataType.Collection(DataType.String)) { IsSearchable = true }, new Field("Json", DataType.String) { IsSearchable = false } }, Suggesters = new List <Suggester>() { new Suggester("default", SuggesterSearchMode.AnalyzingInfixMatching, "Title", "Parts") }, CorsOptions = new CorsOptions(new List <string> { "*" }) }; this._serviceClient.Indexes.CreateOrUpdate(this._index); this._indexClient = this._serviceClient.Indexes.GetClient(_buildIndexName); }
private static void CreateCarModelIndex() { _client.Indexes.Delete(IndexName); var index = new Index { Name = IndexName, Fields = new List <Field> { new Field("id", DataType.String) { IsKey = true, IsRetrievable = true }, new Field("makerId", DataType.String) { IsFacetable = true, IsRetrievable = true }, new Field("makerName", DataType.String) { IsSearchable = true }, new Field("makerCountry", DataType.String) { IsFilterable = true }, new Field("modelName", DataType.String) { IsSearchable = true }, new Field("price", DataType.Double) { IsSortable = true, IsFilterable = true }, new Field("features", DataType.Collection(DataType.String)) { IsFilterable = true } } }; _client.Indexes.Create(index); }
public static void ReCreateIndex() { // Delete and re-create the index if (serviceClient.Indexes.Exists(indexName)) { serviceClient.Indexes.Delete(indexName); } var definition = new Index() { Name = indexName, Fields = new[] { new Field("id", DataType.String) { IsKey = true }, new Field("name", DataType.String) { IsSearchable = true, IsFilterable = false, IsSortable = false, IsFacetable = false }, new Field("company", DataType.String) { IsSearchable = true, IsFilterable = false, IsSortable = false, IsFacetable = false }, new Field("locationsId", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("locationsDescription", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("locationsCombined", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true } } }; serviceClient.Indexes.Create(definition); }
private static void CreateIndex(SearchServiceClient serviceClient) { var definition = new Index() { Name = "posts", Fields = new[] { new Field("guid", DataType.String) { IsKey = true }, new Field("title", DataType.String) { IsSearchable = true, IsFilterable = true, IsRetrievable = true }, new Field("content", DataType.String) { IsSearchable = true }, new Field("description", DataType.String) { IsRetrievable = true }, new Field("link", DataType.String) { IsRetrievable = true }, new Field("category", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("pubDate", DataType.DateTimeOffset) { IsFilterable = true, IsRetrievable = true, IsSortable = true, IsFacetable = true }, } }; serviceClient.Indexes.Create(definition); }
private static void AddCustomFormRecognizerSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, AppConfig config, string modelId) { var headers = new Dictionary <string, string> { { "Content-Type", "application/json" } }; index.Fields.Add(new Field($"formHeight", DataType.Int32)); index.Fields.Add(new Field($"formWidth", DataType.Int32)); index.Fields.Add(new Field($"formKeyValuePairs", DataType.Collection(DataType.String))); index.Fields.Add(new Field($"formColumns", DataType.Collection(DataType.String))); indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formHeight", "formHeight").GetAwaiter().GetResult()); indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formWidth", "formWidth").GetAwaiter().GetResult()); indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formKeyValuePairs", "formKeyValuePairs").GetAwaiter().GetResult()); indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formColumns", "formColumns").GetAwaiter().GetResult()); // Create the custom translate skill skillset.Skills.Add(new WebApiSkill { Description = "Custom Form Recognizer skill", Context = "/document", Uri = $"{config.FunctionApp.Url}/api/AnalyzeForm?code={config.FunctionApp.DefaultHostKey}&modelId={modelId}", HttpMethod = "POST", //HttpHeaders = new WebApiHttpHeaders(), // This is broken in the SDK, so handle by sending JSON directly to Rest API. BatchSize = 1, Inputs = new List <InputFieldMappingEntry> { new InputFieldMappingEntry("contentType", "/document/fileContentType"), new InputFieldMappingEntry("storageUri", "/document/storageUri"), new InputFieldMappingEntry("storageSasToken", "/document/sasToken") }, Outputs = new List <OutputFieldMappingEntry> { new OutputFieldMappingEntry("formHeight", "formHeight"), new OutputFieldMappingEntry("formWidth", "formWidth"), new OutputFieldMappingEntry("formKeyValuePairs", "formKeyValuePairs"), new OutputFieldMappingEntry("formColumns", "formColumns"), } }); }
public Task StartAsync(IDialogContext context) { SearchDialogIndexClient.Schema = new SearchSchema().AddFields( new Field[] { new Field() { Name = "business_title", Type = DataType.String, IsFacetable = true, IsFilterable = true, IsKey = false, IsRetrievable = true, IsSearchable = true, IsSortable = true }, new Field() { Name = "agency", Type = DataType.String, IsFacetable = true, IsFilterable = true, IsKey = false, IsRetrievable = true, IsSearchable = true, IsSortable = true }, new Field { Name = "work_location", Type = DataType.String, IsFacetable = true, IsFilterable = true, IsKey = false, IsRetrievable = true, IsSearchable = true, IsSortable = true }, new Field { Name = "tags", Type = DataType.Collection(DataType.String), IsFacetable = true, IsFilterable = true, IsKey = false, IsRetrievable = true, IsSearchable = true, IsSortable = false }, }); context.Wait(SelectTitle); return(Task.CompletedTask); }