Listeners: What are query listeners and how to work with them?

The reason we have document query listeners is to apply query customizations globally. In order to do this the user need to create their own implementation of the IDocumentQueryListener.

public interface IDocumentQueryListener
{
	/// <summary>
	/// Allow to customize a query globally
	/// </summary>
	void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization);
}

Example

If we want to disable caching of all query results, you can implement DisableCachingQueryListener which will add NoCaching customization to each performed query.

public class DisableCachingQueryListener : IDocumentQueryListener
{
	public void BeforeQueryExecuted(IDocumentQueryCustomization customization)
	{
		customization.NoCaching();
	}
}