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); }
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); }
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); }
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)); }
public void PartialEval() { 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) select doc; QueryOptions qo; var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo); Assert.AreEqual("((price:[1 TO *]) OR (timestamp:[2011-01-01T12:00:00.000Z TO *]))", resDocs.Query); }