Skip to main content
Logo
There is a newer version of Contensis. Click to find out more and download the latest version.

Create a search

This article shows you how you can create a search within Contensis and integrate it into your live website. 

Create a search results page

In order for a search to display results we need to create a web page and add a search results control.

  1. Right click in the editor of your page or template to bring up the context menu.
  2. Select Insert webcontrol and underneath Search select Search Results. A window will pop up giving you some options, like to give the control a specific ID.
  3. Click Finish and the search query control will be included in the editor.

Set the control properties

The properties for the control are set initially when inserting the control into the page, but can be amended at any later date by simply right clicking on the control to display the Web control Editor window.

Enable inflections

A True/False option for allowing variations of the word(s) entered to be searched also. This includes plurals and past or future tenses.

Search columns (edit weights)

This controls the order in which items will be returned from the search. The greater the weighting of a data field the more effect it has on the ranking of a search result if the keyword is found in that field. By default the data fields Property_Title  &  SC_Content are set-up to be searched but this can be changed, this is covered in more detail in how to configure and manage full-text search indexing. It is common practice to give the title and keywords associated with content a large weighting, followed by description and lastly the content. i.e. Title = 100, keywords =100, description = 50 and content = 10.

Provider

Sets whether the search will be Standard Search or Enterprise Search.

Where clause

Allows for an additional SQL (Structured Query Language) statement to be added to the control. for example if you only wanted to return pages from within a publications folder at root you could enter  Property_FullPath like '/publications/%'

Alternatively you could prevent content being returned from a specific folder by its folder by entering its folder id using Property_F_ID not in (411).

 

Enable dictionary

A True/False option to specify if you want the search to recommend alternative search phrases for misspelt keywords.

Enable thesaurus

A True/False option to specify if you want the search to recommend alternative search phrases which have similar meanings to the keywords which have been entered.

Enable permissions

A checkbox option to specify if permissions should be taken into account in the search results. Even if you don't tick this option when a user clicks on the search result they would get an access denied message. This option basically removes the result from the results page, this is recommended if you are using Contensis security.

Extended search results

The extended search results control is very similar to the standard search results control except that it allows for end users to add more than one search query, think of it as an advanced search.

  1. Right click in the editor of your page or template to bring up the context menu.
  2. Select  Insert webcontrol  and underneath  Search  select the  Search Results Extended. A window will pop up giving you some options, like to give the control a specific ID.
  3. Click  Finish and the search query control will be included in the editor.

Create a search form

Now you have created your search results page you can add a search textbox to your site. This is the textbox where visitors to the site will enter their keywords, typically this is usually in a common sub template such as the header template.

  1. Right click in the editor of your page or template to bring up the context menu.
  2. Select Insert webcontrol and underneath Search select the Search Query Control. A window will pop up giving you some options, like to give the control a specific ID.
  3. Click Finish and the search query control will be included in the editor.

Set the control properties

Results Web Page

The Search Query Control must have an assigned search results page containing either a Search Results or Search Results Extended web control.

ID

Each control must be named (by default the name will appear as SearchQueryControl.

Web API search

You can create very specific searches using the Contensis WebAPI in your applications.

Create a Razor view

With all of the examples below you need to create a Razor view, insert the code into the view and then drag the Razor view into a template or page.

A simple query

To do a simple query follow the code below.

Query methods

All query methods shown below are case sensitive.

  • Contains(string)
  • DoesNotContain(string)
  • EndsWith(string)
  • IsBetween(string1, string2)
  • IsEqualTo(string)
  • IsGreaterThan(string)
  • IsGreaterThanOrEqualTo(string)
  • IsLessThan(string)
  • IsLessThanOrEqualTo(string)
  • IsNotBetween(string1, string2)
  • IsNotEqualTo(string)
  • StartsWith(string)

Query method members

  • Where(fieldname)
  • WhereCustom(string)
  • WhereFullTextContains(keywordsString)

Query Chaining

Is it also possible to chain more than one query to form a bigger chain by using the following methods.

AND

Here is a basic AND condition chained query.

OR

Here is a basic OR condition chained query.

Sub queries

For a select few, you will need to carry out sub queries on your queries. This can be done in the following manor. The example below uses the .OrSubQuery method but you also have another method .AndSubQuery available to you to use.

Order results

You can order your results by ascending or descending order depending upon your needs by using the .Ascending and .Descending modifier methods on the end of any query you write.

Further steps

The WebAPI Search namespace is fairly large and without making this page too long you can see all the other features of it by looking at the developer section.

Common errors

If you don't get any search results when you should, there are usually two main causes for this. Either you haven't set up your full-text catalog yet, or you are searching on a column which isn't included in your full-text catalog. See How to configure and manage full-text search indexing