Example #1
0
 /// <summary>
 /// Initializes a new instance of the ScoringProfile class.
 /// </summary>
 public ScoringProfile(string name, TextWeights textWeights = default(TextWeights), IList <ScoringFunction> functions = default(IList <ScoringFunction>), ScoringFunctionAggregation?functionAggregation = default(ScoringFunctionAggregation?))
 {
     Name                = name;
     TextWeights         = textWeights;
     Functions           = functions;
     FunctionAggregation = functionAggregation;
 }
Example #2
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (Name == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "Name");
     }
     if (TextWeights != null)
     {
         TextWeights.Validate();
     }
     if (Functions != null)
     {
         foreach (var element in Functions)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
 }
Example #3
0
        public string CreateIndex()
        {
            // Create the Azure Search index based on the included schema
            try
            {
                //Create the index definition
                var definition = new Index()
                {
                    Name = _indexName,
                    Fields = new[]
                    {
                    new Field ( "DocumentID", DataType.String) { IsKey = true,  IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                    new Field ( "NodeAliasPath", DataType.String) { IsKey = false,  IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                    new Field ( "QuoteAuthor", DataType.String) { IsKey = false,  IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true, IsRetrievable = true},
                    new Field ( "QuoteText", DataType.String) { IsKey = false, IsSearchable = true,  IsFilterable = true, IsSortable = true,  IsFacetable = true, IsRetrievable = true},
                    new Field ( "QuoteDate", DataType.String) { IsKey = false, IsSearchable = true,  IsFilterable = true, IsSortable = true,  IsFacetable = true, IsRetrievable = true}
                    }
                };

                definition.Suggesters = new List<Suggester> {

                    new Suggester()
                    {
                        Name = "quoteauthor",
                        SearchMode = SuggesterSearchMode.AnalyzingInfixMatching,
                        SourceFields = new List<string> { "QuoteAuthor" }
                    }
                };

                List<ScoringProfile> lstScoringProfiles = new List<ScoringProfile>();
                TextWeights twauthor = new TextWeights();
                twauthor.Weights.Add("QuoteAuthor", 100);
                TextWeights twtext = new TextWeights();
                twtext.Weights.Add("QuoteText", 100);

                lstScoringProfiles.Add(new ScoringProfile()
                {
                    Name = "QuoteAuthor",
                    TextWeights = twauthor
                });
                lstScoringProfiles.Add(new ScoringProfile()
                {
                    Name = "QuoteText",
                    TextWeights = twtext
                });

                definition.ScoringProfiles = lstScoringProfiles;



                _searchClient.Indexes.Create(definition);

                

                return "Index created!";
            }
            catch (Exception ex)
            {
                return "There was an issue creating the index: {0}\r\n" + ex.Message.ToString();
            }
        }