Exemplo n.º 1
0
 public void Execute()
 {
     const string queryString = "id:123456";
     var q = new Dictionary<string, string>();
     q["q"] = queryString;
     var conn = new MockConnection(q);
     var mocks = new MockRepository();
     var parser = mocks.StrictMock<ISolrQueryResultParser<TestDocument>>();
     var mockR = mocks.DynamicMock<SolrQueryResults<TestDocument>>();
     var serializer = mocks.StrictMock<ISolrQuerySerializer>();
     With.Mocks(mocks).Expecting(() => {
         Expect.On(parser)
             .Call(parser.Parse(null))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(mockR);
         Expect.On(serializer)
             .Call(serializer.Serialize(null))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(queryString);
     }).Verify(() => {
         var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
         var r = queryExecuter.Execute(new SolrQuery(queryString), null);
     });
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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")},
     });
 }
Exemplo n.º 4
0
 public void Sort() {
     const string queryString = "id:123456";
     var q = new Dictionary<string, string>();
     q["q"] = queryString;
     q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
     q["sort"] = "id asc";
     var conn = new MockConnection(q);
     var querySerializer = new SolrQuerySerializerStub(queryString);
     var parser = new MSolrAbstractResponseParser<TestDocument>();
     parser.parse &= x => x.Expect(1);
     var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
     var r = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
         OrderBy = new[] { new SortOrder("id") }
     });
     parser.parse.Verify();
 }
Exemplo 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") },
            });
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void ExecuteAsyncWithBodyContent()
        {
            const string queryJson = "{ \"query\": \"id:123456\" }";
            var          q         = new Dictionary <string, string>();

            q["rows"] = SolrQueryExecuter <SolrQueryExecuterTests.TestDocument> .ConstDefaultRows.ToString();

            var conn       = new MockConnection(q, SimpleJsonQueryBody.ApplicationJson, queryJson);
            var serializer = new MSolrQuerySerializer();

            serializer.serialize += _ => string.Empty;
            var parser = new MSolrAbstractResponseParser <SolrQueryExecuterTests.TestDocument>();

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

            var queryExecuter = new SolrQueryExecuter <SolrQueryExecuterTests.TestDocument>(parser, conn, serializer, null, null);
            var r             = queryExecuter.ExecuteAsync(new SolrQuery(null), new SimpleJsonQueryBody(queryJson), new QueryOptions());

            Assert.Equal(1, serializer.serialize.Calls);
        }
Exemplo n.º 8
0
        public void ResultFields()
        {
            const string queryString = "id:123456";
            var          q           = new Dictionary <string, string>();

            q["q"]    = queryString;
            q["rows"] = SolrQueryExecuter <TestDocument> .ConstDefaultRows.ToString();

            q["fl"] = "id,name";
            var conn            = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub(queryString);

            var parser = new MSolrAbstractResponseParser <TestDocument>();

            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter <TestDocument>(parser, conn, querySerializer, null, null);
            var r             = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
                Fields = new[] { "id", "name" },
            });
        }
Exemplo n.º 9
0
        public void FacetField()
        {
            var mocks = new MockRepository();
            var query = new Dictionary <string, string>();

            query["q"]    = "";
            query["rows"] = SolrQueryExecuter <TestDocumentWithUniqueKey> .ConstDefaultRows.ToString();

            query["facet"]            = "true";
            query["facet.field"]      = "id";
            query["f.id.facet.limit"] = "3";
            var connection           = new MockConnection(query);
            var parser               = mocks.StrictMock <ISolrQueryResultParser <TestDocumentWithUniqueKey> >();
            var docSerializer        = mocks.StrictMock <ISolrDocumentSerializer <TestDocumentWithUniqueKey> >();
            var querySerializer      = mocks.DynamicMock <ISolrQuerySerializer>();
            var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());

            With.Mocks(mocks).Expecting(() => {
                Expect.On(querySerializer)
                .Call(querySerializer.Serialize(null))
                .IgnoreArguments()
                .Return("");
                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 SolrFacetFieldQuery("id")
                            {
                                Limit = 3
                            },
                        },
                    }
                });
            });
        }
Exemplo n.º 10
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);
            });
        }
Exemplo n.º 11
0
        public void Boosting()
        {
            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);

            var linqQuery = from doc in solr.AsQueryable()
                            where (doc.Name == "john").Boost(10)
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(name:john)^10", resDocs.Query);
        }
Exemplo n.º 12
0
        public void AndsOrs()
        {
            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);

            var linqQuery = from doc in solr.AsQueryable()
                            where doc.DefaultFieldEquals("aa") && (doc.Price >= 1 || doc.Price <= 11)
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(aa AND ((price:[1 TO *]) OR (price:[* TO  11])))", resDocs.Query);
        }
Exemplo n.º 13
0
        public void Sort()
        {
            const string queryString = "id:123456";
            var          q           = new Dictionary <string, string>();

            q["q"]    = queryString;
            q["rows"] = SolrQueryExecuter <TestDocument> .ConstDefaultRows.ToString();

            q["sort"] = "id asc";
            var conn            = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub(queryString);
            var parser          = new MSolrAbstractResponseParser <TestDocument>();

            parser.parse &= x => x.Expect(1);
            var queryExecuter = new SolrQueryExecuter <TestDocument>(parser, conn, querySerializer, null, null);
            var r             = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
                OrderBy = new[] { new SortOrder("id") }
            });

            parser.parse.Verify();
        }
Exemplo n.º 14
0
        public void Collection()
        {
            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);

            var linqQuery = from doc in solr.AsQueryable()
                            where doc.Categories.AnyItem() == "cat1"
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(cat:cat1)", resDocs.Query);
        }
Exemplo n.º 15
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)
                    }
                });
            });
        }
        public void RequestHandler()
        {
            const string queryString = "id:123456";
            var          q           = new Dictionary <string, string>();

            q["q"]       = queryString;
            q["handler"] = "/update";
            q["rows"]    = SolrQueryExecuter <TestDocument> .ConstDefaultRows.ToString();

            var queryOptions = new QueryOptions {
                RequestHandler = new RequestHandlerParameters("/update")
            };
            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), queryOptions);
        }
Exemplo n.º 17
0
        public void FilterQuery()
        {
            var mocks           = new MockRepository();
            var parser          = mocks.DynamicMock <ISolrQueryResultParser <TestDocument> >();
            var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var conn            = new MockConnection(new[] {
                KV.Create("q", "*:*"),
                KV.Create("rows", "10"),
                KV.Create("fq", "id:0"),
                KV.Create("fq", "id:2"),
            });
            var queryExecuter = new SolrQueryExecuter <TestDocument>(parser, conn, querySerializer, null, null)
            {
                DefaultRows = 10,
            };

            queryExecuter.Execute(SolrQuery.All, new QueryOptions {
                FilterQueries = new[] {
                    new SolrQuery("id:0"),
                    new SolrQuery("id:2"),
                },
            });
        }
Exemplo n.º 18
0
        public void ExecuteMLT_with_no_body()
        {
            const string queryString = "my query";

            var parser = new MSolrMoreLikeThisHandlerQueryResultsParser <SolrQueryExecuterTests.TestDocument>();
            var q      = new Dictionary <string, string>();

            q["q"]                    = queryString;
            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, string.Empty);

            var serializer = new MSolrQuerySerializer();

            serializer.serialize += _ => queryString;
            var qe = new SolrQueryExecuter <SolrQueryExecuterTests.TestDocument>(null, conn, serializer, null, parser);
            var r  = qe.ExecuteAsync(new SolrMoreLikeThisHandlerQuery(new SolrQuery(queryString)),
                                     new MoreLikeThisHandlerQueryOptions(
                                         new MoreLikeThisHandlerParameters(new[] { "one", "three" })
            {
                MatchInclude = false,
                MatchOffset  = 5,
                ShowTerms    = InterestingTerms.None,
            })
            {
                Start  = 0,
                Rows   = 5,
                Fields = new[] { "one", "two", "three" },
            });
        }
Exemplo n.º 19
0
        public void ResultFields()
        {
            const string queryString = "id:123456";
            var          q           = new Dictionary <string, string>();

            q["q"]    = queryString;
            q["rows"] = SolrQueryExecuter <TestDocument> .ConstDefaultRows.ToString();

            q["fl"] = "id,name";
            var conn            = new MockConnection(q);
            var mocks           = new MockRepository();
            var parser          = mocks.StrictMock <ISolrQueryResultParser <TestDocument> >();
            var mockR           = mocks.DynamicMock <SolrQueryResults <TestDocument> >();
            var querySerializer = new SolrQuerySerializerStub(queryString);

            With.Mocks(mocks).Expecting(delegate {
                Expect.Call(parser.Parse(null)).IgnoreArguments().Repeat.Once().Return(mockR);
            }).Verify(() => {
                var queryExecuter = new SolrQueryExecuter <TestDocument>(parser, conn, querySerializer, null, null);
                var r             = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
                    Fields = new[] { "id", "name" },
                });
            });
        }
Exemplo n.º 20
0
        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 mocks                = new MockRepository();
            var parser               = mocks.DynamicMock <ISolrQueryResultParser <TestDocument> >();
            var serializer           = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var facetQuerySerializer = new DefaultFacetQuerySerializer(serializer, new DefaultFieldSerializer());
            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"),
                    }
                }
            });
        }
Exemplo n.º 21
0
        public void ResultFields()
        {
            const string queryString = "id:123456";
            var q = new Dictionary<string, string>();
            q["q"] = queryString;
            q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
            q["fl"] = "id,name";
            var conn = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub(queryString);

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
            var r = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
                Fields = new[] { "id", "name" },
            });
        }
Exemplo n.º 22
0
        public void Highlighting()
        {
            const string highlightedField = "field1";
            const string afterTerm = "after";
            const string beforeTerm = "before";
            const int snippets = 3;
            const string alt = "alt";
            const int fragsize = 7;
            var q = new Dictionary<string, string>();
            q["q"] = "";
            q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
            q["hl"] = "true";
            q["hl.fl"] = highlightedField;
            q["hl.snippets"] = snippets.ToString();
            q["hl.fragsize"] = fragsize.ToString();
            q["hl.requireFieldMatch"] = "true";
            q["hl.alternateField"] = alt;
            q["hl.tag.pre"] = beforeTerm;
            q["hl.tag.post"] = afterTerm;
            q["hl.regex.slop"] = "4.12";
            q["hl.regex.pattern"] = "\\.";
            q["hl.regex.maxAnalyzedChars"] = "8000";
            q["hl.usePhraseHighlighter"] = "true";
            q["hl.useFastVectorHighlighter"] = "true";
            q["hl.highlightMultiTerm"] = "true";
            q["hl.mergeContiguous"] = "true";
            q["hl.maxAnalyzedChars"] = "12";
            q["hl.maxAlternateFieldLength"] = "22";
            q["hl.fragmenter"] = "regex";

            var conn = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub("");

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Highlight = new HighlightingParameters {
                    Fields = new[] { highlightedField },
                    AfterTerm = afterTerm,
                    BeforeTerm = beforeTerm,
                    Snippets = snippets,
                    AlternateField = alt,
                    Fragsize = fragsize,
                    RequireFieldMatch = true,
                    RegexSlop = 4.12,
                    RegexPattern = "\\.",
                    RegexMaxAnalyzedChars = 8000,
                    UsePhraseHighlighter = true,
                    UseFastVectorHighlighter = true,
                    MergeContiguous = true,
                    MaxAnalyzedChars = 12,
                    HighlightMultiTerm = true,
                    MaxAlternateFieldLength = 22,
                    Fragmenter = SolrHighlightFragmenter.Regex
                }
            });
        }
Exemplo n.º 23
0
        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"),
                    }
                }
            });
        }
Exemplo n.º 24
0
        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]")),
                    }
                }
            });
        }
Exemplo n.º 25
0
        public void FilterQuery()
        {
            var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var conn = new MockConnection(new[] {
                KV.Create("q", "*:*"),
                KV.Create("rows", "10"),
                KV.Create("fq", "id:0"),
                KV.Create("fq", "id:2"),
            });

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null) {
                DefaultRows = 10,
            };
            queryExecuter.Execute(SolrQuery.All, new QueryOptions {
                FilterQueries = new[] {
                    new SolrQuery("id:0"),
                    new SolrQuery("id:2"),
                },
            });
        }
Exemplo n.º 26
0
        public void Sort()
        {
            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);
            int priceVal = 1;
            DateTime dt = new DateTime(2011, 1, 1);
            var linqQuery = from doc in solr.AsQueryable()
                            where (doc.Price >= priceVal || doc.Timestamp >= dt)
                            orderby doc.Id, doc.Price descending
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual(qo.OrderBy.Count, 2);
            var so = new SortOrder("id", Order.ASC);
            Assert.IsTrue(qo.OrderBy.Contains(so));
            so = new SortOrder("price", Order.DESC);
            Assert.IsTrue(qo.OrderBy.Contains(so));
        }
Exemplo n.º 27
0
 public void QueryISolrQuery()
 {
     const string queryString = "id:123";
     var conn = new MockConnection(new Dictionary<string, string> {
         {"q", queryString},
         //{"rows", DefaultRows()},
     });
     Solr.Connection = conn;
     Solr.Query<TestDocument>(new SolrQuery(queryString));
 }
Exemplo n.º 28
0
 public void OrderBy2Multiple()
 {
     const string queryString = "id:123";
     var query = new Dictionary<string, string> {
         {"q", queryString},
         {"rows", DefaultRows()},
         {"sort", "id asc,name desc"},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>(new SolrQuery(queryString), new[] {
         new SortOrder("id", Order.ASC),
         new SortOrder("name", Order.DESC)
     });
 }
Exemplo n.º 29
0
 public void OrderBy()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"q", "((Id:123456))"},
         {"sort", "id asc"},
         {"rows", DefaultRows()},
     });
     Solr.Connection = conn;
     Solr.Query<TestDocumentWithId>()
         .By("Id").Is("123456")
         .OrderBy("id")
         .Run();
 }
Exemplo n.º 30
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")),
                 },
             }
         });
     });
 }
Exemplo n.º 31
0
 public void QueryByExample()
 {
     var query = new Dictionary<string, string> {
         {"q", "(Id:123456)"},
         {"rows", DefaultRows()},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     var doc = new TestDocumentWithId {Id = 123456};
     Solr.Query<TestDocumentWithId>().By("Id").Is("123456").Run();
 }
Exemplo n.º 32
0
        public void HighlightingWithoutFieldsOutputsPrePost() {
            const string afterTerm = "after";
            const string beforeTerm = "before";

            var q = new Dictionary<string, string>();
            q["q"] = "";
            q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
            q["hl"] = "true";
            q["hl.tag.pre"] = beforeTerm;
            q["hl.tag.post"] = afterTerm;
            q["hl.useFastVectorHighlighter"] = "true";

            var conn = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub("");

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Highlight = new HighlightingParameters {
                    AfterTerm = afterTerm,
                    BeforeTerm = beforeTerm,
                    UseFastVectorHighlighter = true,
                }
            });
        }
Exemplo n.º 33
0
 public void QueryByAnyField()
 {
     var query = new Dictionary<string, string> {
         {"q", "((id:123456))"},
         {"rows", DefaultRows()},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>().By("id").Is("123456").Run();
 }
Exemplo n.º 34
0
 public void QueryByRangeConcatenable()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"q", "((id:[123 TO 456])  p:[a TO z])"},
         {"rows", DefaultRows()},
     });
     Solr.Connection = conn;
     Solr.Query<TestDocument>().ByRange("id", 123, 456).ByRange("p", "a", "z").Run();
 }
Exemplo n.º 35
0
 public void QueryByRangeInclusive()
 {
     var query = new Dictionary<string, string> {
         {"q", "(id:[123 TO 456])"},
         {"rows", DefaultRows()},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>().ByRange("id", 123, 456).Inclusive().Run();
 }
Exemplo n.º 36
0
 public void QueryISolrQueryWithPagination()
 {
     const string queryString = "id:123";
     var query = new Dictionary<string, string> {
         {"q", queryString},
         {"start", 10.ToString()},
         {"rows", 20.ToString()}
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>(new SolrQuery(queryString), 10, 20);
 }
Exemplo n.º 37
0
        public void Highlighting()
        {
            const string highlightedField = "field1";
            const string afterTerm        = "after";
            const string beforeTerm       = "before";
            const int    snippets         = 3;
            const string alt      = "alt";
            const int    fragsize = 7;
            var          q        = new Dictionary <string, string>();

            q["q"]    = "";
            q["rows"] = SolrQueryExecuter <TestDocument> .ConstDefaultRows.ToString();

            q["hl"]                          = "true";
            q["hl.fl"]                       = highlightedField;
            q["hl.snippets"]                 = snippets.ToString();
            q["hl.fragsize"]                 = fragsize.ToString();
            q["hl.requireFieldMatch"]        = "true";
            q["hl.alternateField"]           = alt;
            q["hl.tag.pre"]                  = beforeTerm;
            q["hl.tag.post"]                 = afterTerm;
            q["hl.regex.slop"]               = "4.12";
            q["hl.regex.pattern"]            = "\\.";
            q["hl.regex.maxAnalyzedChars"]   = "8000";
            q["hl.usePhraseHighlighter"]     = "true";
            q["hl.useFastVectorHighlighter"] = "true";
            q["hl.highlightMultiTerm"]       = "true";
            q["hl.mergeContiguous"]          = "true";
            q["hl.maxAnalyzedChars"]         = "12";
            q["hl.maxAlternateFieldLength"]  = "22";
            q["hl.fragmenter"]               = "regex";

            var conn            = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub("");

            var parser = new MSolrAbstractResponseParser <TestDocument>();

            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter <TestDocument>(parser, conn, querySerializer, null, null);

            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Highlight = new HighlightingParameters {
                    Fields                   = new[] { highlightedField },
                    AfterTerm                = afterTerm,
                    BeforeTerm               = beforeTerm,
                    Snippets                 = snippets,
                    AlternateField           = alt,
                    Fragsize                 = fragsize,
                    RequireFieldMatch        = true,
                    RegexSlop                = 4.12,
                    RegexPattern             = "\\.",
                    RegexMaxAnalyzedChars    = 8000,
                    UsePhraseHighlighter     = true,
                    UseFastVectorHighlighter = true,
                    MergeContiguous          = true,
                    MaxAnalyzedChars         = 12,
                    HighlightMultiTerm       = true,
                    MaxAlternateFieldLength  = 22,
                    Fragmenter               = SolrHighlightFragmenter.Regex
                }
            });
        }
Exemplo n.º 38
0
 public void OrderByAscDescMultiple()
 {
     var query = new Dictionary<string, string> {
         {"q", "((Id:123456))"},
         {"rows", DefaultRows()},
         {"sort", "id asc,name desc"},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     var doc = new TestDocumentWithId {Id = 123456};
     Solr.Query<TestDocumentWithId>()
         .By("Id").Is("123456")
         .OrderBy("id", Order.ASC)
         .OrderBy("name", Order.DESC)
         .Run();
 }
Exemplo n.º 39
0
 public void HighlightingFields()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"q", "((makedesc:bmw))"},
         {"hl", "true"},
         {"hl.fl", "make,category"},
         {"rows", DefaultRows()},
     });
     Solr.Connection = conn;
     var r = Solr.Query<TestDocument>().By("makedesc").Is("bmw").WithHighlightingFields("make", "category").Run();
 }
Exemplo n.º 40
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});
            });
        }
Exemplo n.º 41
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);
     });
 }
Exemplo n.º 42
0
 public void QueryByRange_AnotherSyntax()
 {
     var query = new Dictionary<string, string> {
         {"q", "(id:[123 TO 456])"},
         {"rows", DefaultRows()},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>().By("id").Between(123).And(456).Run();
 }
Exemplo n.º 43
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)
                    }
                });
            });
        }
Exemplo n.º 44
0
 public void Highlighting()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"q", "(makedesc:bmw)"},
         {"hl", "true"},
         {"hl.fl", "make"},
         {"rows", DefaultRows()},
     });
     Solr.Connection = conn;
     var r = Solr.Query<TestDocument>().By("makedesc").Is("bmw").WithHighlighting(new HighlightingParameters {
         Fields = new[] {"make"},
     }).Run();
 }