Pagelet[] mainPagelets = pages[0].getPagelets("main");
Pagelet titlePagelet = new PageletImpl(mainPagelets[0].getModule(), mainPagelets[0].getIdentifier());
Pagelet imagePagelet = new PageletImpl(mainPagelets[1].getModule(), mainPagelets[1].getIdentifier());
// Search for pages containing a pagelet (pages 1 and 2)
SearchQuery q = new SearchQueryImpl(site).withPagelet(titlePagelet);
assertEquals(2, idx.getByQuery(q).getDocumentCount());
// Search for pages containing an image pagelet (only page 1)
q = new SearchQueryImpl(site).withPagelet(imagePagelet);
assertEquals(1, idx.getByQuery(q).getDocumentCount());
// Search for pages containing the title pagelet in the correct position
// (only page 1)
q = new SearchQueryImpl(site).withPagelet(titlePagelet).inComposer("main");
assertEquals(1, idx.getByQuery(q).getDocumentCount());
q = new SearchQueryImpl(site).withPagelet(titlePagelet).inComposer("main").atPosition(0);
assertEquals(1, idx.getByQuery(q).getDocumentCount());
q = new SearchQueryImpl(site).withPagelet(titlePagelet).atPosition(0);
assertEquals(1, idx.getByQuery(q).getDocumentCount());
// Search for pages containing the title pagelet in the correct position
// (only page 1)
q = new SearchQueryImpl(site).withPagelet(titlePagelet).inComposer("test");
assertEquals(0, idx.getByQuery(q).getDocumentCount());
q = new SearchQueryImpl(site).withPagelet(titlePagelet).atPosition(2);
assertEquals(0, idx.getByQuery(q).getDocumentCount());
q = new SearchQueryImpl(site).withPagelet(titlePagelet).inComposer("main").atPosition(1);
assertEquals(0, idx.getByQuery(q).getDocumentCount());
// Find documents with both pagelets on one page
q = new SearchQueryImpl(site).withPagelets(All, titlePagelet, imagePagelet);
assertEquals(1, idx.getByQuery(q).getDocumentCount());
// Find documents with both pagelets on one page and in the same composer
q = new SearchQueryImpl(site).withPagelets(All, titlePagelet, imagePagelet).inComposer("main");
assertEquals(1, idx.getByQuery(q).getDocumentCount());
}