RavenDB 分面搜索并在 mvc3 中创建面包屑/过滤器 url
我正在使用 mvc3 和 RavenDB。我有一个过滤菜单,用户可以在其中缩小范围 他们使用分面搜索进行搜索,如下所述: http://ravendb.net/docs/client-api/advanced/faceted-search
我喜欢这样的 URL 模式:/filter/{manufacturer}/{resolution}/{zoom}
例如:/filter/canon/6
表示列出制造商canon的所有相机 百万像素为 6(以及所有变焦范围)。
我可以正常工作,但生成 URL 时遇到问题。这只会 如果 Facet 值可以安全地在 URL 中使用,则可以工作,例如。替换所有&符号, 空格等,带有破折号和小写所有内容。这意味着我最终 我的过滤菜单链接和面包屑中带有“丑陋”的名称。
有没有办法向用户显示一个友好的名称以获取构面值? 所以我可以创建这样的网址:
<a href="/filter/canon/">Canon USA (12)</a>
<a href="/filter/canon/6/">6 megapixels (5)</a>
我能想到的一种解决方案是将过滤器存储为文档 只需搜索构面值即可检索其显示名称。
过滤器文档可以如下所示:
var filter = new Filter
{
DisplayName = "Manufacturer" ,
Slug = "manufacturer" ,
Items = new List< FilterItem >
{
new FilterItem() { DisplayName = "Canon USA" , Slug = "canon" } ,
new FilterItem() { DisplayName = "Photo's & more" , Slug = "photos-and-more" }
}
} ;
I am using mvc3 and RavenDB. I have a filter menu where users can narrow
their search using faceted search, as described here:
http://ravendb.net/docs/client-api/advanced/faceted-search
I like to have this URL pattern: /filter/{manufacturer}/{resolution}/{zoom}
For example: /filter/canon/6
means list all camera's of manufacturer canon with
a megapixel of 6 (and all zoom ranges).
I have this working but I run into trouble generating URLs. This will only
work if the facet values are safe to use in a URL eg. replace all ampersands,
spaces etc with a dash and lower case everything. This means I end up
with 'ugly' names in my filtermenu links and breadcrumbs.
Is there a way to have a friendly name to display to the user for a facet value?
so I can create urls like this:
<a href="/filter/canon/">Canon USA (12)</a>
<a href="/filter/canon/6/">6 megapixels (5)</a>
One solution I can think of would be to store the filters as documents
and just search for a facet value to retrieve its displayname.
A filter document can look like this:
var filter = new Filter
{
DisplayName = "Manufacturer" ,
Slug = "manufacturer" ,
Items = new List< FilterItem >
{
new FilterItem() { DisplayName = "Canon USA" , Slug = "canon" } ,
new FilterItem() { DisplayName = "Photo's & more" , Slug = "photos-and-more" }
}
} ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
安德鲁,
是的,这可能就是您想要做的。一般来说,既然你控制了价值观,你就可以控制这些价值观,但没有理由在全球范围内让事情变得困难。您可以将值存储在某处并在它们之间进行映射。
一切都会变得更容易。
Andrew,
Yes, that is probably what you want to do. In general, since you control the values, you can control what those will be, but there is no reason to make things hard globally. You can just store the values somewhere and map between them.
It would be easier all around.