Score Boosting Examples

Note:

When two or more score boosts have been applied to individual search filters, then specify the boost mode. Otherwise, the default boost mode is MIN, which is equivalent to executing the setBoostModeMinimum method.

Example 1 — Specifying a Single Score Boost

In the following example, the score returned by the search engine is boosted by 2 points if there is a match:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "support");
   &fg.BoostFilterScore(0.02);
   &fg.EndMatchAll();
End-If;

Example 2 — Using the Default Score Boost Mode (with MatchAll)

In the following example, the score returned by the search engine is boosted by 2 points when all filters match because the default boost mode of minimum is applied when no boost mode is explicitly defined:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "support");
   &fg.BoostFilterScore(0.02);
   &fg.ContainsWord("QE_STATUS", "open");
   &fg.BoostFilterScore(0.03);
   &fg.EndMatchAll();
End-If;

Example 2 — Using the Default Score Boost Mode (with MatchAny)

Similarly, in the following example, the score returned by the search engine is also boosted by 2 points when both filter matches because the default boost mode of minimum is applied when no boost mode is explicitly defined; however if only one filter matches, then the score is boosted by that match alone:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "support");
   &fg.BoostFilterScore(0.02);
   &fg.ContainsWord("QE_STATUS", "open");
   &fg.BoostFilterScore(0.03);
   &fg.EndMatchAny();
End-If;

Example 3 — Specifying Sum as the Score Boost Mode

In the following example, if there is a match for both filters, then the score would be boosted by 5 points, which is the sum of the score boosts; otherwise, if just one filter is matched, then the score is boosted by that match alone:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "support");
   &fg.BoostFilterScore(0.02);
   &fg.ContainsWord("QE_STATUS", "open");
   &fg.BoostFilterScore(0.03);
   &fg.EndMatchAny();
   &fg.setBoostModeSum();
   Rem &fg.setBoostMode("ADD"); /* Equivalent mode */
End-If;

See setBoostMode method: SearchFilterGenerator class and setBoostModeSum method: SearchFilterGenerator class for more information.

Example 4 — Adding a Filter That Does Not Include a Score Boost

The score returned by the search engine is boosted by 5 points, which is the sum of the score boosts; otherwise, if just one filter is matched, then the score is boosted by that match alone. While this example includes a third filter (city = Sydney), it does not contribute to the score boosting.

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "systems");
   &fg.BoostFilterScore(0.02);
   &fg.ContainsWord("QE_STATUS", "draft");
   &fg.BoostFilterScore(0.03);
   &fg.ContainsWord("CITY", "Sydney");
   &fg.EndMatchAny();
   &fg.setBoostModeSum();
End-If;

Example 5 — Using the BoostCompositeFilterScore Method

While the BoostCompositeFilterScore method provides a boost of 2 points for the inner block of filters (match any), the entire score boost would be 6 points if all filters match:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("DEPTNAME", "Support");
   &fg.BoostFilterScore(0.02);
   Local date &date = Date("2009/05/07");
   &fg.AfterDateValue("OPEN_DT", &date);
   &fg.BoostFilterScore(0.02);
   &fg.ContainsWord("QE_YEAR_H", "2009");
   If &fg.MatchAnyReturnTrue() Then
      &fg.ContainsWord("QE_YEAR_H", "07");
      &fg.ContainsWord("QE_STATUS", "Draft");
      &fg.BoostCompositeFilterScore(0.02);
      &fg.EndMatchAny();
   End-If;
   &fg.EndMatchAll();
   &fg.setBoostModeSum();
End-If;

See BoostCompositeFilterScore method: SearchFilterGenerator class for more information.

Example 7 — Using the ContainsPhrase Method

In the following example, the score returned by the search engine is boosted by 2 points when the phrase is matched exactly:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsPhrase("MESSAGE_TEXT", "some long days");
   &fg.BoostFilterScore(0.02);
   &fg.EndMatchAny();
End-If;

See ContainsPhrase method: SearchFilterGenerator class for more information.

Example 8 — Performing a Search Using Wildcard Characters

Use the * wildcard to search and match on one or more characters; use the ? wildcard to search and match on a single character.

In the following example, the score returned by the search engine is boosted by 1 point when all filters match because the default boost mode of minimum is applied when no boost mode is explicitly defined:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("MESSAGE_TEXT", "l*g");
   &fg.BoostFilterScore(0.01);
   &fg.ContainsWord("MESSAGE_TEXT", "b??ght");
   &fg.BoostFilterScore(0.02);
   &fg.EndMatchAll();
End-If;

Example 9 — Performing Stemming in a Search

Use the $ character to indicate that stemming is to be performed.

In the following example, the score returned by the search engine is boosted by 3 points if there is a match:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("MESSAGE_TEXT", "$wanted");
   &fg.BoostFilterScore(0.03);
   &fg.EndMatchAll();
End-If;

Example 10 — Performing a Phonetic Search

Use the ! character to indicate that a phonetic search is to be performed.

In the following example, the score returned by the search engine is boosted by 3 points if there is a match:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAllReturnTrue() Then
   &fg.ContainsWord("MESSAGE_TEXT", "!smithee");
   &fg.BoostFilterScore(0.03);
   &fg.EndMatchAll();
End-If;

Example 11 — Performing a Fuzzy Search

Use the ~ character to indicate that a fuzzy search is to be performed.

In the following example, the score returned by the search engine is boosted by 2 points if there is a match:

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsWord("MESSAGE_TEXT", "speeks~");
   &fg.BoostFilterScore(0.02);
   &fg.EndMatchAny();
End-If;

Example 12 — Specifying Custom Scoring with a Keyword-Like Search

Typically, a keyword-like search (similar to a keyword search performed on the Global Search field in the browser) would be constructed programmatically by using the QueryText property of the SearchQuery class. To specify custom scoring for a keyword-like search, you would use either the ContainsWord or ContainsPhrase methods without specifying the search field name value (that is, it is an empty string indicating that the search is against all search fields) as show in the following example.

import PT_SEARCH:SearchFilterGenerator;

Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();

If &fg.MatchAnyReturnTrue() Then
   &fg.ContainsWord("", "long");
   &fg.BoostFilterScore(0.02);
   &fg.EndMatchAny();
End-If;

See QueryText property: SearchQuery class for more information for the typical approach to performing a keyword-like search.