2012-03-30 2 views

답변

2

RavenDB에서 쿼리를 수행 할 수 없습니다. 쿼리하는 필드는 술어의 왼쪽에 있어야하며 술어의 오른쪽은 다른 필드를 참조 할 수 없습니다.

구조 조정 방법은 - 확실하지 않습니다.

편집 :

좋아, 그것은 몇 가지 실험을했다 - 그러나 나는 그것이 하나 구조 조정 MaterializedPath에 가능하다면 일을하거나 새 속성을 추가 할 수 있었다. 여기 혼란을 피하기 위해 새로운 재산이라고 가정하겠습니다.

// Sample class: 
public class Item 
{ 
    public string Name { get;set;} 
    public Dictionary<int, string> Path { get;set;} // Zero-based key on path. 
} 


// Query: Find nodes with path "A B" 
var query = session.Query<Item>().AsQueryable(); 
query = query.Where(item => item.Path[0] == "A"); 
query = query.Where(item => item.Path[1] == "B"); 

var found = query.ToList(); 

그리고 여기가 실행이에서

IDocumentStore store = new EmbeddableDocumentStore { RunInMemory = true }; 
store.Initialize(); 

// Install Data 
using (var session = store.OpenSession()) 
{ 
    session.Store(new Item("Foo1", "A")); // NB: I have a constructor on Item which takes the path and splits it up. See below. 
    session.Store(new Item("Foo2", "A B")); 
    session.Store(new Item("Foo3", "A C D")); 
    session.Store(new Item("Foo4", "A B C D")); 
    session.Store(new Item("Foo5", "C B A")); 
    session.SaveChanges(); 
} 

using (var session = store.OpenSession()) 
{ 
    var query = session 
     .Query<Item>().AsQueryable(); 

    query = query.Where(item => item.Path[0] == "A"); 
    query = query.Where(item => item.Path[1] == "B"); 

    var found = query.ToList(); 

    Console.WriteLine("Found Items: {0}", found.Count); 

    foreach(var item in found) 
    { 
     Console.WriteLine("Item Name {0}, Path = {1}", item.Name, string.Join(" ", item.Path)); 
    } 
} 

출력은 다음과 같습니다 도움이

Found Items: 2 
Item Name Foo2, Path = [0, A] [1, B] 
Item Name Foo4, Path = [0, A] [1, B] [2, C] [3, D] 

희망.

편집 2 : 나는 검색의 모든 가능성을 포함하는 인덱스를 구축 제안합니다

public Item(string name, string materializedPath) 
    { 
     Name = name; 
     var tmpPath = materializedPath.Split(' '); 
     Path = 
      tmpPath 
       .Zip(Enumerable.Range(0, tmpPath.Count()), (item, index) => new {Item = item, Index = index}) 
       .ToDictionary(k => k.Index, v => v.Item); 
    } 
+0

을 표현하는 것이 중요 - 측면을 플립없는 이유 이 술어에 그것은 효과적으로 동일을해야합니까, 또는 나는 무언가를 잃었 는가? –

+0

"A B C"는 "A B"로 시작하고 "A B"는 "A B C"로 시작하지 않습니다. –

+0

나는 RavenDB가 Lucene (Lucene은 전체 텍스트 검색 엔진이 이것을 할 수 있어야 함)을 기반으로하기 때문에 이것을하는 방법이 있다고 확신한다. RavenDB 고급 Lucene 쿼리와 같은 것일까? – W3Max

1

:

내가 항목에있는 생성자는 테스트의 용이성을 위해, 다음과 같습니다 . 이 색인에있는 항목을 많이 만들어하지만 동시에 검색 루씬의 힘을 빠르게

Map = docs => from n in docs 
       let allPaths = n.MaterializedPath.Split(new char[]{' '}) 
       from path in allPaths 
       select new 
       { 
       Path = path 
       }; 

그것은 "경로"는 고유 한 문서 ID 또한

+0

아주 좋은 답변입니다. 처음 엔 작동 할 수 있다고 생각했지만 불행히도 태그는 나무와 조금 다릅니다. – W3Max