Use this guide to help you navigate some aspects of customizing the search in Orchard. Afterwards you will be able to index fields of a part in the example I will be using price and indexing a quick mock of products.
Using the code
The key parts are:
- indexing (if you are including custom fields) To include the data in the index catalog it will need a ContentHandler that has a bit of code like:
- OnIndexing<TestPricePart>((context, part) =>
- context.DocumentIndex.Add("price", part.Record.Price)
- Create a custom search service implementing the priorities of your search and fields to search on
Steps - Creating your own search
- Create the parts and records needed for the content type to search.
- Create an index for the search. This can be done in-code using the IIndexManager or using the admin menu (index under settings).
- Add indexing tasks for the fields that need indexing for the part
- Create a service to define how you want the search to act. This can be based on ISearchService or by starting from scratch.
- Create a controller to take in options and serve the new results of the service.
- Ive taken to suppressing the default controller to support different display types for the basic search.
- Create or extend the main index action or specialize an advanced query route to separate the complexity or different search modes.
Points of Interest
AdvancedSearchFormPartDriver - Provides an additional shape for the SearchFormPart. This is to provide the advanced features of the search and to display on the search form widget.
IAdvancedSearchService (AdvancedSearchService) - shows how to search a particular field. There are a few options to begin. Here is a example of searching for products withing a price range 'only'.
- if (advancedSearch.Between.PriceFrom.HasValue &&
- .WithinRange(SearchDefinitions.Price, advancedSearch.Between.PriceFrom.GetValueOrDefault(), double.MaxValue)
AdvancedSearchController - Overrides the default controller for Search as well as provides the views and shapes for the advanced search. Additionally it serves up results by the content type found in the custom settings rather than the default summary, providing a little more flexibility.
Version 1 - 25th June 2013