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. 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/

Elements of Search Framework API

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

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

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, 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.

Advanced 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

Complex Query

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.

Operators

Operators

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;

Properties

Properties

A complex query can use the following properties.

ImplicitAnd

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

IncludeSuggestedResults

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

criteria.IncludeSuggestedResults = true;
       criteria.IncludeSuggestedResults = false;
OrderBy

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

PagingInfo

Sets the number of search results that appear per page.

criteria.PagingInfo.RecordsPerPage = 10;
Permission

Permission

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.

QueryText

QueryText

The text that is queried.

criteria.QueryText = "Ektron";
ReturnProperties

ReturnProperties

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

criteria.ReturnProperties = new HashSet<PropertyExpression>()
    {
     SearchContentProperty.Title,
     SearchContentProperty.Id,
     };
—Properties—

SearchContentProperty

  • AssetVersion
  • Author
  • ContentSubType
  • ContentType
  • DateCreated
  • DateModified
  • Description
  • ExpiryDate
  • ExpiryType
  • FolderId
  • FolderIdPath
  • FolderName
  • FolderPath
  • GoLiveDate
  • HighlightedSummary

    NOTE: You cannot use HighlightedSummary as a search criterion, but you can display it in search results.

  • Id
  • Language
  • MapAddress
  • MapDate
  • MapLatitude
  • Map Longitude
  • Path
  • Private
  • QuickLink
  • Rank
  • Size
  • Tags
  • TaxonomyCategory
  • Title
  • XMLConfigId

Search eCommerce Property

  • Buyable
  • CatalogNumber
  • CurrencyId
  • Description
  • Height
  • HighlightedSummary

    NOTE: You cannot use HighlightedSummary as a search criterion, but you can display it in search results.

  • Id
  • ImageUrl
  • Language
  • Length
  • ListPrice
  • PathCategory
  • ProductType
  • ProductTypeId
  • Purchased
  • QuickLink
  • Rank
  • SalePrice
  • Size
  • SkuNumber
  • Title
  • Weight
  • Width

SearchUserProperty

  • Avatar
  • DateModified
  • DisplayName
  • EmailAddress
  • FirstName
  • HighlightedSummary

    NOTE: You cannot use HighlightedSummary as a search criterion, but you can display it in search results.

  • Id
  • Language
  • LastName
  • MapAddress
  • MapLatitude
  • MapLongitude
  • Membership
  • Path
  • PrivateProfile
  • QuickLink
  • Rank
  • Size
  • Tags
  • TaxonomyCategory
  • Type
  • UserFriends
  • UserName

SearchGroupProperty

  • Avatar
  • CreatorId
  • DateModified
  • EmailAddress
  • Enroll
  • HighlightedSummary

    NOTE: You cannot use HighlightedSummary as a search criterion, but you can display it in search results.

  • Id
  • Location
  • LongDescription
  • Name
  • Path
  • QuickLink
  • Rank
  • ShortDescription
  • Size
  • Tags
  • TaxonomyCategory
  • Title
  • Type

SearchMetadataProperty

  • GetBooleanProperty
  • GetDateProperty
  • GetDecimalProperty
  • GetIntegerProperty
  • GetStringProperty

SearchSmartFormProperty

  • GetBooleanProperty
  • GetDateProperty
  • GetDecimalProperty
  • GetIntegerProperty
  • GetStringProperty
Scope

Scope

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

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

Synonyms

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.

Keyword Query

Keyword Query

Always uses synonyms

criteria.QueryText = "hockey";
Advanced Query

Advanced Query

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

Private Search

Returns private content only. See Also: Making Content Private

criteria.ExpressionTree = SearchContentProperty.Private == true;
criteria.ExpressionTree = SearchContentProperty.Private == false;
Date search

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

Inflection Search

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

criteria.ExpressionTree = SearchContentProperty.Title.Contains("run", WordForms.Inflections);
Monitoring the query issued by the API

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

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