Sample search results pages
(One intermediate revision by one user not shown) | |||
Line 28: | Line 28: | ||
Of course you can add other categories and use them for other purposes, but as long as you always set a category in the search object, you will not find files in the "forbidden" category. | Of course you can add other categories and use them for other purposes, but as long as you always set a category in the search object, you will not find files in the "forbidden" category. | ||
+ | |||
+ | Remember to rebuild the index after assigning categories. | ||
+ | |||
+ | ---- | ||
+ | '''Have a look at a result page example for showing custom xml content fields on [[Writing_only_specific_xml-element-data_to_the_lucene_index#Creating_a_search_result_page]]''' |
Latest revision as of 09:06, 21 May 2010
You would use the search index in a JSP something like this:
CmsJspActionElement cmsJae = new CmsJspActionElement(pageContext, request, response); CmsSearch search = new CmsSearch();
search.setIndex("online"); search.setQuery(queryString); search.init(cmsJae.getCmsObject()); List searchResults = search.getSearchResult();
Iterator iterator = searchResults.iterator(); while (iterator.hasNext()) { CmsSearchResult r = (CmsSearchResult)iterator.next(); //do stuff... }
Often you want to exclude some files or directories from the search results.
You can do this by using search categories.
All you have to do is set a default category in the properties for the root folder of the site (for example "searchable").
This property is inherited by folders and files in the site, as long as you do not overwrite it.
Now set this category when initializing the search object:
search.setCategories(new String[] {"searchable"} );
Files or complete folders that shall not appear in the search results simply gets a different category (for example "nosearch").
Of course you can add other categories and use them for other purposes, but as long as you always set a category in the search object, you will not find files in the "forbidden" category.
Remember to rebuild the index after assigning categories.
Have a look at a result page example for showing custom xml content fields on Writing_only_specific_xml-element-data_to_the_lucene_index#Creating_a_search_result_page