Solr
  1. Solr
  2. SOLR-786

refactor in DisMaxQParserPlugin and DismaxQParser to allow extending DismaxQParser

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: search
    • Labels:
      None

      Description

      I needed to change some of the default behaviour of the DismaxQParser, so as opposed to infecting the solr codebase with our custom behaviour, I wanted to be able to subclass the DismaxQParser and change only what we wanted to change.

      Here I submit a patch that allows for such subclassing. The change that is done to the code base in the following steps:

      1. refactor in the DismaxQParser.parse() method to
      addMainQuery(query, solrParams);
      addBoostQuery(query, solrParams);
      addBoostFunctions(query, solrParams);

      2. refactor the addMainQuery() method to use
      getUserQuery(userQuery, up, solrParams)
      getAlternateUserQuery(solrParams)
      getPhraseQuery(userQuery, pp)

      3. move the DismaxQParser to the top-level to make it public (and allow subclassing)

      After applying this change I can to as follows:
      1. write my own QParserPlugin to return a subclass of the DismaxQParser
      2. in this subclass I override the the methods I need, in my case the getUserQuery() method.
      3. add this plugin to the solrconfig.xml and use it

      the patch is done against the Solr svn trunk

      1. SOLR-786.patch
        10 kB
        Shalin Shekhar Mangar
      2. dismax-query-parser.patch
        18 kB
        Wojciech Biela

        Activity

        Hide
        Wojciech Biela added a comment -

        the patch

        Show
        Wojciech Biela added a comment - the patch
        Hide
        Wojciech Biela added a comment -

        corrected patch (added the ASL 2.0 Licence note)

        Show
        Wojciech Biela added a comment - corrected patch (added the ASL 2.0 Licence note)
        Hide
        Wojciech Biela added a comment -

        the patch corrected, one of the methods was private, so I made it protected to allow reuse.

        Show
        Wojciech Biela added a comment - the patch corrected, one of the methods was private, so I made it protected to allow reuse.
        Hide
        Koji Sekiguchi added a comment -

        This is not a bug.

        Show
        Koji Sekiguchi added a comment - This is not a bug.
        Hide
        Shalin Shekhar Mangar added a comment -

        Patch updated to trunk.

        We've already marked DisMaxQParser as an experimental API so this can go in as well. I plan to commit shortly.

        Show
        Shalin Shekhar Mangar added a comment - Patch updated to trunk. We've already marked DisMaxQParser as an experimental API so this can go in as well. I plan to commit shortly.
        Hide
        Shalin Shekhar Mangar added a comment -

        Committed revision 779469.

        Thanks Wojciech!

        Show
        Shalin Shekhar Mangar added a comment - Committed revision 779469. Thanks Wojciech!
        Hide
        Grant Ingersoll added a comment -

        Bulk close for Solr 1.4

        Show
        Grant Ingersoll added a comment - Bulk close for Solr 1.4

          People

          • Assignee:
            Shalin Shekhar Mangar
            Reporter:
            Wojciech Biela
          • Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development