Esempio n. 1
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" },
                };
                CollectionAssert.AreEquivalent(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);
        }
Esempio n. 2
0
        public void QueryWithPagination()
        {
            const string qstring    = "id:123";
            const int    start      = 10;
            const int    rows       = 20;
            var          connection = new MSolrConnection();

            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", qstring },
                    { "start", start.ToString() },
                    { "rows", rows.ToString() },
                };
                CollectionAssert.AreEquivalent(expectedParams, param);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            };

            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => qstring;

            var resultParser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            resultParser.parse &= x => x.Stub();

            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, null, null);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.Query(new SolrQuery(qstring), new QueryOptions {
                Start = start, Rows = rows
            });

            Assert.AreEqual(1, connection.get.Calls);
        }
Esempio n. 3
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")),
                        },
                    }
                });
            });
        }
Esempio n. 4
0
 public void FilterQueries()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"fq", "id:0"},
         {"q", "*:*"},
         {"rows", "100000000"},
     });
     var mocks = new MockRepository();
     var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
     ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);
     solr.Query(SolrQuery.All, new QueryOptions {
         FilterQueries = new[] {new SolrQuery("id:0")},
     });
 }
Esempio n. 5
0
        public void FilterQueries()
        {
            var conn = new MockConnection(new Dictionary <string, string> {
                { "fq", "id:0" },
                { "q", "*:*" },
                { "rows", "100000000" },
            });
            var mocks         = new MockRepository();
            var queryExec     = mocks.StrictMock <ISolrQueryExecuter <Document> >();
            var docSerializer = mocks.StrictMock <ISolrDocumentSerializer <Document> >();
            ISolrBasicReadOnlyOperations <Document> solr = new SolrBasicServer <Document>(conn, queryExec, docSerializer, null, null, null, null, null);

            solr.Query(SolrQuery.All, new QueryOptions {
                FilterQueries = new[] { new SolrQuery("id:0") },
            });
        }
Esempio n. 6
0
        public void QueryWithSortAndPagination()
        {
            const string qstring = "id:123";
            const int    start   = 10;
            const int    rows    = 20;

            var connection = new MSolrConnection();

            connection.get += new MFunc <string, IEnumerable <KeyValuePair <string, string> >, string>((url, param) => {
                Assert.Equal("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", qstring },
                    { "start", start.ToString() },
                    { "rows", rows.ToString() },
                    { "sort", "id asc,name desc" },
                };
                Assert.Equal(expectedParams, param); //should ignore order
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            });

            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => qstring;

            var resultParser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            resultParser.parse &= x => x.Stub();

            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, null, null);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.Query(new SolrQuery(qstring), new QueryOptions {
                Start   = start,
                Rows    = rows,
                OrderBy = new[] {
                    new SortOrder("id", Order.ASC),
                    new SortOrder("name", Order.DESC)
                }
            });

            Assert.Equal(1, connection.get.Calls);
        }
Esempio n. 7
0
        public void FacetField()
        {
            var connection = new MSolrConnection();

            connection.get += new MFunc <string, IEnumerable <KeyValuePair <string, string> >, string>((url, param) => {
                Assert.Equal("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", "*:*" },
                    { "rows", SolrQueryExecuter <TestDocumentWithUniqueKey> .ConstDefaultRows.ToString() },
                    { "facet", "true" },
                    { "facet.field", "id" },
                    { "f.id.facet.limit", "3" },
                };
                Assert.Equal(expectedParams, param); //should ignore order
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            });

            var parser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            parser.parse &= x => x.Stub();
            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => "*:*";
            var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());

            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 SolrFacetFieldQuery("id")
                        {
                            Limit = 3
                        },
                    },
                }
            });

            Assert.Equal(1, connection.get.Calls);
        }
Esempio n. 8
0
        public void QueryWithSortAndPagination()
        {
            const string qstring = "id:123";
            const int    start   = 10;
            const int    rows    = 20;

            var mocks = new MockRepository();
            var query = new Dictionary <string, string>();

            query["q"]     = qstring;
            query["start"] = start.ToString();
            query["rows"]  = rows.ToString();
            query["sort"]  = "id asc,name desc";
            var connection      = new MockConnection(query);
            var parser          = mocks.StrictMock <ISolrQueryResultParser <TestDocumentWithUniqueKey> >();
            var docSerializer   = mocks.StrictMock <ISolrDocumentSerializer <TestDocumentWithUniqueKey> >();
            var querySerializer = mocks.StrictMock <ISolrQuerySerializer>();

            With.Mocks(mocks).Expecting(() => {
                Expect.On(querySerializer)
                .Call(querySerializer.Serialize(null))
                .IgnoreArguments()
                .Return(qstring);
                Expect.On(parser)
                .Call(parser.Parse(null))
                .IgnoreArguments()
                .Return(new SolrQueryResults <TestDocumentWithUniqueKey>());
            }).Verify(() => {
                var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(parser, connection, querySerializer, null);
                var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
                var r        = solr.Query(new SolrQuery(qstring), new QueryOptions {
                    Start   = start,
                    Rows    = rows,
                    OrderBy = new[] {
                        new SortOrder("id", Order.ASC),
                        new SortOrder("name", Order.DESC)
                    }
                });
            });
        }
Esempio n. 9
0
        public void QueryWithSort()
        {
            const string qstring = "id:123";

            var connection = new MSolrConnection();

            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", qstring },
                    { "rows", SolrQueryExecuter <TestDocumentWithUniqueKey> .ConstDefaultRows.ToString() },
                    { "sort", "id asc,name desc" },
                };
                CollectionAssert.AreEquivalent(expectedParams, param);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            };

            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => qstring;

            var resultParser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            resultParser.parse &= x => x.Stub();

            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, null, null);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.Query(new SolrQuery(qstring),
                                      new QueryOptions {
                OrderBy = new[] {
                    new SortOrder("id", Order.ASC),
                    new SortOrder("name", Order.DESC)
                }
            });

            Assert.AreEqual(1, connection.get.Calls);
        }
Esempio n. 10
0
        public void QueryWithSortAndPagination()
        {
            const string qstring = "id:123";
            const int start = 10;
            const int rows = 20;

            var mocks = new MockRepository();
            var query = new Dictionary<string, string>();
            query["q"] = qstring;
            query["start"] = start.ToString();
            query["rows"] = rows.ToString();
            query["sort"] = "id asc,name desc";
            var connection = new MockConnection(query);
            var parser = mocks.StrictMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
            var querySerializer = mocks.StrictMock<ISolrQuerySerializer>();
            With.Mocks(mocks).Expecting(() => {
                Expect.On(querySerializer)
                    .Call(querySerializer.Serialize(null))
                    .IgnoreArguments()
                    .Return(qstring);
                Expect.On(parser)
                    .Call(parser.Parse(null))
                    .IgnoreArguments()
                    .Return(new SolrQueryResults<TestDocumentWithUniqueKey>());
            }).Verify(() => {
                var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(parser, connection, querySerializer, null);
                var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
                var r = solr.Query(new SolrQuery(qstring), new QueryOptions {
                    Start = start,
                    Rows = rows,
                    OrderBy = new[] {
                        new SortOrder("id", Order.ASC),
                        new SortOrder("name", Order.DESC)
                    }
                });
            });
        }
Esempio n. 11
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")),
                 },
             }
         });
     });
 }
Esempio n. 12
0
        public void QueryWithPagination()
        {
            const string qstring = "id:123";
            const int start = 10;
            const int rows = 20;

            var mocks = new MockRepository();
            //var connection = mocks.CreateMock<ISolrConnection>();
            var query = new Dictionary<string, string>();
            query["q"] = qstring;
            query["start"] = start.ToString();
            query["rows"] = rows.ToString();
            var connection = new MockConnection(query);
            var parser = mocks.CreateMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
            var docSerializer = mocks.CreateMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
            With.Mocks(mocks).Expecting(() => {
                Expect.On(parser).Call(parser.Parse(null))
                    .IgnoreArguments()
                    .Return(new SolrQueryResults<TestDocumentWithUniqueKey>());
            }).Verify(() => {
                var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(connection, parser);
                var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer);
                var r = solr.Query(new SolrQuery(qstring), new QueryOptions {Start = start, Rows = rows});
            });
        }
Esempio n. 13
0
        public void QueryWithSortAndPagination()
        {
            const string qstring = "id:123";
            const int start = 10;
            const int rows = 20;

            var connection = new MSolrConnection();
            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary<string, string> {
                    {"q", qstring},
                    {"start", start.ToString()},
                    {"rows", rows.ToString()},
                    {"sort", "id asc,name desc"},
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };

            var querySerializer = new MSolrQuerySerializer();
            querySerializer.serialize += _ => qstring;

            var resultParser = new MSolrAbstractResponseParser<TestDocumentWithUniqueKey>();
            resultParser.parse &= x => x.Stub();

            var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, null, null);
            var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r = solr.Query(new SolrQuery(qstring), new QueryOptions {
                Start = start,
                Rows = rows,
                OrderBy = new[] {
                    new SortOrder("id", Order.ASC),
                    new SortOrder("name", Order.DESC)
                }
            });

            Assert.AreEqual(1, connection.get.Calls);
        }
Esempio n. 14
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);
        }