使用SolrNet启动多个Solr词典索引

Initiating Multiple Solr Dictionary Indexes Using SolrNet
2020-10-25
  •  译文(汉语)
  •  原文(英语)

我目前正在使用Solrnet进行搜索.我的索引很大,因为我们是一家跨国公司,所以它们会被翻译.我最初的想法是在一个索引中包含所有记录的所有翻译,但是这最终成为一个问题,因为对于一个索引而言索引变大了,因此我们按语言将索引拆分.例如,我创建了一个名为SearchEnglish的英语索引和一个名为SearchFrench的法语索引.

要启动Solrnet,我使用类似以下内容的方法:

Startup.Init<Dictionary<string, object>>(SearchIndexUrl);

我使用字典是因为我的Solr索引包含动态构面.问题是我的代码库将需要启动所有索引.因此,我无法将一个索引与另一个索引区分开.您对使用Solrnet处理多个字典Solr索引的启动有何建议?我在文档中没有看到任何有关此的内容.

谢谢保罗

解决过程1

我已经想出了如何通过使用SolrNet / Windsor初始化我的Solr实例来做到这一点.我没有找到有关如何执行此操作的大量文档,所以我想分享一下.

这是我的一些代码.

在Global.asax.cs中,我有以下内容

    public static WindsorContainer _WindsorContainer { get; set; }

    protected void Application_Start()
    {
        InitiateSolr();
    }

    protected void Application_End()
    {
        _WindsorContainer.Dispose();
    }

    /// <summary>
    /// Initialized Misc Solr Indexes
    /// </summary>
    protected void InitiateSolr() {
        var reader = ApplicationConfig.GetResourceReader("~/Settings/AppSettings.resx");
        InitiateSolrFacetedIndex(reader);
    }

    /// <summary>
    /// Initializes The Faceted Search Indexes
    /// </summary>
    protected void InitiateSolrFacetedIndex(ResourceReader reader) {
        Data d = new Data();
        _WindsorContainer = new WindsorContainer();

        var solrFacility = new SolrNetFacility(reader.ResourceCollection["Url.SolrIndexPath"] + "EN");

        foreach (var item in d.GetLanguages())
        {
            solrFacility.AddCore("ProductSpecIndex" + item.LanguageCode.ToString(), typeof(Dictionary<string, object>), reader.ResourceCollection["Url.SolrIndexPath"] + item.LanguageCode.ToString());
        }

        _WindsorContainer.AddFacility("solr", solrFacility);

        Models.Solr.SolrWindsorContainer c = new Models.Solr.SolrWindsorContainer();
        c.SetContainer(_WindsorContainer);
    }

我还创建了一个扩展静态类来保存WindsorContainer对象.

public class SolrWindsorContainer
{
    public static WindsorContainer Container { get; set; }

    public void SetContainer(WindsorContainer container){
        Container = container;
    }
    public WindsorContainer GetContainer(){
        return Container;
    }
}

然后在我的应用程序中,我只是调用该静态对象来获取我的Windsor容器

Models.Solr.SolrWindsorContainer c = new Models.Solr.SolrWindsorContainer();
ISolrOperations<Dictionary<string, object>> solr = container.Resolve<ISolrOperations<Dictionary<string, object>>>("ProductSpecIndex" + languageCode);

var results = solr.Query("*:*");

如果对此有任何疑问,可以在下面的链接中阅读有关solrnet和Windsor初始化的信息.

https://github.com/mausch/SolrNet/blob/master/Documentation/Initialization.md

https://github.com/mausch/SolrNet/blob/master/Documentation/Multi-core-instance.md

I'm currently in the process of implementing a search using Solrnet. My indexes are very large, and because we're a global company they are translated. My initial thought was to have multiple records with all translations in one index, however this ended up being an issue because the indexes became to large for one index, so we split up the indexes by language. For instance I created an English index called SearchEnglish and a French index called SearchFrench.

To initiate Solrnet, I use something like:

Startup.Init<Dictionary<string, object>>(SearchIndexUrl);

I use dictionaries because my Solr indexes contain dynamic facets. The issue is that my code base is going to need to initiate all indexes. So I have no way of distinguishing one index from another. What would be your recommendation to handling the initiation of multiple dictionary Solr indexes using Solrnet? I don't see anything in the documentation regarding this.

Thanks, Paul

Solutions1

I've figured out how to do this by using SolrNet/Windsor to initialize my Solr instance. I didn't find a ton of documentation on how to do this, so I wanted to share.

Here's some of my code.

In the Global.asax.cs I have the following

    public static WindsorContainer _WindsorContainer { get; set; }

    protected void Application_Start()
    {
        InitiateSolr();
    }

    protected void Application_End()
    {
        _WindsorContainer.Dispose();
    }

    /// <summary>
    /// Initialized Misc Solr Indexes
    /// </summary>
    protected void InitiateSolr() {
        var reader = ApplicationConfig.GetResourceReader("~/Settings/AppSettings.resx");
        InitiateSolrFacetedIndex(reader);
    }

    /// <summary>
    /// Initializes The Faceted Search Indexes
    /// </summary>
    protected void InitiateSolrFacetedIndex(ResourceReader reader) {
        Data d = new Data();
        _WindsorContainer = new WindsorContainer();

        var solrFacility = new SolrNetFacility(reader.ResourceCollection["Url.SolrIndexPath"] + "EN");

        foreach (var item in d.GetLanguages())
        {
            solrFacility.AddCore("ProductSpecIndex" + item.LanguageCode.ToString(), typeof(Dictionary<string, object>), reader.ResourceCollection["Url.SolrIndexPath"] + item.LanguageCode.ToString());
        }

        _WindsorContainer.AddFacility("solr", solrFacility);

        Models.Solr.SolrWindsorContainer c = new Models.Solr.SolrWindsorContainer();
        c.SetContainer(_WindsorContainer);
    }

I also created an extension static class to hold the WindsorContainer object.

public class SolrWindsorContainer
{
    public static WindsorContainer Container { get; set; }

    public void SetContainer(WindsorContainer container){
        Container = container;
    }
    public WindsorContainer GetContainer(){
        return Container;
    }
}

Then in my application, I just call that static object to get my Windsor container

Models.Solr.SolrWindsorContainer c = new Models.Solr.SolrWindsorContainer();
ISolrOperations<Dictionary<string, object>> solr = container.Resolve<ISolrOperations<Dictionary<string, object>>>("ProductSpecIndex" + languageCode);

var results = solr.Query("*:*");

If you have any questions about this, you can read about solrnet and Windsor initialization at the links below.

https://github.com/mausch/SolrNet/blob/master/Documentation/Initialization.md

https://github.com/mausch/SolrNet/blob/master/Documentation/Multi-core-instance.md

转载于:https://stackoverflow.com/questions/30399943/initiating-multiple-solr-dictionary-indexes-using-solrnet

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入