How to Fine-tune Search Engine Relevancy
About
This functionality provides the ability to dynamically select which search engines are targeted by the current query.
-
This is useful if you need to target different search engines based on a set of criteria.
-
For example, if a query targets a set of search engines, but you need to change this set because the current user does not have access to the set targeted by the query.
-
The identity of the current user is just one possible criteria that can be used to decide which search engines to query.
Limitations
-
Some SmartHub Features are unsupported by some search engines.
-
For information about limitations to your search engine, see the "Limitations" topic for your search engine
Select the Search Engines to Query (via Scripting Stage)
You achieve this by using a Query Scripting Tuning stage added at the General level (not on each search engine).
-
Query.SelectedBackends is a List<string> property which you can modify based on your own criteria.
It contains the search engine names that the current query targets.
Steps to configure:
- Open the SmartHub Administration page at http(s)://<web-app-url>/_admin.
- Click the General Settings link on the left side navigation.
- Under USER EXPERIENCE TUNING click ADD QUERY TUNING
- Select Query Scripting Processor and give it a name (ex: "search engine Selector")
- Inside the Code Editor modify the Query.SelectedBackends property using any List<string> operations.
Initially, this list contains all the search engine names targeted by the page where the query was triggered.
Example
- Assume 3 search engines are configured in SmartHub:
- SharePoint Online
- NetDocuments
- RightFind
- The page query targets all search engines using the FederatorBackends:"*" syntax in the query template.
-
You want to remove RightFind search engine if the current user is from "Department=X."
You would achieve this by:Copy//code to detect if the user is from Department X goes here and initializes bool userIsFromDepartmentX
if (userIsFromDepartmentX) {
Query.SelectedBackends.Remove("RightFind"); // the initial SelectedBackends list contains the items SPO, NetDocs, RightFind
}
Boost the Document Score Dynamically Based on the Search Engine Name
This functionality gives you the ability to increase (or decrease) the document score (Rank) if the document comes from a specific search engine.
-
This enables you to change the position of the document in the final result set.
You achieve this by using a Query Scripting Stage added at the General level (not on each search engine).
Query Rank Boosting Property
-
Query.RankBoostingSpecification is a property that enables you to specify the boost based on the search engine name.
-
It accepts a set of rules called "specifications" which define what search engine needs boosting and the boost amounts.
Syntax and Parameters
A boost specification has the following format: PropertyName,PropertyValue,Multiplier,Addition
- PropertyName: This is the property name which defines the search engine name. Set this value as <Search Engine Name>
- PropertyValue: This is the search engine name. For example: "SPO".
- Multiplier; This is a float number which shows the value that is multiplied with the original score. If the multiplier=1 the score is not changed.
- A value greater than 1 increases the score.
- A value lower than 1 decreases the score.
- Addition: This is a float number which shows the value that is added to the original score.
- If addition=0 the score will not be changed.
- A value greater than 0 increases the score.
- A value lower than 0 decreases the score.
Basic Operations
Query.RankBoostingSpecification supports the following basic operations:
- Initialization
- Initializes the property by using an object constructor.
- Notice that multiple specs are separated by the ";" character.
Example:CopyQuery.RankBoostingSpecification = new RankBoostingSpecification("BackendName,SPO,2,10;BackendName,RightFind,0.1,0");
- Add a new boost specification
- Add a new condition for boosting based on backend name.
- You don't need to call the constructor first.
Example- Query.RankBoostingSpecification.Add("BackendName,NetDocs,2,-10");
- Remove a boost specification
- Remove a previously added boost specification.
Example:- Query.RankBoostingSpecification.Remove("BackendName,NetDocs,2,-10");
- Remove a previously added boost specification.
Example for Basic Usage
- Assume you are increasing the SharePoint Online backend scores by doubling them and subtracting 10.
- A document with an initial score of 50 would end up with a score of 90.
Query.RankBoostingSpecification.Add("BackendName,SPO,2,-10");
For more advanced usage scenarios you can use the underlying strongly typed object model.
RankBoostingSpecification.BoostSpecs property is a List<FieldBoostSpecification> which holds an item for each boost specification.
FieldBoostSpecification class has the following properties:
- public string Field;
- public string Value;
- public double BoostMultiplier;
- public double BoostAddition;
FieldBoostSpecification has a constructor which accepts a boost specification in a string format and deserializes it for you.
Example:
new FieldBoostSpecification("BackendName,SPO,2,10");
Example for Advanced Usage
- Assume you have a previous stage which affects the score for the SPO backend but you don't know the exact multiplier or addition which were used.
- You want to remove only those specific boost specifications
Query.RankBoostingSpecification.BoostSpecs.RemoveAll(x => x.Field == "BackendName" && x.Value == "SPO");