Exemple #1
0
        public void QueryAll_with_pagination() {

            var querySerializer = new MSolrQuerySerializer();
            querySerializer.serialize += _ => "id:123456";

            var serviceLocator = new MServiceLocator();
            serviceLocator.getService = MServiceLocator.Table(new Dictionary<System.Type, object> {
                {typeof (ISolrReadOnlyOperations<Entity>), mockSolr},
                {typeof (ISolrQuerySerializer), querySerializer},
            });

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            mockSolr.queryStringOptions += (s, o) => {
                Assert.AreEqual("id:123456", s);
                Assert.AreEqual(5, o.Rows);
                Assert.AreEqual(3, o.Start);
                Assert.AreEqual(1, o.OrderBy.Count);
                Assert.AreEqual("pepe asc", o.OrderBy.First().ToString());
                return new SolrQueryResults<Entity>();
            };
            mockSolr.queryStringOptions &= x => x.Expect(1);

            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery(new SolrQueryByField("id", "123456"))
                    .SetMaxResults(5)
                    .SetFirstResult(3)
                    .SetSort(Order.Asc("pepe"))
                    .List<Entity>();
            }
        }
        public void Execute() {
            const string queryString = "id:123456";
            var q = new Dictionary<string, string>();
            q["q"] = queryString;
            var conn = new MockConnection(q);
            var serializer = new MSolrQuerySerializer();
            serializer.serialize += _ => queryString;
            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();

            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
            var r = queryExecuter.Execute(new SolrQuery(queryString), null);
            Assert.AreEqual(1, serializer.serialize.Calls);
        }
Exemple #3
0
		public void DeleteByQuery() {
            const string queryString = "someQuery";
		    var q = new SolrQuery(queryString);
            var xml = string.Format("<delete><query>{0}</query></delete>", queryString);

		    var conn = new Mocks.MSolrConnection();
		    conn.post = conn.post.Args("/update", xml);

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

            var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(null, q, querySerializer), null);
            cmd.Execute(conn);

            Assert.AreEqual(1, conn.post.Calls);
		}
        public void DeleteByIdAndQuery()
        {
            var ids = new[] { "123", "456" };
            const string queryString = "someQuery";
            var xml = string.Format("<delete><id>{0}</id><id>{1}</id><query>{2}</query></delete>", ids[0], ids[1], queryString);
            var conn = new Mocks.MSolrConnection();
            conn.post = conn.post.Args("/update", xml);

            var q = new SolrQuery(queryString);
            var querySerializer = new Mocks.MSolrQuerySerializer();
            querySerializer.serialize += _ => queryString;

            var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(ids, q, querySerializer));
            cmd.Execute(conn);

            Assert.AreEqual(1, conn.post.Calls);
        }
Exemple #5
0
        public void DeleteByIdAndQuery()
        {
            var          ids         = new[] { "123", "456" };
            const string queryString = "someQuery";
            var          xml         = string.Format("<delete><id>{0}</id><id>{1}</id><query>{2}</query></delete>", ids[0], ids[1], queryString);
            var          conn        = new Mocks.MSolrConnection();

            conn.post = conn.post.Args("/update", xml);

            var q = new SolrQuery(queryString);
            var querySerializer = new Mocks.MSolrQuerySerializer();

            querySerializer.serialize += _ => queryString;

            var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(ids, q, querySerializer), null);

            cmd.Execute(conn);

            Assert.AreEqual(1, conn.post.Calls);
        }
Exemple #6
0
        public void DeleteByQuery()
        {
            const string queryString = "someQuery";
            var          q           = new SolrQuery(queryString);
            var          xml         = string.Format("<delete><query>{0}</query></delete>", queryString);

            var conn = new Mocks.MSolrConnection();

            conn.post = conn.post.Args("/update", xml);

            var querySerializer = new Mocks.MSolrQuerySerializer();

            querySerializer.serialize += _ => queryString;

            var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(null, q, querySerializer));

            cmd.Execute(conn);

            Assert.AreEqual(1, conn.post.Calls);
        }
        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);
        }
        public void MoreLikeThisHandlerQuery()
        {
            const string qstring = "id:123";

            var connection = new MSolrConnection();
            connection.get += (url, param) => {
                Assert.AreEqual("/mlt", url);
                var expectedParams = new Dictionary<string, string> {
                    {"q", qstring},
                    {"rows", SolrQueryExecuter<TestDocumentWithUniqueKey>.ConstDefaultRows.ToString() },
                    {"mlt", "true"},
                    {"mlt.fl", "id"},
                    {"mlt.match.include", "true"},
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml");
            };

            var querySerializer = new MSolrQuerySerializer();
            querySerializer.serialize &= x => x.Return(qstring);

            var mlthParser = new MSolrMoreLikeThisHandlerQueryResultsParser<TestDocumentWithUniqueKey>();
            mlthParser.parse += _ => new SolrMoreLikeThisHandlerResults<TestDocumentWithUniqueKey>();

            var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(null, connection, querySerializer, null, mlthParser);
            var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r = solr.MoreLikeThis(new SolrMoreLikeThisHandlerQuery(new SolrQuery(qstring)), new MoreLikeThisHandlerQueryOptions(new MoreLikeThisHandlerParameters(new[] { "id" }) { MatchInclude = true }));
            Assert.AreEqual(1, connection.get.Calls);
        }
        public void FacetField()
        {
            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.field", "id"},
                    {"f.id.facet.limit", "3"},
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                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.AreEqual(1, connection.get.Calls);
        }
 public void DeleteByQuery()
 {
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<delete><query>id:123</query></delete>", content);
         return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     };
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse += _ => null;
     var querySerializer = new MSolrQuerySerializer();
     querySerializer.serialize += _ => "id:123";
     var ops = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, querySerializer, null, null);
     ops.Delete(null, new SolrQuery("id:123"));
     Assert.AreEqual(1, connection.post.Calls);
 }