简体   繁体   English

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

[英]Initiating Multiple Solr Dictionary Indexes Using SolrNet

I'm currently in the process of implementing a search using Solrnet. 我目前正在使用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. 例如,我创建了一个名为SearchEnglish的英语索引和一个名为SearchFrench的法语索引。

To initiate Solrnet, I use something like: 要启动Solrnet,我使用类似以下内容的方法:

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

I use dictionaries because my Solr indexes contain dynamic facets. 我使用字典是因为我的Solr索引包含动态构面。 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? 您对使用Solrnet处理多个字典Solr索引的启动有何建议? I don't see anything in the documentation regarding this. 我在文档中没有看到任何有关此的内容。

Thanks, Paul 谢谢保罗

I've figured out how to do this by using SolrNet/Windsor to initialize my Solr instance. 我已经想出了如何通过使用SolrNet / Windsor初始化我的Solr实例来做到这一点。 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 在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);
    }

I also created an extension static class to hold the WindsorContainer object. 我还创建了一个扩展静态类来保存WindsorContainer对象。

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 然后在我的应用程序中,我只是调用该静态对象来获取我的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("*:*");

If you have any questions about this, you can read about solrnet and Windsor initialization at the links below. 如果对此有任何疑问,可以在下面的链接中阅读有关solrnet和Windsor初始化的信息。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM