// create an instance of Sort object Sort sortByTitle = new Sort(new SortField("title", SortField.STRING)); // set the sort order to ascending sortByTitle.SetSort(SortField.FIELD_SCORE, new SortField("title", SortField.STRING)); // perform the search using the sort object searcher.Search(query, filter, 100, sortByTitle);
// create an instance of Sort object Sort sortByRelevance = new Sort(new SortField(null, SortField.SCORE)); // set the sort order to descending sortByRelevance.SetSort(SortField.FIELD_SCORE, new SortField(null, SortField.SCORE, true)); // perform the search using the sort object searcher.Search(query, filter, 100, sortByRelevance);In this example, the search results will be sorted by relevance, which is determined by the score of the search query. The results will be sorted in descending order. The Lucene.Net.Search.Sort class is part of the Lucene.Net package library.