facet search

Feb 13, 2012 at 6:35 PM


How can i performan a facet search?



Feb 14, 2012 at 11:04 AM

This isn't really specific to SimpleLucene. To create a faceted search I would recommend you make use of query objects - see http://simplelucene.codeplex.com/wikipage?title=Creating%20Query%20Objects&referringTitle=Documentation.

Based on this example, assume you have a asp.net web forms page with a free text box and additional filters like price. In your search button click event handler you could do something like:

	var indexSearcher = new DirectoryIndexSearcher(new DirectoryInfo(indexPath), true);
	using (var searchService = new SearchService(indexSearcher)) {
		var query = new ProductQuery().WithKeywords(txtKeywords.Text);
		// build up the query using additional filters:
		if !(string.IsNullOrEmpty(txtFromPrice.Text) && 
				string.IsNullOrEmpty(txtToPrice.Text)) {
			query = query.WithPriceBetween(decimal.Parse(txtFromPrice.Text),
		// you can chain more queries on here
		var result = searchService.SearchIndex(query.Query);
		// do something with results

Using query objects you can chain as many filters together as you like.

Hope that helps