Graffiti CMS:搜索自定义字段
我正在尝试找出一种方法来搜索帖子的自定义字段。基本上,我需要的是找到一篇帖子,其中 post.CustomField1 == "some value"
我已经搜索并搜索并挖掘了 Graffiti CMS 源代码 (graffiticms.codeplex.com),但无法弄清楚我如何会这样做。
I am trying to figure out a way to search through posts' custom fields. Basically, what I need is to find a post where post.CustomField1 == "some value"
I've searched and searched and been digging through the Graffiti CMS source code (graffiticms.codeplex.com) and can't figure out how I would do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 EJB 所说,解决方案因您要实现搜索的位置而异。
如果您想查找具有特定自定义字段值的帖子,只需搜索当前页面上显示的帖子(例如index.view或类别视图),您可以在模板中使用Chalk来完成,如下所示:
您也可以使用 API 迭代所有帖子并检查自定义值。不幸的是,Graffiti CMS 没有内置方法来根据特定的自定义字段值查询数据库中的帖子。
但是您可以使用内置的基于 Lucene 的搜索引擎。如果您想使用搜索来搜索特定的自定义字段值,则需要对 Graffiti.Core.SearchIndex 类中的源代码进行一些调整。在 CreateDocument 方法中,将自定义字段值添加到索引文档,如下所示:
然后在 GetQueryParser 方法中,将该键添加到要搜索的字段列表中:
通过上述两项更改,您将能够搜索“某个值”并让它返回具有 CustomField1 值的任何帖子。
希望有帮助!
As EJB said, the solution varies with where you want to implement the search.
If you want to find a post with a particular custom field value, searching on just the posts displayed on the current page (such as index.view or a category view) you could do it with Chalk in a template like this:
You could also use the API to iterate through ALL posts and check for the custom value. Unfortunately Graffiti CMS doesn't have a built-in method to query the database for posts based on a specific custom field value.
However you could use the built-in Lucene-based search engine. If you want to enable searching for a particular custom field value using search, you'd need to make a couple tweaks to the source code in the Graffiti.Core.SearchIndex class. In the CreateDocument method add the custom field value to the indexed Document like this:
Then in the GetQueryParser method add that key to the list of fields to search on:
With the two changes above, you'd be able to do a search for "some value" and have it return any posts with CustomField1 value of that.
Hope that helps!