2014-02-05 51 views

回答

2

只是爲了節省您在前往論壇的努力:

var serializer = ServiceLocator.Current.GetInstance<ISolrQuerySerializer>(); 
queries = new List<ISolrQuery> 
{ 
new SolrQueryByField("category_facet", "Fjärrin"), 
new SolrQueryByField("branch_facet", sigel), 
new SolrQueryByField("isArchived", "false"), 
SolrQuery.All 
}; 
var q = new SolrMultipleCriteriaQuery(queries,"AND"); 
var queryRaw = serializer.Serialize(q); 
Debug.WriteLine(queryRaw); 
+1

僅供參考:這不會顯示使用SolrQueryInList創建的任何參數 - 它只獲取SolryQueryByField參數。 – LandonC

1

寫兩件事(只查詢,或所有參數)到LinqPad腳本,方便,完整的參考:

void Main() 
{ 
    //Reset from scratch since doesn't play great with linqpad 
    Startup.InitContainer(); 
    //Setup the container contents 
    Startup.Init<FakeModel>("http://localhost:8983/solr"); 


    var queries = new List<ISolrQuery> 
     { 
     new SolrQueryByField("category_facet", "Fjärrin"), 
     new SolrQueryByField("branch_facet", "sigel"), 
     new SolrQueryByField("isArchived", "false"), 
     SolrQuery.All 
     }; 
    var q = new SolrMultipleCriteriaQuery(queries, "AND"); 


    var opts = new QueryOptions 
    { 
     Start = 20, 
     Rows = 15, 
     OrderBy = new[] { new SolrNet.SortOrder("myFakeField") } 
    }; 


    DumpQuery(q); 
    DumpAllParameters(q, opts); 
} 

private void DumpQuery(ISolrQuery q) 
{ 
    var serializer = ServiceLocator.Current.GetInstance<ISolrQuerySerializer>(); 

    var queryRaw = serializer.Serialize(q); 
    //Dump is a LinqpadMethod, running elsewhere this needs to be modified 
    queryRaw.Dump("Query only"); 
} 
private void DumpAllParameters(ISolrQuery q, QueryOptions opts) 
{ 
    var queryExecuterInterface = ServiceLocator.Current.GetInstance<ISolrQueryExecuter<FakeModel>>(); 
    var queryExecuter = queryExecuterInterface as SolrQueryExecuter<FakeModel>; 
    queryExecuter.GetAllParameters(q, opts).Dump("All Parameters"); 
} 


public class FakeModel 
{ 
} 
相關問題