Sets the override values for an attribute. If values for the attribute have previously
been set, they will be overwritten.
Namespace: Gronewold.SphinxConnectorAssembly: Gronewold.SphinxConnector (in Gronewold.SphinxConnector.dll) Version: 2.7.0.3011 (2.7.0.3011)
Syntax
| C# |
|---|
public void SetOverride<TOverridable>( SphinxAttributeOverride<TOverridable> attributeOverride ) where TOverridable : IOverridableType |
| Visual Basic |
|---|
Public Sub SetOverride(Of TOverridable As IOverridableType) ( _ attributeOverride As SphinxAttributeOverride(Of TOverridable) _ ) |
Parameters
- attributeOverride
- Type: Gronewold.SphinxConnector..::..SphinxAttributeOverride<(Of <(<'TOverridable>)>)>
The values dictionary.
Type Parameters
- TOverridable
- The type of the attribute for which override values are set.
Examples
This example is based on the Sakila sample index in the Samples folder.
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.
CopyC#
SphinxAttributeOverride<SphinxBoolean> attributeOverride = new SphinxAttributeOverride<SphinxBoolean>("recommended_by_friends"); attributeOverride.AddOverrideValue(743, true); //Normally this value would be retrieved from somewhere else 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); }
Exceptions
| Exception | Condition |
|---|---|
| System..::..ArgumentException | attributeOverride does not contain any elements. |
| System..::..ArgumentNullException | attributeOverride is null. |
| System..::..NotSupportedException | Version is less than 0.9.9. |