Efficient processing of similarity queries with applications