public static IEnumerable <KeyValuePair <string, string> > GetExpandOptions(ExpandParameters parameters, Func <ISolrQuery, string> serializer) { if (parameters == null) { yield break; } yield return(KV.Create("expand", "true")); if (parameters.Rows.HasValue) { yield return(KV.Create("expand.rows", parameters.Rows.Value.ToString())); } if (parameters.Sort != null) { yield return(KV.Create("expand.sort", parameters.Sort.ToString())); } if (serializer == null) { throw new ArgumentNullException("serializer"); } if (parameters.Query != null) { yield return(KV.Create("expand.q", serializer(parameters.Query))); } if (parameters.FilterQuery != null) { yield return(KV.Create("expand.fq", serializer(parameters.FilterQuery))); } }
public void GetCollapseExpandParameters_Expand() { var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer()); var e = new SolrQueryExecuter <TestDocument>(null, null, querySerializer, null, null); var expand = new ExpandParameters( sort: new SortOrder("sortField", Order.ASC), rows: 100, query: new SolrQuery("aquery"), filterQuery: null); var p = e.GetAllParameters(SolrQuery.All, new QueryOptions { Rows = 1, CollapseExpand = new CollapseExpandParameters("somefield", expand, null, null), }).ToList(); Assert.Contains(p, KV.Create("fq", "{!collapse field=somefield}")); Assert.Contains(p, KV.Create("expand.sort", "sortField asc")); Assert.Contains(p, KV.Create("expand.rows", "100")); Assert.Contains(p, KV.Create("expand.q", "aquery")); }
public void GetCollapseExpandParameters_Expand() { var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer()); var e = new SolrQueryExecuter<TestDocument>(null, null, querySerializer, null, null); var expand = new ExpandParameters( sort: new SortOrder("sortField", Order.ASC), rows: 100, query: new SolrQuery("aquery"), filterQuery: null); var p = e.GetAllParameters(SolrQuery.All, new QueryOptions { Rows = 1, CollapseExpand = new CollapseExpandParameters("somefield", expand, null, null), }).ToList(); CollectionAssert.Contains(p, KV.Create("fq", "{!collapse field=somefield}")); CollectionAssert.Contains(p, KV.Create("expand.sort", "sortField asc")); CollectionAssert.Contains(p, KV.Create("expand.rows", "100")); CollectionAssert.Contains(p, KV.Create("expand.q", "aquery")); }