Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1851

Expose unary plus and unary minus operators as interceptable method calls: positive() and negative()

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.1-rc-1
    • None
    • None

    Description

      I'm writing a Groovy builder for Compass (Lucene) queries, and it would be nice to use + and - in the closure, since it mirrors Lucene's own query string syntax, eg:

          def query = builder.build {
             +term('keywords', 'book')
             -term('keywords', 'audio')
             queryString('color theory')
         } 
      

      would create a query that in Lucene query string syntax looks like +keywords:book -keywords:audio all:color all:theory.

      (Incidentally this query means: 'keywords' MUST have the value 'book' and MUST NOT have the value 'audio' and 'all' SHOULD (may or may not) have 'color' and 'theory'.)

      Ok they don't mirror each other exactly, but for those familar with Lucene query string syntax I think this will just feel "right".

      So can these + and - operators be made interceptable method calls?

      I think the opinion of the list was to use positive() and negative() as the method names: http://www.nabble.com/use-of-%2B-and---in-DSL--tf3623677.html

      Attachments

        Activity

          People

            paulk Paul King
            maurice.nicholson Maurice Nicholson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: