1

I've been playing around with the RavenDB Northwind database, and am having trouble getting orders sorted by Freight.

My index:

    Map = orders => from o in orders
                    select new {
                            o.Freight
                        };
    IndexSortOptions.Add(x => x.Freight, SortOptions.Double);
    Indexes.Add(x => x.Freight, FieldIndexing.NotAnalyzed);

My query:

 return sess.Query<Order>("Orders/ByFreight")
                    .OrderByDescending(x => x.Freight)
                    .Select(x => x.Freight);

It get the following order back:

[
    32.38,
    11.61,
    65.83,
    41.34 ... ]

Which is clearly not correct. In the studio, I can define the order to be by Freight, and it orders just fine. However, if in the studio I specify the range as over Freight_Range, I get these same results back. It appears to me that Raven is selecting the Freight_Range field to sort by rather than the Freight field. Why?

heneryville
  • 2,853
  • 1
  • 23
  • 30

1 Answers1

1
  • Remove the line starting with Indexes.Add. You don't need to do that.

  • Use this syntax instead of the IndexSortOptions:

    Sort(x=> x.Freight, SortOptions.Double);
    
  • Make sure your Freight field is indeed a double as defined on your Order class.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575