SearchCondition extraConditions parameter syntax

Moiz Mala asked on June 6, 2023 09:06

With reference to the post: https://devnet.kentico.com/questions/kentico-12-mvc-smart-search-api-with-multiple-indexes

The syntax created in ExtraCondition as parameter we use, can anyone explain how these syntax defined: like example ^3, ^0.2, ^0.3 as mentioned in the above post for extraConditions as

string extraConditions = " (documentname:" + q + ")^2 (classname:institute)^0.3 (classname:service)^0.1";

Please advise.

Recent Answers


Brenden Kehren answered on June 6, 2023 18:46

The conditions are increasing the score based on class names and document names. This is done to give one page type a higher score (sort order) in the ranking so they show first or at the top of the list.

(documentname:" + q + ")^2
This is scoring the page very high if the page name equals the search term.

(classname:institute)^0.3
If the classname (page type) equals "institute" then add an additional score of 0.3.

(classname:service)^0.1
If the classname (page type) equals "service" then add an additional score of 0.1.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on June 7, 2023 06:48 (last edited on June 7, 2023 06:53)

this is an old article on boosting search results but the logic/idea is still the same in Lucene.NET search engine. You can also refer to the Lucene query syntax docs.
But at the same time I would suggest to think about whether you are really searching or filtering. The front end for the visitor might look the same, but the difference is how it works in the background. I have seen many times (mis)using search for filtering and it usually ended up with crazy search conditions and disappointment. So, what is the difference?
Filtering takes an existing full list, and removes items based on criteria that match/don't match. Search takes a blank slate and adds to it based on criteria that match/don't match - so there is still some uncertainty.

Under filtering you can imagine e.g. getting set of pages using DocumentQuery and the filter the results using WHERE condition. For example, you have an e-shop and the visitor is searching for green shoes but this is not real search because you have the colors specified in some field - so it is better, faster and more reliable to do filtering and not searching.

0 votesVote for this answer Mark as a Correct answer

Moiz Mala answered on June 7, 2023 09:10

Thanks @Brenden and @Juraj for your responses.

I am basically looking for filtering records based on the condition provided.

In extraConditions as parameter of method SearchCondition, I wanted to add DocumentIsArchived column value, in order to check if the document results only published documents.

Do we have better way to handle ?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on June 8, 2023 06:38

The smart search should return published pages only by default. What is your search index setup and search code in the front end app? This does not sound right and looks like there is something wrong, maybe some DB inconsistency.
This SQL query returns published pages only:

SELECT * FROM [View_CMS_Tree_Joined] WHERE ([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= GETDATE()) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= GETDATE()))

If it returns also the "archived" pages, then there is something wrong with the page data and you should review them as well as the workflow setup.

0 votesVote for this answer Mark as a Correct answer

Abdullah Alowais answered on June 12, 2023 05:59

With the same context for search, with the help of SearchParameters we can set the Path. However, it only accepts single path, if i need to allow multiple path and exclude path, how can can I achieve by API?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 12, 2023 06:14

Abdullah you should set the path to the root of the site, then filter by the included paths in your filter clause. For example, where nodealiaspath like '/path-1/%' or nodealiaspath like '/path-2/%'

0 votesVote for this answer Mark as a Correct answer

Abdullah Alowais answered on June 12, 2023 06:26

ok, Could you please let me give example to add filter clause? to the SearchParameters

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.