如何在Ravendb中创建复合索引
我的基地(RavenDB)中有文档集合“消息” 文档定义如下:
class Message
{
string Content;
Tag[] Tags;
Location[] Locations;
string[] Actions;
bool IsActive;
}
标签类定义:
class Tag
{
string Value;
Translation[] Translations;
}
位置类:
class Location
{
string Code;
Translation[] Translations;
}
翻译类:
class Translation
{
string LanguageCode;
string Value;
}
因此,我想创建一个索引,允许我通过多个字段进行查询:
- 按 Message.Content 进行全文搜索
- 仅包含 IsActive==true 的
- 消息包含我在 Message.Actions 中的操作
- 消息包含带有 myValue 和 myLanguageCode 的标记
- 位置包含带有某些 myCode 和 myLanguageCode 的位置
我想同时查询所有条件
那么,我应该如何为 RavenDB 定义索引?
I have documents collection "Messages" in my base (RavenDB)
Document definition like:
class Message
{
string Content;
Tag[] Tags;
Location[] Locations;
string[] Actions;
bool IsActive;
}
Tag class definition:
class Tag
{
string Value;
Translation[] Translations;
}
Location class:
class Location
{
string Code;
Translation[] Translations;
}
Translation class:
class Translation
{
string LanguageCode;
string Value;
}
So, I want to create a index that will allow me to make queries by several fields:
- Full-text search by Message.Content
- Only messages with IsActive==true
- Messages that contains my action in Message.Actions
- Messages that contains tag with myValue and myLanguageCode
- Locations that contains location with some myCode and myLanguageCode
I would like to query to be on all the conditions simultaneously
So, how should i define index for RavenDB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,在对 RavenDB 自动动态索引进行简短研究后,我创建了类似的东西
Well, after a short studies of RavenDB auto dynamic indexes i created something like
在 RavenDB 中进行查询时无需预先定义索引。只需创建 linq-query - RavenDB 就会为您动态创建索引,无需任何额外成本。
您可能想要自己创建索引的唯一用例是,如果想要指定不同的 Lucene.NET 分析器来对 Message.Content 字段执行所谓的“全文搜索”。但即便如此,也应该像为索引创建 linq 查询并在启动时将其传递到 RavenDB 一样简单。如果您想知道如何做到这一点,我建议您查看 Ayende RaccoonBlog 示例或官方文档,它们将很快更新(仅供参考 -> ravendb/docs 有新文档)。
There's no need to define an index upfront to do queries in RavenDB. Just create the linq-query - RavenDB will then dynamically create an index for you without any additional cost.
The only use-case where you would possible want to create an index by your own, would be if want do specify a different Lucene.NET analyzer to do what you call "full-text search" on the field Message.Content. But even that should be as simple as just creating the linq-query for the index and pass it into RavenDB on startup. If you want to know how to do that, I recommend to have a look into Ayende RaccoonBlog sample or the officials docs, which will be updated soon (FYI -> ravendb/docs has the new docs).