solr express
Search…
Dynamic field behaviour

Feature

Use dynamic fields controlled by you in code
Useful when use a unified collection and isolate your tenant by a prefix/suffix in each field

How to

  1. 1.
    You need prepare your SOLR collection with dynamic fields, to do this, follow steps in SOLR wiki
  2. 2.
    Choose one or more approachs:
    2.1. Using global settings (see </tutorials/global-settings> to more informations), than all searchs will use prefix and/or suffix setted in global settings (useful when you know your tenant in app startup)
    2.1.1. Set global settings
    1
    services
    2
    .AddSolrExpress<TechProduct>(builder => builder
    3
    .UseOptions(options =>
    4
    {
    5
    // ... Other settings
    6
    options.GlobalDynamicFieldPrefix = "my_prefix_",
    7
    options.GlobalDynamicFieldSuffix = "_my_suffix"
    8
    })
    9
    // ... Other settings
    10
    );
    Copied!
    2.1.2. Optionally, set global settings for specific field
    1
    using SolrExpress.Search.Behaviour.Extension;
    2
    3
    services.AddSolrExpress<TechProduct>(q => q
    4
    .ChangeDynamicFieldBehaviour(q => q.Manufacturer, prefixName: "my_prefix_", suffixName: "_my_suffix")
    5
    // ... Other settings
    6
    );
    Copied!
    2.1.3. Change your class that represent your collection, extend Document (see </tutorials/getting-started> to more informations), set dynamic field in SolrFieldAttribute, like below:
    1
    public class MyDocument : Document
    2
    {
    3
    [SolrField("myfield_s", IsDynamicField = true)]
    4
    public string MyField { get; set; }
    5
    }
    Copied!
    2.2. Using settings to each search, than only this search will use prefix and/or suffix (useful when you know your tenant only in after some process)
    2.2.1. Set settings in your search
    1
    using SolrExpress.Search.Behaviour.Extension;
    2
    3
    DocumentSearch<TechProduct> documentSearch; // From your DI provider
    4
    documentSearch
    5
    .ChangeDynamicFieldBehaviour(q => q.Manufacturer, prefixName: "my_prefix_", suffixName: "_my_suffix")
    6
    // ... Other settings
    7
    .Execute();
    Copied!
    2.2.2. Change your class that represent your collection, extend Document (see </tutorials/getting-started> to more informations), set dynamic field in SolrFieldAttribute, like below:
    1
    public class MyDocument : Document
    2
    {
    3
    [SolrField("myfield_s", IsDynamicField = true)]
    4
    public string MyField { get; set; }
    5
    }
    Copied!
    2.3. Using settings to each field, than all searchs will use prefix and/or suffix setted in field settings (useful when you know your tenant in hard code)
    2.3.1. Change your class that represent your collection, extend Document (see </tutorials/getting-started> to more informations), set settings in SolrFieldAttribute, like below:
    1
    public class MyDocument : Document
    2
    {
    3
    [SolrField("myfield_s", IsDynamicField = true, DynamicFieldPrefixName = "my_prefix_", DynamicFieldSuffixName = "_my_suffix")]
    4
    public string MyField { get; set; }
    5
    }
    Copied!

NOTE

See another example in issue 206;
Last modified 2yr ago
Copy link