This section presents an overview of Ektron's Search API. For a more detailed documentation of the Search API and all other APIs, install Ektron's OnTrek sample site and click Developer Reference. You can also access this reference online via http://reference.ektron.com/developer/.
The following webinar is another good resource: http://ektron.com/Resources-And-Tools/Webinars/Screencasts/Ektron-8-5-and-the-Search-Framework-API/
Element | Description | Example |
---|---|---|
Search manager See Also: Search Manager |
|
|
Search See Also: |
|
|
|
|
|
SearchResponse Data Type See Also: To see the list of properties that can be returned, see Properties. |
|
s s {
s |
Use to specify an access mode, which defines permissions of the user performing the search.
using Ektron.Cms.Framework.Search; SearchManager manager=new SearchManager SearchManager manager=new SearchManager(ApiAccessMode.Admin); SearchManager manager=new SearchManager(ApiAccessMode.LoggedInUser);
If the user is an admin (see line 5 above), all search results are returned.
If the user is a logged in user (see line 6 above), only search results available to the currently logged in user are returned.
Use Keyword Search to run a simple search query.
KeywordSearchCriteria criteria = new KeywordSearchCriteria(); criteria.QueryText = "ektron";
When stemming is enabled, a search for "run" returns content that contains running, ran, and run, and so on.
criteria.EnableStemming = true; criteria.EnableStemming = false;
You cannot combine an exact phrase search with stemming. For example, the search term "run" does not return content that includes ran
. However, with stemming enabled, the term run
does return content that includes ran
.
NOTE: To use stemming with an Advanced Search, use Inflection Search.
Use Advanced Search to return specific results and run complex queries.
AdvancedSearchCriteria criteria = new AdvancedSearchCriteria(); criteria.ExpressionTree = SearchContentProperty.Title.Contains("ektron");
The following complex query example uses the advanced search class.
criteria.ExpressionTree = SearchContentProperty.Title.Contains("Animal") & !(SearchContentProperty.Title.Contains("dog") | SearchContentProperty.Title.Contains("cat"));
A complex query can use several Operators and Properties.
You can use the following operators in a complex query.
NOTE: Ektron's Search API does not support NEAR searches.
Type | Example |
---|---|
AND search words | criteria.ExpressionTree = new KeywordExpression("ektron") & new KeywordExpression("cms"); |
OR search words | criteria.ExpressionTree = new KeywordExpression("ektron") | new KeywordExpression("cms"); |
ANDNOT search words | criteria.ExpressionTree = new KeywordExpression("ektron") &! new KeywordExpression("cms"); |
GreaterThan or > |
criteria.ExpressionTree = SearchContentProperty.Id.GreaterThan(10); criteria.ExpressionTree = SearchContentProperty.Id > 10; |
GreaterThanOrEqualTo or >= |
criteria.ExpressionTree = SearchContentProperty.Id.GreaterThanOrEqualTo(10); criteria.ExpressionTree = SearchContentProperty.Id >= 10; |
LessThan or < |
criteria.ExpressionTree = SearchContentProperty.Id.LessThan(10); criteria.ExpressionTree = SearchContentProperty.Id < 10; |
LessThanOrEqualTo or <= |
criteria.ExpressionTree = SearchContentProperty.Id.LessThanOrEqualTo(10); criteria.ExpressionTree = SearchContentProperty.Id <= 10; |
Equal or = |
criteria.ExpressionTree = SearchContentProperty.Id.EqualTo(10); criteria.ExpressionTree = SearchContentProperty.Id == 10; |
NotEqualTo or != |
criteria.ExpressionTree = SearchContentProperty.Id.NotEqualTo(10); criteria.ExpressionTree = SearchContentProperty.Id != 10; |
A complex query can use the following properties.
Set to true to include suggested results along with regular search results. See Also: Suggested Results
criteria.IncludeSuggestedResults = true; criteria.IncludeSuggestedResults = false;
Lets you search as a specific user or administrator.
criteria.Permission = Permission.CreateAdministratorPermission(); criteria.Permission = Permission.CreateCurrentUserPermission(); criteria.Permission = Permission.CreateManualUserPermission(1);
In the previous example, the search is executed using the permissions of the user whose ID is specified in parentheses.
The properties for each Search Class you want returned with search results.
criteria.ReturnProperties = new HashSet<PropertyExpression>() { SearchContentProperty.Title, SearchContentProperty.Id, };
SearchContentProperty
NOTE: You cannot use HighlightedSummary
as a search criterion, but you can display it in search results.
Search eCommerce Property
NOTE: You cannot use HighlightedSummary
as a search criterion, but you can display it in search results.
SearchUserProperty
NOTE: You cannot use HighlightedSummary
as a search criterion, but you can display it in search results.
SearchGroupProperty
NOTE: You cannot use HighlightedSummary
as a search criterion, but you can display it in search results.
SearchMetadataProperty
SearchSmartFormProperty
Lets you search other scopes in Search Server. Used for Integrated Search. See Also: Setting Up Integrated Search
criteria.Scope = new ScopeExpression("NewScope");
Returns content that contains any word in a synonym set. See Also: Using Synonym Sets
NOTE: Synonyms are always returned for keyword searches. You cannot turn them off.
Returns private content only. See Also: Making Content Private
criteria.ExpressionTree = SearchContentProperty.Private == true; criteria.ExpressionTree = SearchContentProperty.Private == false;
Search before, after, or between dates to get results.
criteria.ExpressionTree = SearchContentProperty.DateCreated < new DateTime(2006, 2, 22);
criteria.ExpressionTree = SearchContentProperty.DateCreated > new DateTime(2010, 8, 22);
criteria.ExpressionTree = SearchContentProperty.DateCreated < new DateTime(2010, 8, 22) & SearchContentProperty.DateCreated > new DateTime(2009, 2, 22);
You can use either the Framework API or the Search API to retrieve and display search results. The following table contrasts criteria for using both APIs.
Criterion | Content manager of Framework API | Search API |
---|---|---|
Available properties of returned content |
A list of strongly- typed content data objects. They provide access to every property of the ContentData object. |
You specify properties of the SearchResult object to be returned. |
Immediacy | Queries directly against the database, so is immediately available | Search indexes are not updated immediately. So, content added or changed since last crawl is not available. |
Can query against | ContentData properties only | Properties that span types (taxonomy, metadata, content tags, and so on.) |
Criteria | Simple criteria using filters. Cannot nest conditions. | Complex criteria using expression trees See Also: Advanced Search |