0

I'm trying to figure out how to implement a "strength based search" using multiple fields/terms. For example:

Searching:

  • Number Of Legs: 4
  • Has Fur: True
  • Has Hooves: True
  • Keywords: Moo

Results:

  • [High] Cow
  • [Medium] Cat
  • [Medium] Dog
  • [Low] Hairless Mole-rat
  • [No Match] Bird

It may be worth mentioning that the criteria in my actual model is somewhat weighted, related, and structured.

My language of choice is C#.NET, and I'm using LINQ + Fluent NHibernate. I have been playing around with a few different ways to implement this, but most feel clunky. Currently, the DB I'm using has over 100,000 "Animals", and they can be searched on against ~15 fields.

Questions:

Does this kind of search have a name?

Are there best practices or techniques that I should be aware of while trying to implement this?

What are some high performance ways to implement a search like this? Psuedo code and general logic appreciated just as much as code.

Daniel Brown
  • 2,942
  • 5
  • 29
  • 41
  • 1
    http://stackoverflow.com/questions/177753/search-ranking-relevance-algorithms – Robert McKee Oct 20 '15 at 21:43
  • 1
    You could use SQL Server's full text search to generate a relevancy score on keyword(s), and merge that with your booleans to generate a composite relevancy score. That should make your searches fairly quick. – Robert McKee Oct 20 '15 at 21:45

1 Answers1

1

You're speaking about a "weighted term query".

Since you're already using LINQ and I assume MSSQL, your quickest solution is probably to write a stored procedure (that you will ultimately call with LINQ) which uses full-text search functions (CONTAINSTABLE and ISABOUT) to "rank" results the way you desire.


If you expect heavy search traffic or your ranking requirements get much more complex, or your collection grows significantly you should consider breaking this functionality out into a search engine like Solr or Elasticsearch.

Peter Dixon-Moses
  • 3,169
  • 14
  • 18