lucene.net 4.8 custom sorting according to string length

How can I sort by string length?
For example, I use lucene.net to search, the keyword is "toluene", then the name of "toluene" is in the front, and the name containing "toluene" is in the back, which makes me very troubled.

This is my search:

var query = MultiFieldQueryParser.Parse(version, GetKeyword(keyword), fileds, new Occur[] { Occur.SHOULD, Occur.SHOULD, Occur.SHOULD, Occur.SHOULD }, analyzer);

foreach (var item in fileds)
{
    var regexpQuery = new RegexpQuery(new Term(item, $".*{keyword}.*"));

    bq.Add(regexpQuery, Occur.SHOULD);
}

Sort sort = new Sort(new SortField("name", SortFieldType.SCORE, false));

Image



Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept