Solr
  1. Solr
  2. SOLR-4081

QueryParsing.toString(Query,IndexSchema) does not properly handle WrappedQuery

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: query parsers
    • Labels:
      None

      Description

      QueryParsing.toString() is a method that uses knowledge of various Query implementations to properly render a query string. For example, using toString with a BooleanQuery might return a string like this:

      owner_id:18935 (acl_id:9451 acl_id:11634 acl_id:15678 acl_id:16791)

      When using localParams such as "

      {!cache=false cost=0}

      ", the query turns into a WrappedQuery wrapping a BooleanQuery. This is not understood by QueryParsing.toString(), which calls WrappedQuery.toString() instead, returning a string like this:

      {!cache=false cost=0}owner_id:w (acl_id:` acl_id:Ik acl_id:Zr acl_id:z> acl_id:)

      The probable (untested) solution will be to include a couple of lines at the top of toString(), as shown below. A further optimization would be to create "void WrappedQuery.getOptions(Appendable out)", to avoid creating a StringBuilder inside WrappedQuery.getOptions().

      public static void toString(Query query, IndexSchema schema, Appendable out, int flags) throws IOException {
        boolean writeBoost = true;
      
        // Begin new code to handle WrappedQuery
        if (query instanceof WrappedQuery) {
          WrappedQuery q = (WrappedQuery)query;
          out.append (q.getOptions());
          query = q.getWrappedQuery();
        }
        // End new code to handle WrappedQuery
      
        if (query instanceof TermQuery) {
          ...
      

        Activity

        Hide
        Yonik Seeley added a comment -

        Thanks Eirik, I've committed a fix to trunk & 4x.
        http://svn.apache.org/viewvc?rev=1410115&view=rev

        Show
        Yonik Seeley added a comment - Thanks Eirik, I've committed a fix to trunk & 4x. http://svn.apache.org/viewvc?rev=1410115&view=rev

          People

          • Assignee:
            Yonik Seeley
            Reporter:
            Eirik Lygre
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development