Optimizely Content Management System (CMS) recommends Optimizely Search & Navigation which is a cloud-ready extension that lets you build advanced customized search features based on your content model.
For non-cloud environments, you can programmatically search for CMS pages based on a certain **page type using** built-in functionality. By specifying search criteria and a place to start the search you gets a `PageDataCollection
` containing matching pages.
The `DataFactory
` contains a method called `FindPagesWithCriteria
` which takes a `PageReference
` (representing where to start the search) and a `PropertyCriteriaCollection
` object (representing what to search for). When the `FindPagesWithCriteria
` method is called it returns a `PageDataCollection
` object containing matching pages.
### Create a criteria collection
Create a `
PropertyCriteriaCollection
` object that contains the individual `PropertyCriteria
` objects:Create a `
PropertyCriteria
` object that contains the information about the property criteria for the search:
### Create search criteria
Define the search criteria by creating a `PropertyCriteria
` object that contains the information about the property criteria for the search:
Set the `
Condition
` property to specify the type of comparison you want; for example, `CompareCondition.Equal
`.Set the `
Name
` property to the `PageTypeID
` property.Set the `
Type
` property to the `PageType
` property.Set the `
Value
` property to specify what page type to search for; (the load of a page type is based on its name); for example, `PageTypeNewsItem
`.Set the `
Required
` property to **true**. This criterion is required for a match.
### Create additional search criteria
Define another search criterion by creating a `PropertyCriteria
` object that contains the information about the property criteria for the search:
Set the `
Condition
` property to specify the type of comparison you want; for example, `CompareCondition.GreaterThan
`.Set the `
Name
` property to the `PageCreated
` property.Set the `
Type
` property to the `Date
` property.Set the `
Value
` property to specify a period of time; for example, set to search for pages that are created during the last 120 days.Set the `
Required
` property to **true**, this criterion is required for a match.
### Add your criteria to the criteria collection
Add your specified criteria to the criteria collection as follows:
### Execute the search
After you specify criteria, define where to start the search. Use the start page as the search starting point.
Note
The following example may return many matches (and in some cases could be time-consuming).
### FilterForVisitor
Filter for visitors. The following filter removes pages that the current user does not have access to or that are not currently published:
You can find the source code for the `PageDataCollection
` and `PageData
` classes the `Framework Reference
` section under the **Remarks** section for the class.