Make a optional search in umbraco

扶醉桌前 提交于 2019-12-11 10:58:27

问题


I made new document type in umbraco.then made some node by this document type in content. i will set up a new search index so found this code that Setting up a new search index.

@* Get the search term from query string *@
@{var searchTerm = Request.QueryString["search"];}
@{var results = ExamineManager.Instance.Search(searchTerm, true); }

but i do not know how to limited this code that can search only in my document type.


回答1:


There are couple of steps for this.

You will have to:

  • Create a ISearchCriteria object;
  • Create an search expression from the criteria object, including the docType alias as a field to be searched;
  • Search using the expression.

This can be coded as:

var criteria = ExamineManager.Instance.CreateSearchCriteria();

var expression = criteria.Field("nodeTypeAlias", "yourDocTypeAlias")
                         .And()
                         .Field("nodeName", searchTerm);

var results = ExamineManager.Instance.Search(expression.Compile());

This is possible because when Umbraco publishes a node, it saves the node's docType alias to the search index.

There is more Examine documentation here. I would also recommend downloading Luke which is a standalone tool that will allow you to look inside an index so you can see what is actually stored by Umbraco.



来源:https://stackoverflow.com/questions/14333732/make-a-optional-search-in-umbraco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!