2016-08-23 51 views
0

SolrNet QueryOptions中的結果分組和突出顯示不檢索任何結果。我想我的問題可能是我正在使用的傳統映射。下面 是 核心加入:SolrNet結果分組和突出顯示的傳統映射

windsorSolrStartUp.AddCore(suggestionsIndex.IndexName,typeof(SuggestionsIndexMapper), ConfigurationSettings.ContentSearch_Solr_ServiceBaseAddress + "/" + suggestionsIndex.IndexName); 

SuggestionsIndexMapper.cs

public class SuggestionsIndexMapper: ISuggestionsIndexMapper 
    { 
    public SuggestionsIndexMapper() 
    { 
    } 

    /// <summary> 
    /// Composite ID: contains SuggestionType,SitecoreItemID,Site,Language 
    /// Created on fly during indexing in solr. 
    /// Checkout schema.xml and solrconfig.xml 
    /// </summary> 
    [SolrUniqueKey("compositeId")] 
    public string CompositeId { get; set; } 

    /// <summary> 
    /// SitecoreId 
    /// </summary> 
    [SolrField("sitecoreId")] 
    public string SitecoreId { get; set; } 

    /// <summary> 
    /// DisplayName 
    /// </summary> 
    [SolrField("name")] 
    public string Name { get; set; } 

    /// <summary> 
    /// Imageurl 
    /// </summary> 
    [SolrField("imageUrl")] 
    public string ImageUrl { get; set; } 

    /// <summary> 
    /// Url 
    /// </summary> 
    [SolrField("url")] 
    public string Url { get; set; } 
    } 

SolrSearchContext如下所示:

public class SolrSearchContext<T> : ISolrSearchContext<T> 
{ 
    public readonly ISolrOperations<T> IndexOperations; 

    public SolrSearchContext() {} 

    /// <summary> 
    /// Setting the indexOperations for given index 
    /// </summary> 
    /// <param name="indexName"></param> 
    public SolrSearchContext(string indexName) 
    { 
     IOC ioc = new IOC(); 
     IndexOperations = ioc.GetContainer().Resolve<ISolrOperations<T>>(indexName); 
    } 

    /// <summary> 
    /// Get IndexOperations for index 
    /// </summary> 
    /// <returns></returns> 
    public ISolrOperations<T> GetIndexOperations() 
    { 
     return IndexOperations; 
    } 
public SolrQueryResults<T> ExecuteQuery(ISolrQuery query, QueryOptions queryOptions = null) 
    { 
     try 
     { 
      Logger.Debug(string.Format("SolrSearchContext - ExecuteQuery: Executing your query {0}", query)); 
      if (queryOptions != null) 
      { 
       return IndexOperations.Query(query, queryOptions); 
      } 
      return IndexOperations.Query(query); 
     } 
     catch(Exception e) 
     { 
      Logger.Debug(string.Format("SolrSearchContext - ExecuteQuery: Error while executing the query - {0} is {1}", query, e)); 
      return new SolrQueryResults<T>(); 
     } 
    } 
} 

指數:

public class SuggestionsIndex: SearchIndex<SuggestionsIndexMapper> 
{ 
    public override string IndexName 
    { 
     get { return "suggestions_index"; } 
    } 

    public override string SwapIndexName 
    { 
     get { return "suggestions_index_swap"; } 
    } 
} 

public class SearchIndex<T> : ISearchIndex<T> 
{ 
    public ISolrSearchContext<T> CreateSearchContext() 
    { 
     return new SolrSearchContext<T>(IndexName); 
    } 

    public virtual string IndexName { get; set; } 
    public virtual string SwapIndexName { get; set; } 
} 

因此,對於每個索引,我們都有SolrSearchContext初始化其Mapping類,在這種情況下爲SuggestionsIndexMapper。

現在查詢Solr的,當

ISolrQuery query = QueryBuilder(site, language, term); 
     QueryOptions queryOptions = new QueryOptions() 
     { 
      Highlight = new HighlightingParameters() 
      { 
       Fields = new[] {"uvw"} 
      }, 
      Grouping = new GroupingParameters() 
      { 
       Fields = new[] { "xyz"}, 
       Format = GroupingFormat.Grouped, 
       Limit = 3 
      } 
     }; 
    SuggestionsIndex index = new SuggestionsIndex(); 
    ISolrSearchContext<SuggestionsIndexMapper> searchContext = index.CreateSearchContext(); 
    var results = searchContext.ExecuteQuery(query, queryOptions).ToList(); 

結果來作爲empty.If我不使用結果分組或突出顯示他們得到正確映射到SuggestionsIndexMapper的類型列表的結果變量。

我應該如何映射數據,以便可以訪問Solr結果中的各個組以及高照度結果?

任何幫助將是偉大的。 謝謝,

+0

我是通過不執行.toList()從executeQuery得到結果來訪問Result Groupings和Highlight。這給出了solr的全部結果。隨着分組和亮點。並可以作爲結果訪問。分組和結果。重點 –

回答

0

我能夠通過不執行.toList()從executeQuery的結果訪問結果分組和亮點。 而不是: var results = searchContext.ExecuteQuery(query,queryOptions).ToList(); 基本上只是做: var results = searchContext.ExecuteQuery(query,queryOptions); Var highlights = results.higlights; var grouping = results.grouping;

這給出了solr的全部結果。隨着分組和亮點。