public void FacetFieldOptions()
 {
     var querySerializer = new SolrQuerySerializerStub("q");
     var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, null);
     var queryExecuter = new SolrQueryExecuter<TestDocument>(null, null, querySerializer, facetQuerySerializer, null);
     var facetOptions = queryExecuter.GetFacetFieldOptions(
         new FacetParameters {
             Queries = new List<ISolrFacetQuery> {
                 new SolrFacetQuery(new SolrQuery("q")),
             },
             Prefix = "pref",
             EnumCacheMinDf = 123,
             Limit = 100,
             MinCount = 5,
             Missing = true,
             Offset = 55,
             Sort = true,
         }).ToDictionary(x => x.Key, x => x.Value);
     Assert.AreEqual("pref", facetOptions["facet.prefix"]);
     Assert.AreEqual("123", facetOptions["facet.enum.cache.minDf"]);
     Assert.AreEqual("100", facetOptions["facet.limit"]);
     Assert.AreEqual("5", facetOptions["facet.mincount"]);
     Assert.AreEqual("true", facetOptions["facet.missing"]);
     Assert.AreEqual("55", facetOptions["facet.offset"]);
     Assert.AreEqual("true", facetOptions["facet.sort"]);
 }
Beispiel #2
0
 public void FacetQuery()
 {
     var mocks = new MockRepository();
     var query = new Dictionary<string, string>();
     query["q"] = "";
     query["rows"] = SolrQueryExecuter<TestDocumentWithUniqueKey>.ConstDefaultRows.ToString();
     query["facet"] = "true";
     query["facet.query"] = "id:1";
     var connection = new MockConnection(query);
     var parser = mocks.StrictMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
     var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
     With.Mocks(mocks).Expecting(() => {
         Expect.On(parser)
             .Call(parser.Parse(null))
             .IgnoreArguments()
             .Return(new SolrQueryResults<TestDocumentWithUniqueKey>());
     }).Verify(() => {
         var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(parser, connection, querySerializer, facetQuerySerializer);
         var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
         var r = solr.Query(new SolrQuery(""), new QueryOptions {
             Facet = new FacetParameters {
                 Queries = new ISolrFacetQuery[] {
                     new SolrFacetQuery(new SolrQuery("id:1")),
                 },
             }
         });
     });
 }
Beispiel #3
0
 public void FacetFieldQuery()
 {
     var mocks = new MockRepository();
     var query = new Dictionary<string, string>();
     query["q"] = "*:*";
     query["facet"] = "true";
     query["facet.field"] = "cat";
     query["rows"] = "0";
     var connection = new MockConnection(query);
     var resultParser = mocks.StrictMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     With.Mocks(mocks).Expecting(() => {
         Expect.On(resultParser)
             .Call(resultParser.Parse(""))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(new SolrQueryResults<TestDocumentWithUniqueKey> {
                 FacetFields = new Dictionary<string, ICollection<KeyValuePair<string, int>>> {
                     {
                         "cat", new List<KeyValuePair<string, int>> {
                             new KeyValuePair<string, int>("electronics", 5),
                             new KeyValuePair<string, int>("hard drive", 3),
                         }
                         }
                 }
             });
     }).Verify(() => {
         var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
         var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
         var queryExecuter = new SolrQueryExecuter<TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, facetQuerySerializer);
         var basicSolr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, queryExecuter, docSerializer, null, null, null, null, null);
         var solr = new SolrServer<TestDocumentWithUniqueKey>(basicSolr, mapper, validationManager);
         var r = solr.FacetFieldQuery(new SolrFacetFieldQuery("cat"));
         Assert.AreEqual(2, r.Count);
         Assert.AreEqual("electronics", r.First().Key);
     });
 }
 private static IList<KeyValuePair<string, string>> Serialize(object o)
 {
     var fieldSerializer = new DefaultFieldSerializer();
     var serializer = new DefaultFacetQuerySerializer(new DefaultQuerySerializer(fieldSerializer), fieldSerializer);
     return serializer.Serialize(o).ToList();
 }
        public void MultipleFacetFields()
        {
            var conn = new MockConnection(new[] {
                KV.Create("q", ""),
                KV.Create("rows", SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString()),
                KV.Create("facet", "true"),
                KV.Create("facet.field", "Id"),
                KV.Create("facet.field", "OtherField"),
            });
            var serializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var facetQuerySerializer = new DefaultFacetQuerySerializer(serializer, new DefaultFieldSerializer());

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, facetQuerySerializer, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Facet = new FacetParameters {
                    Queries = new ISolrFacetQuery[] {
                        new SolrFacetFieldQuery("Id"),
                        new SolrFacetFieldQuery("OtherField"),
                    }
                }
            });
        }
        public void Facets()
        {
            var q = new Dictionary<string, string>();
            q["q"] = "";
            q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
            q["facet"] = "true";
            q["facet.field"] = "Id";
            q["facet.query"] = "id:[1 TO 5]";
            var conn = new MockConnection(q);
            var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, facetQuerySerializer, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Facet = new FacetParameters {
                    Queries = new ISolrFacetQuery[] {
                        new SolrFacetFieldQuery("Id"),
                        new SolrFacetQuery(new SolrQuery("id:[1 TO 5]")),
                    }
                }
            });
        }
Beispiel #7
0
        public void FacetQuery()
        {
            var connection = new MSolrConnection();
            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary<string, string> {
                    {"q", ""},
                    {"rows", SolrQueryExecuter<TestDocumentWithUniqueKey>.ConstDefaultRows.ToString()},
                    {"facet", "true"},
                    {"facet.query", "id:1"},
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };

            var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
            var parser = new MSolrAbstractResponseParser<TestDocumentWithUniqueKey>();
            parser.parse &= x => x.Stub();
            var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(parser, connection, querySerializer, facetQuerySerializer, null);
            var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r = solr.Query(new SolrQuery(""), new QueryOptions {
                Facet = new FacetParameters {
                    Queries = new ISolrFacetQuery[] {
                        new SolrFacetQuery(new SolrQuery("id:1")),
                    },
                }
            });

            Assert.AreEqual(1, connection.get.Calls);
        }