Skip to main content
Required ACL: editSettings

Usage

// Initialize the client
var client = new CompositionClient(
  new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);

// Call the API
var response = await client.SaveRulesAsync(
  "my-compo",
  new CompositionRulesBatchParams
  {
    Requests = new List<RulesMultipleBatchRequest>
    {
      new RulesMultipleBatchRequest
      {
        Action = Enum.Parse<Action>("Upsert"),
        Body = new RulesBatchCompositionAction(
          new CompositionRule
          {
            ObjectID = "rule-with-deduplication",
            Description = "my description",
            Enabled = true,
            Conditions = new List<Condition>
            {
              new Condition
              {
                Anchoring = Enum.Parse<Anchoring>("Contains"),
                Pattern = "harry",
              },
            },
            Consequence = new CompositionRuleConsequence
            {
              Behavior = new CompositionBehavior
              {
                Injection = new Injection
                {
                  Main = new Main
                  {
                    Source = new CompositionSource
                    {
                      Search = new CompositionSourceSearch { Index = "my-index" },
                    },
                  },
                  InjectedItems = new List<InjectedItem>
                  {
                    new InjectedItem
                    {
                      Key = "my-unique-injected-item-key",
                      Source = new InjectedItemSource(
                        new SearchSource
                        {
                          Search = new Algolia.Search.Models.Composition.Search
                          {
                            Index = "my-index",
                          },
                        }
                      ),
                      Position = 0,
                      Length = 3,
                    },
                  },
                  Deduplication = new Deduplication
                  {
                    Positioning = Enum.Parse<DedupPositioning>("HighestInjected"),
                  },
                },
              },
            },
          }
        ),
      },
    },
  }
);
// >LOG

See the full API reference

For more details about input parameters and response fields.
I