Git Product home page Git Product logo

smartsolrschema's Introduction

SmartSolrSchema

This module enhances the built-in Sitecore Solr Populate Managed Schema functionality by populating not only standard Sitecore dynamic fields but also reads any custom languages that are set up in the Sitecore Master database under /sitecore/system/languages.

Why?

If you add a new language to Sitecore, for example Korean, and start adding items based on that language, when it comes to indexing on Solr you will see issues about missing dynamic fields about the ko language.

Example:

org.apache.solr.common.SolrException: ERROR: [doc=sitecore://master/{bfde3d21-3a67-4938-aa90-33da9caf7bf5}?lang=cs-cz&ver=1] unknown field '__display_name_t_cs'

Usually you would then need to manually patch the Solr schema yourself like this.

That is a very manual process and makes the DevOps side of things much more tricky. So let's automate it!

Date *_dtm Bugfix

This module also fixes a Sitecore bug where Solr datetimeCollection has fieldNameFormat="{0}_dtm" but the schema builder format is "*_tdtm"

Date Sorting

There is a somewhat common issue with sorting by date fields in Solr where it does not always sort correctly. It happens more often if you have a lot of items that you are searching and ordering. This has been blogged about here by Rich Seal, where the fix is to add a date field to the solr managed schema that is indexed="true" stored="false". I have made this easier for you by automatically adding a *_tdts dynamic field with this setting. You can then use it in your project as follows:

  1. Open the App_Config/Modules/SmartSolrSchema/DateTimeSortable.config and uncomment the example computed field. Update the fieldName parameter with your field name.
  2. Add as many fields as you need to sort by here.
  3. Build and deploy your solution and do a full index rebuild
  4. You can now sort by fieldname_tdts which will return accurate results.

Sitecore Version Support

How to install

  1. Install the nuget package.
  2. If you're using PackageReferences then you'll also need to copy in the configs in the package App_Config/Modules/SmartSolrSchema
  3. Build your solution and ensure the SmartSolrSchema.dll and configs are deployed

How to use

  1. Log into Sitecore and go to the Control Panel
  2. Open the Populate Solr Managed Schema window
  3. Check the indexes you want to populate and click Populate
  4. Ensure that the process Succeeded. You can also check the logs to see what custom languages have been populated. For example: SmartSolrSchema: adding custom defined language to schema ko
  5. Close the dialog and open the Indexing Manager
  6. Rebuild the indexes
  7. You can check the Crawling log file to make sure you're not getting errors about unknown fields.

smartsolrschema's People

Contributors

dw-alexangas avatar markgibbons25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

peterrydetorp

smartsolrschema's Issues

SolrProvider.GetHelper is obsolete

Hi Mark,

I am trying to use your library in my sitecore 9.3 (Sitecore 9.3.0 rev. 003498 (OnPrem)_single.scwdp) project and I found an issue with some obsolete code - so your library does not work in v9.3
When trying to use it with Sitecore.ContentSearch.SolrProvider dll v6.0.0 it fails with an exceptoin "unable to find the constructor".

After digging the code I found out the issue lies in 'Sitecore.ContentSearch.SolrProvider.Pipelines.PopulateSolrSchema.PopulateFields' class of the sitecore library.

Both constructor and GetHelper are marked now as obsolete and are not used anymore in sitecore

[Obsolete("Please use PopulateFields(IPopulateHelperFactory) constructor instead")]
public PopulateFields()
[Obsolete("This method is not in use anymore, use IPopulateHelperFactory.GetPopulateHelper instead")]
protected virtual ISchemaPopulateHelper GetHelper(SolrSchema schema)

So I manage to get it work by replacing your PopulateFields helper class with this code:

  public class PopulateFields : Sitecore.ContentSearch.SolrProvider.Pipelines.PopulateSolrSchema.PopulateFields
    {
        private readonly IPopulateHelperFactory populateHelperFactory;
        public PopulateFields(IPopulateHelperFactory populateFactory) : base(populateFactory)
        {
            populateHelperFactory = populateFactory;
        }

        public override void Process(PopulateManagedSchemaArgs args)
        {
            var solrIndex = (args.Index as SolrSearchIndex);
            var schema = (SolrIndexSchema)solrIndex.Schema;
            var helper = new PopulateSolrSchemaHelper(schema.SolrSchema);

            var solrConnector = (ISolrConnector)solrIndex.GetType().GetProperty("SolrConnector", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(solrIndex, null);
            if (solrConnector != null)
            {
                foreach (string core in args.Cores)
                {
                    var operations = solrConnector.OperationsFactory.GetSolrOperations(core);
                    var elements = helper.GetAllFields().ToList();
                    operations.UpdateSchema(elements);

                }
            }
        }
    }

Do you think this is the right approach? So far I got back all missing fields in my solr managed schema...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.