 | 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 |
---|
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 type | Supported since version | SphinxConnector.NET Type | Can be filtered | Can be range filtered | Updateable | Overridable |
---|
uint | 0.9.8 | SphinxInteger | Yes, since 0.9.8 | Yes, since 0.9.8 | Yes, since 0.9.8 | Yes, since 0.9.9 |
float | 0.9.8 | SphinxFloat | No | Yes, since 0.9.8 | Yes, since 0.9.8 | Yes, since 0.9.9 |
bigint | 0.9.9 | SphinxBigInt | Yes, since 0.9.8 | Yes, since 0.9.8 | No | Yes, since 0.9.9 |
bool | 0.9.8 | SphinxBoolean | Yes, since 0.9.8 | No | Yes, since 0.9.8 | Yes, since 0.9.9 |
timestamp | 0.9.8 | SphinxTimestamp | Yes, since 0.9.8 | Yes, since 0.9.8 | Yes, since 0.9.8 | Yes, since 0.9.9 |
str2ordinal | 0.9.8 | SphinxOrdinal | No | No | No | No |
(JSON) string | 2.1.1 | SphinxString | Yes, since 2.2.1 | No | No | No |
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 |
---|
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 |
---|
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!
|