RavenDB分面搜索:我的价格范围错误

时间:2013-05-01 12:54:56

标签: ravendb

我正在尝试实施这种分面的搜索逻辑:http://ravendb.net/docs/2.0/client-api/faceted-search。但是,从数据库返回的每个价格范围的命中都不能按预期工作;所有点击都按最后的价格范围分组。

我的产品文档如下:

{
  "Sku": "000000000000069673",
  "Title": "APPLE ME186",
  "Brand": "APPLE",
  "RegularPrice": 84.99,
  "ReferencePrice": 0.0,
  "YouSavePrice": 0.0,
  "ShortDescription": "",
  "Description": "",
  "CategoryHierarchyPath": "Beeld en geluid/Hoofdtelefoons/In-ear koptelefoon",
  "Categories": [
    "0/Beeld en geluid",
    "1/Beeld en geluid/Hoofdtelefoons",
    "2/Beeld en geluid/Hoofdtelefoons/In-ear koptelefoon"
  ],
  "Stocks": [
    {
      "Quantity": ,
      "Branch": ""
    }
  ],
  "Images": [],
  "Attributes": [
    {
      "Name": "",
      "Value": ""
    }
  ]
}

我要查询的索引:

public class CategoryProducts : AbstractIndexCreationTask<Product, CategoryProducts.ReduceResult>
{
    public class ReduceResult
    {
        public string Category { get; set; }
        public string Title { get; set; }
        public decimal RegularPrice { get; set; }
        public string ShortDescription { get; set; }
        public int Description { get; set; }
    }

    public CategoryProducts()
    {
        Map = products =>
              from p in products
              from c in p.Categories
              select new
              {
                  Category = c,
                  Title = p.Title,
                  RegularPrice = p.RegularPrice,
                  ShortDescription = p.ShortDescription,
                  Description = p.Description
              };
    }
}

FacetSetup:

Facets = new List<Facet>
{
new Facet
    {
        Name = "RegularPrice",
        Mode = FacetMode.Ranges,
        Ranges =
            {
                "[NULL TO Dx200.0]",
                "[Dx200.0 TO Dx400.0]",
                "[Dx400.0 TO Dx600.0]",
                "[Dx600.0 TO Dx800.0]",
                "[Dx800.0 TO NULL]",
            }
    }
}

查询:

var priceRangeFacets = Session.Query<CategoryProducts.ReduceResult, CategoryProducts>()
            .Where(r => r.Category.StartsWith("1/Beeld en   geluid/Hoofdtelefoons")).ToFacets("facets/PriceRanges")

结果:

[0] = {Range: [NULL TO Dx200.0], Hits: 0}
[1] = {Range: [Dx200.0 TO Dx400.0], Hits: 0}
[2] = {Range: [Dx400.0 TO Dx600.0], Hits: 0}
[3] = {Range: [Dx600.0 TO Dx800.0], Hits: 0}
[4] = {Range: [Dx800.0 TO NULL], Hits: 77}

请注意,我的数据库中的产品比800便宜。

P.S。我正在使用RavenDB-Build-2330

1 个答案:

答案 0 :(得分:1)

Ayende对我创造的失败测试的纠正后解决了:

  
      
  • 在数字字段上进行范围搜索时,需要使用_Range postfix
  •   
  • 您需要[NULL TO Dx200.0}
  •   
     

[包容性,}是独家的。

所以我们的方面设置应该声明为:

Facets = new List<Facet>
{
    new Facet
    {
        Name = "RegularPrice_Range",
        Mode = FacetMode.Ranges,
        Ranges =
        {
            "[NULL TO Dx200.0}",
            "[Dx200.0 TO Dx400.0}",
            "[Dx400.0 TO Dx600.0}",
            "[Dx600.0 TO Dx800.0}",
            "[Dx800.0 TO NULL}",
        }
    }
}