簡體   English   中英

使用SolrNet啟動多個Solr詞典索引

[英]Initiating Multiple Solr Dictionary Indexes Using SolrNet

我目前正在使用Solrnet進行搜索。 我的索引很大,因為我們是一家跨國公司,所以它們會被翻譯。 我最初的想法是在一個索引中包含所有記錄的所有翻譯,但是由於一個索引的索引變大了,所以這最終成為一個問題,因此我們按語言划分了索引。 例如,我創建了一個名為SearchEnglish的英語索引和一個名為SearchFrench的法語索引。

要啟動Solrnet,我使用類似以下內容的方法:

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

我使用字典是因為我的Solr索引包含動態構面。 問題是我的代碼庫將需要啟動所有索引。 因此,我無法將一個索引與另一個索引區分開。 您對使用Solrnet處理多個字典Solr索引的啟動有何建議? 我在文檔中沒有看到任何有關此的內容。

謝謝保羅

我已經想出了如何通過使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM