Ektron Reference


>>Helping Users Navigate Your Web Site > Using Search > Using Ektron’s Search APIs

Using Ektron’s Search APIs

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.

The following webinar is another good resource: http://ektron.com/Resources-And-Tools/Webinars/Screencasts/Ektron-8-5-and-the-Search-Framework-API/

This section also contains the following topics.

Elements of Search Framework API

Element Description Example

Search manager

See Also: Search Manager

Includes search method you use to execute search, based on specified criterion

Use Criteria object to define query text

using Ektron.Framework.Search;

SearchManager manager =
new SearchManager();

Search

See Also:

Keyword Search ,

Advanced Search

Simple

KeywordSearchCriteria criteria = new KeywordSearchCriteria();

criteria.QueryText = "ektron";

Advanced - can create complex queries using expressive syntax

AdvancedSearchCriteria criteria = new AdvancedSearchCriteria();

criteria.ExpressionTree = SearchContentProperty.Title.Contains("ektron");

SearchResponse Data Type

See Also:

To see the list of properties that can be returned, see Properties.

The type of structure returned when a developer executes a search via thesearchManager.Search
(criteria)
method

SearchResponseData response = manager.Search(criteria);

searchResults.DataSource = from r in response.Results

select new

{

Title = r[SearchContentProperty.Title],

Summary = r[SearchContentProperty.HighlightedSummary],

Id = r[SearchContentProperty.Id] * 10

};

searchResults.DataBind();

Search Manager

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.

Keyword Search

Use Keyword Search to run a simple search query.

KeywordSearchCriteria criteria = new KeywordSearchCriteria();

criteria.QueryText = "ektron";

Keyword Search Property: EnableStemming

When stemming is enabled, a search for "run" returns content that contains running, ran, and run, etc.

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.

Advanced Search

Use Advanced Search to return specific results and run complex queries.

AdvancedSearchCriteria criteria = new AdvancedSearchCriteria();

criteria.ExpressionTree = SearchContentProperty.Title.Contains("ektron");

Complex Query

Below is a complex query example that 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.

Operators

You can use the following operators in a complex query.

NOTE: Ektron's Search API does not support NEAR searches.

Properties

A complex query can use the following properties.

ImplicitAnd

If set to true, search terms have an AND relationship. If set to false, search terms have an OR relationship.

criteria.ImplicitAnd = true;

criteria.ImplicitAnd = false;

IncludeSuggestedResults

Set to true to include suggested results along with regular search results. See Also: Suggested Results

criteria.IncludeSuggestedResults = true;

criteria.IncludeSuggestedResults = false;

OrderBy

Sets a return property's order to ascending or descending.

criteria.OrderBy = new List<OrderData>()

{

new OrderData(SearchContentProperty.Id, OrderDirection.Descending)

};

NOTE: You cannot sort the Description and Highlighted Summary properties.

PagingInfo

Sets the number of search results that appear per page.

criteria.PagingInfo.RecordsPerPage = 10;

Permission

Allows you to search as a specific user or administrator.

criteria.Permission = Permission.CreateAdministratorPermission();

criteria.Permission = Permission.CreateCurrentUserPermission();

criteria.Permission = Permission.CreateManualUserPermission(1);

In the last example above, the search is executed using the permissions of the user whose ID is specified in parentheses.

QueryText

The text that is queried.

criteria.QueryText = "Ektron";

ReturnProperties

The properties for each Search Class you want returned with search results.

criteria.ReturnProperties = new HashSet<PropertyExpression>()

{

SearchContentProperty.Title,

SearchContentProperty.Id,

};

The following table lists the properties available in each class.

Scope

Lets you search other scopes in Search Server. Used for Integrated Search. See Also: Using Integrated Search

criteria.Scope = new ScopeExpression("NewScope");

Synonyms

Returns content that contains any word in a synonym set. See Also: Synonym Sets

NOTE: Synonyms are always returned for keyword searches. You cannot turn them off.

Keyword Query

Always uses synonyms

criteria.QueryText = "hockey";

Advanced Query

criteria.ExpressionTree = SearchContentProperty.Title.Contains("hockey", WordForms.Synonyms);

Private Search

Returns private content only. See Also: Making Content Private

criteria.ExpressionTree = SearchContentProperty.Private == true;

criteria.ExpressionTree = SearchContentProperty.Private == false;

Date Search

Search before, after, or between dates to get results.

Before Search

criteria.ExpressionTree = SearchContentProperty.DateCreated < new DateTime(2006, 2, 22);

After Search

criteria.ExpressionTree = SearchContentProperty.DateCreated > new DateTime(2010, 8, 22);

Between Search

criteria.ExpressionTree = SearchContentProperty.DateCreated < new DateTime(2010, 8, 22) & SearchContentProperty.DateCreated > new DateTime(2009, 2, 22);

Inflection Search

An inflection search on "run" returns contains various forms of the word, such as running, ran, and run, etc.

criteria.ExpressionTree = SearchContentProperty.Title.Contains("run", WordForms.Inflections);

Monitoring the Query Issued by the API

If you specify a siteroot/web.config LogLevel of 3 or higher, then open the Windows Event Viewer, Windows Logs > Application on the Ektron server, you can view the exact query issued by the API to the search server.

Framework API vs. Search API

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, etc.)
Criteria Simple criteria using filters. Cannot nest conditions. Complex criteria using expression trees See Also: Advanced Search

Ektron Version 8.5, Doc. Rev. 2.0 (Dec. 2011)
Visit the
Ektron Dev Center at http://dev.ektron.com 1–866–4–EKTRON
Ektron Documentation, © 2011 Ektron, Inc.