<div dir="ltr"><div>There are actually very few queries so far. I have yet to optimize the preview section, that still uses the gateway, but I will follow up this email with those optimizations, plus any I make in webtagging to optimize that.</div>

<div><br></div><div>Cheers,</div><div><br></div><div>Douglas</div><div><br></div><div>In the subquery, take a list of tag IDs and find which images have all of these present. Use the list of imageIds that the subquery generates to find the list of all other tags which are present on those images. These are the potential criteria for refinements to the tag search space.</div>

<div><br></div><div>            selected_tags = [1L,2L,3L,4L] # e.g.</div><div><br></div><div>            sub_hql = &quot;select <a href="http://link.parent.id">link.parent.id</a> from ImageAnnotationLink link &quot; \</div>

<div>                   &quot;where <a href="http://link.child.id">link.child.id</a> in (:oids) &quot; \</div><div>                   &quot;group by <a href="http://link.parent.id">link.parent.id</a> &quot; \</div><div>                   &quot;having count (link.parent) = %s&quot; % len(selected_tags)</div>

<div><br></div><div>            hql = &quot;select distinct <a href="http://link.child.id">link.child.id</a> from ImageAnnotationLink link &quot; \</div><div>               &quot;where <a href="http://link.parent.id">link.parent.id</a> in (%s)&quot; % sub_hql</div>

<div><br></div><div><div>            params = Parameters()</div><div>            params.map = {}</div><div>            params.map[&quot;oids&quot;] = rlist([rlong(o) for o in set(selected_tags)])</div><div><br></div><div>

            qs = conn.getQueryService()</div><div>            results = qs.projection(hql, params)</div></div><div><br></div><div><br></div><div>Get the Ids and text values of all the tags, excluding any tags which are not applied to anything as those do not make sense in the context of navigation.</div>

<div><div><br></div><div>        hql = &quot;select distinct <a href="http://link.child.id">link.child.id</a>, link.child.textValue &quot; \</div><div>              &quot;from ImageAnnotationLink link &quot; \</div><div>
              &quot;where link.child.class is TagAnnotation &quot; \</div>
<div>              &quot;order by link.child.textValue&quot;</div><div><br></div><div><div>        params = Parameters()</div><div>        qs = self.conn.getQueryService()</div></div><div>        tags = [(result[0].val, result[1].val) for result in qs.projection(hql, params)]</div>

</div></div>