Uploaded image for project: '[Read Only] - Hippo Site Toolkit 2'
  1. [Read Only] - Hippo Site Toolkit 2
  2. HSTTWO-1188

Missing brackets in JCR Query Expression - AND takes priority over OR

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • 2.05.01, 2.10.00
    • 2.05.02, 2.10.01
    • None
    • None

    Description

      Example:

      String categories[][] = "foo1", "foo2"}, {"bar1", "bar2";
      try {
      HstQuery query = getQueryManager().createQuery(getContentBean(request));
      final Filter taxonomyFilter = query.createFilter();
      for (String keys[] : categories) {
      Filter mainCategoryFilter = new FilterImpl();
      for (String key : keys) {
      final Filter subcategoryFilter = new FilterImpl();
      try

      { subcategoryFilter.addEqualTo(TaxonomyNodeTypes.HIPPOTAXONOMY_KEYS, key); mainCategoryFilter.addOrFilter(subcategoryFilter); }

      catch (FilterException exception)

      { // nothing }

      }
      taxonomyFilter.addAndFilter(mainCategoryFilter);
      }
      query.setFilter(taxonomyFilter);
      query.getQueryAsString(false);
      } catch (QueryException exception) {
      // nothing
      }

      Results in query: foo1 + foo2 * (bar1 + bar2)

      //*[(@hippo:paths='868e22f8-ad19-4b16-ace5-a7cbeea2cc4b' and @hippostd:state='published' and not(@jcr:primaryType='nt:frozenNode')) and
      (@hippotaxonomy:keys = 'foo1' or (@hippotaxonomy:keys = 'foo2') and
      (@hippotaxonomy:keys = 'bar1' or (@hippotaxonomy:keys = 'bar2'))
      )] order by @jcr:score descending

      My expected query is: (foo1 + foo2) * (bar1 + bar2)

      //*[(@hippo:paths='868e22f8-ad19-4b16-ace5-a7cbeea2cc4b' and @hippostd:state='published' and not(@jcr:primaryType='nt:frozenNode')) and
      ((@hippotaxonomy:keys = 'foo1' or (@hippotaxonomy:keys = 'foo2')) and
      (@hippotaxonomy:keys = 'bar1' or (@hippotaxonomy:keys = 'bar2'))
      )] order by @jcr:score descending

      Attachments

        Activity

          People

            aschrijvers Ard Schrijvers
            jbloemendal Jannis Bloemendal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: