2014-11-06 22 views

回答

3

更新:作为5/6/15,DocumentDB添加一组字符串的功能,包括STARTSWITHENDSWITH,和CONTAINS。请注意,大多数这些函数不会在索引上运行,并会强制执行扫描。

LIKECONTAINS尚未在DocumentDB中受支持。

您需要查看DocumentDB feedback page并对功能进行投票(例如LIKECONTAINS)才能听到您的声音!

+0

感谢您的信息,我已经和投票,但我猜那些没有被异常的支持。我问是否有任何其他的方式来绕过它,而不是把整个集合拉到客户端,并在那里过滤。 – bUKaneer 2014-11-07 03:15:27

+1

根据您处理的日期大小而定 - 一种潜在的解决方法是创建UDF以过滤服务器端的查询结果。这个警告是UDFs有限的执行时间,并没有利用指数;您将希望避免大扫描(尽可能过滤对索引值的查询)并限制传递给UDF的数据量。 – 2014-11-07 23:15:58

+0

请将您的注意力放在我的解决方案上,也许您会反馈您是否认为这是一个合理的解决方案,而不是UDF方法? – bUKaneer 2014-11-08 01:23:56

0

因为我只需要搜索较大对象属性的谨慎子集,我实现了.Contains搜索功能,如下所示。它按预期工作,但我不知道性能或可伸缩性。

领域模型

public interface ITaxonomySearchable 
{ 
    string Name { get; set; } 
    string Description { get; set; } 
} 

public class TaxonomySearchInfo : ITaxonomySearchable { 
    [JsonProperty(PropertyName = "id")] 
    public Guid Id { get; set; } 
    [JsonProperty(PropertyName = "name")] 
    public string Name { get; set; } 
    [JsonProperty(PropertyName = "description")] 
    public string Description { get; set; } 
} 

public class TaxonomyContainer : ITaxonomySearchable 
{ 
    [JsonProperty(PropertyName = "id")] 
    public Guid Id { get; set; } 
    [JsonProperty(PropertyName = "userId")] 
    public string UserId { get; set; } 
    [JsonProperty(PropertyName = "name")] 
    public string Name { get; set; } 
    [JsonProperty(PropertyName = "description")] 
    public string Description { get; set; } 
    [JsonProperty(PropertyName = "tags")] 
    public string[] Tags { get; set; } 
    [JsonProperty(PropertyName = "taxonomy")] 
    public Node[] Taxonomy { get; set; } 
} 

搜索方法

public async static Task<List<TaxonomySearchInfo>> Search(string searchTerm) 
{ 
    var db = GetJsonDocumentDb.GetDb(); 
    using (var client = GetJsonDocumentDb.GetClient()) 
    { 
     var documentCollection = await GetJsonDocumentDb.GetDocumentCollection(db, client, "TaxonomyContainerCollection"); 
     return client.CreateDocumentQuery<TaxonomySearchInfo>(documentCollection.DocumentsLink) 
      .AsEnumerable() 
      .Where(r => r.Name.Contains(searchTerm) || r.Description.Contains(searchTerm)) 
      .ToList(); 
    } 
} 
+1

您的搜索方法中的查询看起来好像它会通过UDF从集合中传递具有名称或说明属性的每个文档 - 这可能会花费很多,具体取决于集合中符合此条件的文档数量。您可以尝试分解查询(一个用于名称,另一个用于描述)并合并;并尽可能在where子句中添加任何其他过滤器/提示。尝试运行查询并确保在x-ms-request-charge头中使用的RU的数量是可以接受的。 – 2014-11-10 18:45:42

+0

有一个相当不错的工具,名为DocumentDB Studio,它可以很容易地尝试查询和检查响应/头文件...链接:https://github.com/mingaliu/DocumentDBStudio/releases – 2014-11-10 18:48:05

+0

非常感谢您阅读本文,关于DocumentDB工作室的小贴士 - 非常感谢! – bUKaneer 2014-11-11 09:37:43