How to Fine-tune Backend Relevancy

About

This functionality provides the ability to dynamically select which backends are targeted by the current query.

This is useful if you need to target different backends based on a set of criteria.

For example, if a query targets a set of backends, 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 backends to query.

Limitations

Some SmartHub Features are unsupported by some backends.

For information about limitations to your backend The search engine your SmartHub instance uses to perform queries. SmartHub can be configured to use more than one search engine., see the "Limitations" topic for your backend

Select the Backends to Query (via Scripting Stage)

You achieve this by using a Query Scripting Stage added at the General level (not on each Backend). 

Query.SelectedBackends is a List<string> property which you can modify based on your own criteria.

It contains the Backend names that the current query targets.

Steps to configure:

  1. Open the SmartHub Administration page at http(s)://<web-app-url>/_admin.
  2. Click on "General Settings" section on the left

  3. Under "Query Pipeline Stages" click "Add New Query Stage"
  4. Select "Query Scripting Processor" and give it a name (ex: "Backend Selector")

  5. Inside the Code Editor modify the Query.SelectedBackends property using any List<string> operations.
    Initially, this list contains all the Backend names targeted by the page where the query was triggered. 

Example

  • Assume 3 backends are configured in SmartHub:
    • SharePoint Online
    • NetDocuments
    • RightFind
  • The page query targets all backends using the FederatorBackends:"*" syntax in the query template.
  • You want to remove RightFind backend 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 Backend Name

This functionality gives you the ability to increase (or decrease) the document score (Rank) if the document comes from a specific Backend.

  • 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 Backend).

Query Rank Boosting Property

Query.RankBoostingSpecification is a property which enables you to specify the boost based on the backend name.

It accepts a set of rules called "specifications" which define what backend needs boosting and the boost amounts. 

A boost specification has the following format: PropertyName,PropertyValue,Multiplier,Addition

  • PropertyName
    • The property name which defines the Backend name.
    • Set as "BackendName"
  • PropertyValue
    • The backend name.
    • Example: "SPO"
  • Multiplier
    • 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
    • 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
      Copy
      Query.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");

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.
Copy
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:

Copy
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
Copy
Query.RankBoostingSpecification.BoostSpecs.RemoveAll(x => x.Field == "BackendName" && x.Value == "SPO");