Exemple #1
0
        public void ExecuteMLT_with_stream_body_query()
        {
            var parser = new MSolrMoreLikeThisHandlerQueryResultsParser <SolrQueryExecuterTests.TestDocument>();
            var q      = new Dictionary <string, string>();

            q["mlt"]                  = "true";
            q["mlt.fl"]               = "one,three";
            q["mlt.match.include"]    = "false";
            q["mlt.match.offset"]     = "5";
            q["mlt.interestingTerms"] = InterestingTerms.None.ToString().ToLowerInvariant();
            q["start"]                = "0";
            q["rows"]                 = "5";
            q["fl"] = "one,two,three";
            var conn = new MockConnection(q, MediaTypeNames.Text.Plain, "one two three");

            var qe = new SolrQueryExecuter <SolrQueryExecuterTests.TestDocument>(null, conn, null, null, parser);
            var r  = qe.ExecuteAsync(new SolrMoreLikeThisHandlerStreamBodyQuery("one two three"),
                                     new MoreLikeThisHandlerQueryOptions(
                                         new MoreLikeThisHandlerParameters(new[] { "one", "three" })
            {
                MatchInclude = false,
                MatchOffset  = 5,
                ShowTerms    = InterestingTerms.None,
            })
            {
                Start  = 0,
                Rows   = 5,
                Fields = new[] { "one", "two", "three" },
            });
        }
Exemple #2
0
        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" },
                };
                CollectionAssert.AreEquivalent(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 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);
        }