8

Currently I am doing Faceted search on indexes created by Lucene.NET. Below is my code.

var query = new MatchAllDocsQuery();
var factedSearch = new SimpleFacetedSearch(luceneIndexReader,new[] { "field1","field2" });

SimpleFacetedSearch.Hits genreFactedHits = genreFactedSearch.Search(query, 100000);

foreach (var facet in factedSearch .HitsPerFacet)
{
    var docs = facet.Documents;
    var facetName = facet.Name.ToString();
}

Here I am getting the results in the variable "docs". Here I can put all the results into memory and do OrderBy. But I don't think it is an efficient way to do. Can anybody please help me here to get the sorted results ?

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
  • Facets are normally sorted on facetName and the docs are not presented until the facet is selected and the search executed. Why would you want to present the docs here, instead of just the `Name` and `HitCount`? – sisve Nov 26 '13 at 06:41
  • @Simon. Thanks for your reply. Suppose I have some books and I faceted them according to categories(e.g. Action, Story). Now I want to do sort by title Z to A for the books in the faceted results. That Thing I am unaware how to do. Can you please help me on this? – Bishwaranjan Dec 02 '13 at 07:35
  • I have a related question - So, SimpleFacetedSearch gives us facets only, what about hits for our original search. Do we need run two queries - once to get the search results and another using SimpleFacetedSearch to fetch facets? – EagerToLearn Jun 26 '15 at 23:47
  • That's how SimpleFacetedSearch works. You could build a custom Collector that grabs search results and facet values from those results (potentially using the field cache) in one search. Ask a new question if your wondering about the details. – sisve Jun 27 '15 at 04:05
  • I would suggest to use elastic search https://www.elastic.co/ which is created upon lucene and has great features.To use facets, elastic search have aggregation concept which supports sorting and many more features – Hardik Dobariya Sep 18 '15 at 05:50

0 Answers0