Hi All,
I am using Lucene Search to get the articles that are matching the search text. Is there any way to get them in ascending order of number of hits in the Article.
Example: If my search text is stack
and in first Article there are two occurrences of the word stack
and in the second Article there are three occurrences of stack
then the second one should come first and the first one should come second.
Any idea how can I get it done?
Below is the code that I am using
List<LuceneSearchResult> searchResult = new List<LuceneSearchResult>();
LuceneSearchResult result;
IndexReader reader = IndexReader.Open(INDEX_DIR);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser("Text", analyzer);
//Text and Type are column name
Query q = parser.Parse(string.Format("Text:{0} AND Type:{1}", finalText, type));
Hits hs = searcher.Search(q);
ArrayList idList = new ArrayList();
for (int i = 0; i < hs.Length(); i++)
{
Document doc = hs.Doc(i);
result = new LuceneSearchResult();
result.ID = doc.Get("ID");
result.Type = doc.Get("Type");
if (!idList.Contains(result.ID))
{
searchResult.Add(result);
idList.Add(result.ID);
}
}
return searchResult.ToArray();