0
votes

I'm quite new to RavenDB so sorry if my question sounds stupid. I have a class which contains a DateTime property. I store instances of this class in RavenDB. I have defined index the following way:

from doc in docs.Orders
from docItemsItem in ((IEnumerable<dynamic>)doc.Items).DefaultIfEmpty()
select new { Items_Price_Amount = docItemsItem.Price.Amount, Items_Quantity = docItemsItem.Quantity, Date = doc.Date }

http://dl.dropbox.com/u/3055964/Capture.GIF <-- here's a screenshot

Here's class definition:

    public class Order
    {
        public DateTime Date { get; set; }
        public IList<OrderItem> Items { get; set; }
        public string CustomerId { get; set; }

        public Order()
        {
            Items = new List<OrderItem>();
        }
    }

Now, when I try to query RavenDB with the index shown above, the query yields no result at all.

var orders = session.Query<Order>("OrdersIndex").Where(o => o.Date > DateTime.Now).ToList(); // orders.Count == 0

If I omit the index from query, like this:

var orders = session.Query<Order>().Where(o => o.Date > DateTime.Now).ToList(); // orders.Count == 128

a temporary index is created and eveything works as expected.

Does anyone has any idea what's wrong with my query? Thanks.

UPDATE

Allright, I removed Fields Date, Items,Price,Amount and Items,Quantity via management studio (shown in screenshot), and now the query works fine. Anyone any idea why? What's the purpose to define those fields explicitly?

1
Can you try providing a full failing test to understand what is going on in here? - Ayende Rahien
Thank you for your response Ayende, I appreciate your help and your effort you invested in RavenDB :) I will update my post in a few hours and upload the database and full working tests. But probably, this was my fault because I guess I wasn't using indexes correctly. - Davita

1 Answers

4
votes

Check that the date in the Index is stored as Index(x => x.Date, FieldIndexing.Default).

I had it set to FieldIndexing.Analysed, and wasn't getting the correct results back.

I need to read up more on the difference between the different FieldIndexing options :)