| SphinxSearchOptionsSetOverrideTOverridable Method |
Sets the override values for an attribute. If values for the attribute have previously
been set, they will be overwritten.
Namespace:
SphinxConnector.NativeApi
Assembly:
SphinxConnector (in SphinxConnector.dll) Version: 5.4.1
Syntax public void SetOverride<TOverridable>(
SphinxAttributeOverride<TOverridable> attributeOverride
)
where TOverridable : IOverridableType
Public Sub SetOverride(Of TOverridable As IOverridableType) (
attributeOverride As SphinxAttributeOverride(Of TOverridable)
)
Parameters
- attributeOverride
- Type: SphinxConnector.NativeApiSphinxAttributeOverrideTOverridable
The values dictionary.
Type Parameters
- TOverridable
- The type of the attribute for which override values are set.
Exceptions Examples
This example is based on the
Sakila sample index from the introduction.
The attributes include a field 'recommended_by_friends' which is set to false as default.
We will use the SetOverrides() method to dynamically overwrite this value for a query.
We then use this attribute in a sort by expression, so that films which have been recommended by friends of
the user doing the search, will appear at the top of the list.
SphinxAttributeOverride<SphinxBoolean> attributeOverride = new SphinxAttributeOverride<SphinxBoolean>("recommended_by_friends");
attributeOverride.AddOverrideValue(743, true);
SphinxClient sphinxClient = new SphinxClient();
sphinxClient.SearchOptions.SetOverride(attributeOverride);
sphinxClient.SearchOptions.SortMode = SphinxSortMode.Expression;
sphinxClient.SearchOptions.SortBy = "@weight + (recommended_by_friends * 1000)";
SphinxSearchResult searchResult = sphinxClient.Query("room", "sakila");
foreach (SphinxMatch sphinxMatch in searchResult.Matches)
{
Console.WriteLine(sphinxMatch);
}
See Also