Sitecore synonym search file location

I changed the defaultIndexConfiguration configuration file for synonyms search ( http://firebreaksice.com/sitecore-synonym-search-with-lucene/ ) and it works fine. However, this is based on an XML file in the file system.

<param hint="engine" type="Sitecore.ContentSearch.LuceneProvider.Analyzers.XmlSynonymEngine, Sitecore.ContentSearch.LuceneProvider">
   <param hint="xmlSynonymFilePath">C:\inetpub\wwwroot\website\Data\synonyms.xml</param>
</param>

What I would like to do is manage the data in the CMS. Does anyone know how I can set this xmlSynonymFilePath parameter to achieve what I want? Or am I missing something?

+4
source share
1 answer

Sitecore (, /sitecore/system/synonyms) Synonyms xml , .

ISynonymEngine ( - ):

public class CustomSynonymEngine : Sitecore.ContentSearch.LuceneProvider.Analyzers.ISynonymEngine
{
    private readonly List<ReadOnlyCollection<string>> _synonymGroups = new List<ReadOnlyCollection<string>>();

    public CustomSynonymEngine()
    {
        Database database = Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database ?? Database.GetDatabase("web");
        Item item = database.GetItem("/sitecore/system/synonyms"); // or whatever is the path
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(item["synonyms"]);
        XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/synonyms/group");

        if (xmlNodeList == null)
            throw new InvalidOperationException("There are no synonym groups in the file.");

        foreach (IEnumerable source in xmlNodeList)
            _synonymGroups.Add(
                new ReadOnlyCollection<string>(
                    source.Cast<XmlNode>().Select(synNode => synNode.InnerText.Trim().ToLower()).ToList()));
    }

    public IEnumerable<string> GetSynonyms(string word)
    {
        Assert.ArgumentNotNull(word, "word");
        foreach (ReadOnlyCollection<string> readOnlyCollection in _synonymGroups)
        {
            if (readOnlyCollection.Contains(word))
                return readOnlyCollection;
        }
        return null;
    }
}

Sitecore :

<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.PerExecutionContextAnalyzer, Sitecore.ContentSearch.LuceneProvider">
  <param desc="defaultAnalyzer" type="Sitecore.ContentSearch.LuceneProvider.Analyzers.DefaultPerFieldAnalyzer, Sitecore.ContentSearch.LuceneProvider">
    <param desc="defaultAnalyzer" type="Sitecore.ContentSearch.LuceneProvider.Analyzers.SynonymAnalyzer, Sitecore.ContentSearch.LuceneProvider">
      <param hint="engine" type="My.Assembly.Namespace.CustomSynonymEngine, My.Assembly">
      </param>
    </param>
  </param>
</analyzer>

, , CustomSynonymsEngine ( , Sitecore ).

, .

, Sitecore , xml blob, .

+4

Source: https://habr.com/ru/post/1622679/


All Articles