Question

I am using NHibernate.Search libraries in my project for free text search. Recently when I started getting more than 2100 results, I started getting max parameter length error from SQL Server.

Does NHibernate.Search take care of such situation ? Any workaround anyone ?

Was it helpful?

Solution

You could modify NHibernate.Search code to take care of this, or, use custom paging, IE get number of hits for your search, then page nhibernate search results accordingly.

public IList<TEntity> Search<TEntity>(Query query, bool? active, string orderBy)
{
    var search = NHibernate.Search.Search.CreateFullTextSession(this.session);

    var total = search.CreateFullTextQuery(query, typeof(TEntity)).ResultSize;

    var first = 0;

    var l = new List<TEntity>();

    while (total > 0)
    {
        l.AddRange(search.CreateFullTextQuery(query, typeof(TEntity))
                .SetFirstResult(first)
                .SetMaxResults(1000)
                .List<TEntity>());

        first += 1000;
        total -= 1000;
    }

    return l;
}

See : IFullTextQuery - exception if there are too may objects

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top