1

We have relational db (SQL Server 2014, about 30 tables, very normalized). The application is built using Web.API/AngularJS

We need to implement dynamic search - user may select a few fields from several entities; the resulting search pseudo-code might look like:

SearchConditions
    (
        {Company.Name} <Contains> "Enterprise"
    )
    AND
    (
        {Customer.State} <Equals> "MO"
        OR
        {Customer.State} <Equals> "TX"
    )
    AND
    (
        {Company.AnnualSales} <LessThan> "123456.00"
    )
Return
    Company.Name,Customer.Name
    Group By State, Company

The structure of the search will stay the same - bunch of conditions connected by "AND"; each condition might have a few "OR" items inside.

We are using Entity Framework;

so far I see several ways to implement this functionality:

  • 1) build SQL query and run it against db (quite cumbersome)

  • 2) create EF IQueryable object and get data by using EF (somewhat easier, but I am afraid that resulting SQL will be awful)

  • 3) use Lucene.NET (it will require Solr server, I'd like to avoid it if possible)

  • 4) create denormalized OLAP instance of our db and use approach (1) or (2)

I am pretty sure there must be other ways; after all, EF/.NET/SQL combination is not so rare; I don't want to reinvent the wheel if I can avoid it. The ideal solution would parse search string, do the search and get back required fields (paging would be a good plus as well)

Would SSAS/SSRS help?

3
  • I've done that with something close to data annotations into POCO classes which gives me field names to use on search control (reflection) and than build a filter based on DapperExtensions (using IPredicate). It will require both Dapper and DapperExtensions (and creation of POCO mappings to your DB), though. It's just a way, if no other comes to appear =) Commented Apr 27, 2015 at 21:28
  • 1
    If you are on a web page you could try this javascript solution. If you are on WPF, Telerik has a control for that but I don't recall the name, and of course it costs money. Commented Apr 27, 2015 at 21:47
  • thank you, the idea of ISBjs looks very promising Commented Apr 27, 2015 at 21:50

1 Answer 1

1

Although all the solutions you have mentioned will probably work, I will recommend Elasticsearch.

Elasticsearch is a document store that is built on top of Lucene (you do not need to run a separate Solr server though) and is really easy to run and install. There is also a nice .Net API for it called Nest. As the name mentions it is specifically built for searching. And it also has paging built in among many other features.

You can quite easily store only your search terms in the db and return the ids that is applicable to your search query. We currently use it to store all our data as documents however there are lots of people using it to just do all their searching.

You literally just copy the exe on your machine and run it. You then have a REST api that allows you to communicate with it. Nest abstracts this.

You can built your dynamic queries using Nest by just adding onto the search object or if you want to you can built a json object that you pass in.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.