2014-08-27 3 views
1

FacetSetup 문서에 정의 된 범위가있는면이 있습니다. 나는 FacetSetup에서 Id (ToFacets()로 전화 할 때 FacetSetup 대신)을 지정하여 개별 Facet을 검색 할 수있는 기능을 가지고 있기 때문에 지금까지는 이러한 Ranged Facets로 시도했지만 지금까지 성공하지 못했습니다.RavenDB : 개별 범위면을 검색 할 수 없습니다.

여기 내 실패 시험입니다. 어떤 팁?

using Raven.Abstractions.Data; 
using Raven.Abstractions.Indexing; 
using Raven.Client; 
using Raven.Client.Embedded; 
using Raven.Tests.Helpers; 
using System.Collections.Generic; 
using System.Linq; 
using Xunit; 

namespace RavenDBTests 
{ 
    public class RangedFacetTests : RavenTestBase 
    { 
     [Fact] 
     public void RangedFacetTest() 
     { 
      using (EmbeddableDocumentStore documentStore = NewDocumentStore()) 
      { 
       // create and store an index 
       Dictionary<string, string> analyzers = new Dictionary<string, string>(); 
       analyzers.Add("MyProperty", ""); 
       Dictionary<string, SortOptions> sortOptions = new Dictionary<string, SortOptions>(); 
       sortOptions.Add("MyProperty", SortOptions.Long); 

       IndexDefinition indexDefinition = new IndexDefinition() 
        { 
         Analyzers = analyzers, 
         SortOptions = sortOptions, 
         Map = @"from d in docs 
select new 
{ 
    MyProperty = d.MyProperty 
}", 
        }; 

       documentStore.DatabaseCommands.PutIndex("MyIndex", indexDefinition); 

       using (IDocumentSession documentSession = documentStore.OpenSession()) 
       { 
        // store some sample documents 
        documentSession.Store(new { MyProperty = 10 }); 
        documentSession.Store(new { MyProperty = 25 }); 
        documentSession.Store(new { MyProperty = 100 }); 

        // store a facetsetup with one ranged facet 
        documentSession.Store(new FacetSetup 
        { 
         Id = "facets/MyFacetSetup", 
         Facets = new List<Facet>() 
         { 
          new Facet() 
          { 
           Mode = FacetMode.Ranges, 
           Name = "MyProperty_Range", 
           Ranges = new List<string>() 
           { 
            "[0x0000000000000001 TO 0x0000000000000032]" 
           } 
          } 
         } 
        }, "facets/MyFacetSetup"); 

        documentSession.SaveChanges(); 
       } 

       // let that process 
       WaitForIndexing(documentStore); 

       using (IDocumentSession documentSession = documentStore.OpenSession()) 
       { 
        // retrieve ALL facets 
        FacetResults facetResults1 = documentSession.Query<dynamic>("MyIndex").ToFacets("facets/MyFacetSetup"); 

        Xunit.Assert.True(facetResults1.Results.Values.First().Values.First().Hits > 0); 

        // retrieve SPECIFIED facets 
        FacetResults facetResults2 = documentSession.Query<dynamic>("MyIndex").ToFacets(new List<Facet>() 
         { 
          new Facet() 
          { 
           Mode = FacetMode.Ranges, 
           Name = "MyProperty_Range" 
          } 
         }, 
         0, 
         null); 

        // this fails: why can't I specify the ranged facet? 
        Xunit.Assert.True(facetResults2.Results.Values.First().Values.First().Hits > 0); 
       } 
      } 
     } 
    } 
} 

답변

2

코드에 실제 범위가 무엇인지 명시하지 않습니다.

RavenDB에서는 패싯을 만드는 두 가지 방법이 있습니다. 하나는 패싯 문서 ID를 지정하는 것이고 두 번째는 패싯을 실제로 전달하는 것입니다. 이 경우 범위가없는 범위 패싯을 전달하므로 결과를 반환하지 않습니다. 다음 코드 사용 :

FacetResults facetResults2 = documentSession.Query<dynamic>("MyIndex").ToFacets(new List<Facet>() 
         { 
          new Facet() 
          { 
           Mode = FacetMode.Ranges, 
           Name = "MyProperty_Range", 
           Ranges = new List<string>() 
           { 
            "[0x0000000000000001 TO 0x0000000000000032]" 
           } 
          } 
         }, 
         0, 
         null); 
관련 문제