3 Replies Latest reply on Oct 21, 2008 6:56 PM by andygibson.contact.andygibson.net

    EntityQuery and Facetted Browsing

    sushi6677
      Hi all,

      I'm new in the field of Seam and I already have a question :-)
      I'm using the EntityQuery class for generating a Query over documents. These documents are stored in a database and the search can be done over the attributes doi, title and year. The query works fine!

      But now the problem: I implemented a Facette Class which gets the result list and generates for example a rich tab panel where you have content like: 2005 [10] 2006 [2]
      This means that in the result list you have 10 documents published in 2005 and 2 in 2006. But exactly here is the problem: I defined a method which has a List<Documents> parameter. But this parameter just holds the elements inside the actual page of results and I need the whole result list. So is there any solution for getting the whole resultlist out of an EntiytQuery object and still have the pageinaging stuff?



        • 1. Re: EntityQuery and Facetted Browsing
          andygibson.contact.andygibson.net

          If the entity query has all the results, it doesn't need the dynamic kind of pagination. You could simply use the rich faces data scroller since you have all the results.


          Alternatively, you can use some other method to get the list of documents by year which will do so in a more optimized manner. This way you don't have to fetch all the results back to count them by year.


          Cheers,


          Andy

          • 2. Re: EntityQuery and Facetted Browsing
            sushi6677

            Hi,


            first thanks for your reply...
            I will try your solution with the datascroller.


            But during coding on I developed the following method inside my DocumentList bean derived from EntityQuery<Document>.


            @Factory("yearFacete")
             public List<Year> initYearFacete() {
              List<Document> documents = super.getResultList();
              List<Year> years = new ArrayList<Year>();
            
              for(Document doc : documents) {
                Year year = new Year();
                year.setName(String.valueOf(doc.getYear()));
                if(years.contains(year)) {
                 int index = years.indexOf(year);
                 int value = years.get(index).getOcc();
                 value++;
                 year.setOcc(value);
                 years.set(index, year);
                } else {
                 year.setOcc(1);
                 years.add(year);
                }
              }
              return years;
             }
            



            Here I call the super.getResultList() method and watched the log. It seams that seam just made one query to the database.
            So my question is: When does seam decide if it has to make a query or not? I mean due to the logic there should be two same queries:
            1) for getting the resultList for the JSF page
            2) for getting the resultList inside the yearFacete factory method...


            Bests,
            Sushi


                 

            • 3. Re: EntityQuery and Facetted Browsing
              andygibson.contact.andygibson.net

              Hey Sascha,


              Yes, that is correct. The resultList is only loaded on demand and remembered.  If you look at at the iniResultList method that is called by getResultList :


                 private void initResultList()
                 {
                    if (resultList==null)
                    {
                       javax.persistence.Query query = createQuery();
                       resultList = query==null ? null : query.getResultList();
                    }
                 }
              



              In other words, once you get the results, the entity query remembers them for the lifespan of the bean (or until you call refresh which essentially sets results list = null)


              Cheers,


              Andy