Search code examples
asp.netsqldatabasesearchsearch-engine

How to implement dynamic categorization / search filters


I am building a website where I need to have dynamic categories like ebay search filters. Can you please point me to the right direction and send me some helpful links or ideas.

In ebay, search filters on the left hand side are always generated based on the product data.

Any ideas how to implement that?

Thanks very much.


Solution

  • Here's one of the simplest way: you need to first tag your products. Tagging is essentially categorization but its important that you can put the product into multiple categories (or tags).

    Now when the product is searched, you have to fire corresponding query for tags - for example, assuming three simple tables: product_master, tag_master and product_tag (many_to_many relationships), a MS Sql query such as would do the trick

    select
      t.tag_name,
      count distinct (pt.product_id)
    from
      tag_master t
      inner join product_tag pt
         on t.tag_id = pt.tag_id
      inner join product p
         on pt.product_id = p.product_id
    Where
      p.name like '%search_term%'
    group by
      t.tag_name
    

    Essentially, for very product search, you need to fire such query. Typically, you would match on few thousands of tags and so you cache the query result while further paging of search. Drilling down by tag/category will simple add to where clause.

    You can extend the query for supporting hierarchies in tags (or categories).