SearchExtensions: Method restructure

2 min read

A new release of NinjaNye.SearchExtensions is now available from nuget. Following on from my previous post, I describe some changes to the method signatures used within search extensions.

###Method signature restructure

Since the project began, the method signatures have not been very consistent and as more methods get added the mess was getting bigger so I decided to set a standard to fix this.

Previously, methods were ordered to take advantage of the params keyword so that if a user had multiple search terms they could do so very easily, likewise, if they wanted multiple properties, it was equally easy:

// Multiple search terms
var result = data.Search(x => x.Property1, "searchTerm1", "searchTerm2", "searchTerm3");
// Multiple properties
var result = data.Search("searchTerm1", x => x.Property1, x => x.Property2, x => x.Property3);

As the project grew this became messy and it was unclear whether or not to provide as search term first or a property. So I decided to put in place a rule whereby the first property always relates to the search term and, where needed, the second property always relates to the property. This means, the first example above with multiple search terms now reads a bit differently:

// Old signature
var result = data.Search(x => x.Property1, "searchTerm1", "searchTerm2", "searchTerm3");
// New signature
var result = data.Search(new[]{ "searchTerm1", "searchTerm2", "searchTerm3" }, x => x.Property1);

Now on this occasion, it may not be quite as nice to read but the result means all Search methods conform to the new standard making the whole library much easier to use. Below is a list of methods available which I think illustrates the benefit of the change:

<div class="row"> <div class="col-sm-6"> <h4 class="text-center">Old</h4> <pre class="prettyprint prettyprinted" > Search(term); Search(property, term); Search(property, term, comparison); Search(term, comparison, params properties); Search(property, params terms); Search(property, comparison, params term); Search(terms, params properties); Search(terms, comparison, properties);</pre> </div> <div class="col-sm-6"> <h4 class="text-center">New</h4> <pre class="prettyprint prettyprinted"> Search(term); Search(term, property); Search(term, property, comparison); Search(term, params properties); Search(term, properties, comparison); Search(terms, property); Search(terms, property, comparison); Search(terms, params properties); Search(terms, properties, comparison);</pre> </div> </div>

I hope you agree that the new methods are much better then before and hopefully mean the package is much easier to integrate with.


NinjaNye.SearchExtensions is availabel as a nuget package and can be installed using the following code in your Package Manager Console

<p class="nuget-badge"><code>PM> Install-Package NinjaNye.SearchExtensions</code></p>

As always, any comments are greatly appreciated. I'd love to hear how you are using SearchExtensions and maybe help find new ways to improve it.