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);
     });
 }
示例#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);
        }
示例#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")},
     });
 }
示例#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();
 }
示例#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") },
            });
        }
示例#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);
        }
示例#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);
        }
示例#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" },
            });
        }
示例#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
                            },
                        },
                    }
                });
            });
        }
示例#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);
            });
        }
示例#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);
        }
示例#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);
        }
示例#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();
        }
示例#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);
        }
示例#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);
        }
示例#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"),
                },
            });
        }
示例#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" },
            });
        }
示例#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" },
                });
            });
        }
示例#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"),
                    }
                }
            });
        }
        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" },
            });
        }
        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
                }
            });
        }
        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]")),
                    }
                }
            });
        }
        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"),
                },
            });
        }
示例#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));
        }
示例#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));
 }
示例#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)
     });
 }
示例#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();
 }
示例#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")),
                 },
             }
         });
     });
 }
示例#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();
 }
示例#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,
                }
            });
        }
示例#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();
 }
示例#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();
 }
示例#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();
 }
示例#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);
 }
示例#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
                }
            });
        }
示例#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();
 }
示例#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();
 }
示例#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});
            });
        }
示例#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);
     });
 }
示例#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();
 }
示例#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)
                    }
                });
            });
        }
示例#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();
 }