SphinxConnector.NET 3.8 has been released

by Dennis 14. November 2013 11:49

The long awaited beta of Sphinx 2.2.1 has just been released, and we're following suit with releasing version 3.8 of SphinxConnector.NET! It is available for download and via NuGet!

SphinxConnector.NET 3.8 contains a bulk of changes to support new features that have been introduced with Sphinx 2.2.1: the support for JSON attributes has been greatly expanded with the newest Sphinx release. New functions like IN, ALL, ANY, and INDEXOF have been added to JSON arrays. These functions are supported through their .NET equivalents via IEnumerable, IList, and SphinxConnector.NET’s In() extension method, e.g.:

using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
    var results = fulltextSession.Query<Product>().
                                  Select(p => new
                                  {
                                      Any = p.JsonTestEntity.Categories.Any(x => x > 2),
                                      All = p.JsonTestEntity.Categories.All(x => x < 5),
                                      IndexOf = p.JsonTestEntity.Categories.IndexOf(1),
                                      In = p.JsonTestEntity.Categories.In(1, 2, 3)
                                  }).
                                  Where(x => x.In).
                                  ToList();
}

Please note that the syntax for IN is a little different for JSON attributes than for MVAs: IN can only be used within SELECT and than be used as a filter in WHERE, instead of using it directly in the WHERE clause.

Other newly supported functions include LEAST, GREATEST, and LENGTH which work with both JSON arrays and MVAs via Min(), Max() and IEnumerable.Count(), ICollection.Count or Length:

using (IFulltextSession fulltextSession = fulltextStore.StartSession())
            {
                var results = fulltextSession.Query<JsonTestObject>().
                                              Select(p => new
                                              {
                                                  Min = p.JsonTestEntity.Categories.Min(),
                                                  Max = p.JsonTestEntity.Categories.Max(),
                                                  Count = p.JsonTestEntity.Categories.Count,
                                              }).
                                              ToList();
            }

Note that LENGTH() has been available since the release of Sphinx 2.1.2.

Another new feature of Sphinx 2.2.1 is the HAVING clause, which is now also supported by the fluent API:

using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
    var results = fulltextSession.Query<Product>().
                                  Match("a product").
                                  GroupBy(p => p.VendorId).
                                  Select(p => new
                                  {
                                      p,
                                      Count = Projection.Count()
                                  }).
                                  Having(p => p.Count > 1).
                                  ToList();
}

The next feature has been supported by Sphinx for some time and can now be used from the fluent API: user variables with IN and NOT IN:

using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
    var results = fulltextSession.Query<Product>().
                                  Where(p => p.CategoryId.In("@my_user_var")).
                                  ToList();
}

There are a few more new features not mentioned here, which you can find in the version history.

Tags:

Announcements