Click or drag to resize

Handling of Sphinx types

SphinxConnector.NET's native API contains objects for every attribute type provided by Sphinx search engine. They are used as type parameters for methods like e.g. SetOverrideTOverridable(SphinxAttributeOverrideTOverridable) or SetFilter. This gives you strongly typed access to these methods and also enables the compiler to check whether the operation is valid for a given type.

The following example demonstrates the use of SphinxFloat as a type parameter to the SetFilterRangeTRangeFilterable method.

Setting a range filter for an attribute of type float
SphinxClient sphinxClient = new SphinxClient();
sphinxClient.SearchOptions.SetFilterRange<SphinxFloat>("rental_rate", 0, 0.99f);
Tip Tip

See in the above example that it is not necessary to instantiate an instance of the SphinxFloat type. All types can be implicitly converted to/from underlying .NET types.

Type Matrix

The table shows how each Sphinx type maps to a SphinxConnector.NET object and which operations can be applied to them.

Sphinx typeSupported since versionSphinxConnector.NET TypeCan be filteredCan be range filteredUpdateableOverridable
uint0.9.8SphinxIntegerYes, since 0.9.8Yes, since 0.9.8Yes, since 0.9.8Yes, since 0.9.9
float0.9.8SphinxFloatNoYes, since 0.9.8Yes, since 0.9.8Yes, since 0.9.9
bigint0.9.9SphinxBigIntYes, since 0.9.8Yes, since 0.9.8NoYes, since 0.9.9
bool0.9.8SphinxBooleanYes, since 0.9.8NoYes, since 0.9.8Yes, since 0.9.9
timestamp0.9.8SphinxTimestampYes, since 0.9.8Yes, since 0.9.8Yes, since 0.9.8Yes, since 0.9.9
str2ordinal0.9.8SphinxOrdinalNoNoNoNo
(JSON) string2.1.1SphinxStringYes, since 2.2.1NoNoNo
Note Note
As you can see from the type matrix above, Sphinx supports attributes of type unsigned int. An instance of SphinxInteger can be cast or instantiated from the .NET type uint, which is supported in both C# and VB.NET, but is not CLS-compliant. So it might not be available in all languages supported by .NET. To make SphinxInteger usable from .NET languages without support for unsigned integers, longs can also be cast this type. But in that case you need to be aware that the long value may not be negative or greater than 2^32. Otherwise an SphinxConversionException will be thrown.
Note Note
The attribute type timestamp is a Unix timestamp, which means that not all values which are valid for a .NET SystemDateTime are valid for this type. Valid values range from 1901-12-13 to 2038-01-19. Trying to cast a .NET DateTime which is not in this range to a SphinxTimestamp will cause a SphinxConversionException to be thrown.
Note Note
The attribute type string can currently be used to filter JSON string attributes only. Sphinx does not support filtering on 'regular' string attributes (e.g. sql_attr_string) at the moment!