Question

I am rewriting a Hibernate/lucene function, findRangeSorting(), that retrieves all records in a table based on a permissions filter. Right now this is done (very badly) by hand by stitching together HQL (hibernate sql) strings and using that to query the database.

I also have a search function which uses a better programmatic approach by creating filters for the classes using the hibernate annotation and combines Boolean queries into a full text query which then has the filters added to it based on which user is doing the search. (Note that is not the entire function)

fullTextQuery = fullTextSession.createFullTextQuery(bq, this.type); results = tab.getQueryFiltersForSearch(fullTextQuery).setSort(sort).list();

I would like to use this functionality for the findRangeSorting() function since the filters are already in place, so I would basically just need to have the search return everything. The downside is that searching for "" and * don't accomplish this, and so I need to basically create a FullTextQuery without having to search for an actual term, or possibly find an alternative method for retrieving a range of rows from a table with filters based on user permissions.

I do not have the best grasp of hibernate so I might be totally wrong in my assumptions. Any help is appreciated.

Was it helpful?

Solution

To create a query match all documents, you should just be able to use Lucene's MatchAllDocsQuery. I'm not aware of anything in the Hibernate QueryBuilder that creates a MatchAllDocsQuery, but it's simple enough to create one through the Lucene API directly, something like:

org.apache.lucene.search.Query allQuery = new org.apache.lucene.search.MatchAllDocsQuery();
fullTextQuery = fullTextSession.createFullTextQuery(allQuery, this.type); 
results = tab.getQueryFiltersForSearch(fullTextQuery).setSort(sort).list();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top