Skip to content

Allow to use dismax when calculating scores of synonym expansions #281

Closed

Description

@renekrie

Let's assume we have the following synonym expansions defined in the common rules rewriter:

A => 
  SYNONYM: B
  SYNONYM:  X Y
K =>
  SYNONYM: G

After applying this expansion to an input query A K, the query would be represented as follows in Querqy's (q.*) query object model:

q.BQ(
    q.DMQ(
      q.TQ(A),
      q.TQ(B),
      q.BQ(
        q.DMQ(
          q.TQ(X)
        ),
        q.DMQ(
          q.TQ(Y)
        )
      )
    ),
    q.DMQ(
      q.TQ(K),
      q.TQ(G)
    )
)

BQ = 'Boolean Query', DMQ = 'DisMax Query', TQ = 'Term Query' - despite their similar names, these 
  are not Lucene queries 

Let's assume that we want to search in fields f1 and f2. Querqy would build the following Lucene (lc.*) query for our case:

lc.BQ(
    lc.DMQ(
      lc.TQ(f1:A),
      lc.TQ(f2:A),
      lc.TQ(f1:B),
      lc.TQ(f2:B),
      lc.BQ(
        lc.DMQ(
          lc.TQ(f1:X),
          lc.TQ(f2:X)
        ),
        lc.DMQ(
          lc.TQ(f1:Y),
          lc.TQ(f2:Y),
        )
      )
    ),
    lc.DMQ(
      lc.TQ(f1:K),
      lc.TQ(f2:K),
      lc.TQ(f1:G),
      lc.TQ(f2:G)
    )
)

We can set the tie parameter and it would be applied for all DMQs. But as soon as we use tie>0 we would favour the documents that match the most synonyms, for example, documents that match A and B and X Y in our case. This is not what we would indent in most cases.

I suggest to insert one lc.DMQ per top-level query clause (of the BQ) and repeat the above clause structure per field as clauses under that DMQ:

lc.BQ(
  lc.DMQ(  ### new DMQ, uses current tie parameter for aggregation across fields
    lc.DMQ( ### 'old' DMQ, but having only f1 clauses. New tie parameter to aggregate across synonyms.  
      lc.TQ(f1:A),
      lc.TQ(f1:B),
      lc.BQ(
        lc.DMQ(
          lc.TQ(f1:X)
        ),
        lc.DMQ(
          lc.TQ(f1:Y)
        )
      )
    ),
    lc.DMQ( ### 'old' DMQ, but having only f2 clauses. New tie parameter to aggregate across synonyms.  
      lc.TQ(f2:A),
      lc.TQ(f2:B),
      lc.BQ(
        lc.DMQ(
          lc.TQ(f2:X)
        ),
        lc.DMQ(
          lc.TQ(f2:Y)
        )
      )
    )
  ),
  lc.DMQ(### new DMQ, uses current tie parameter for aggregation across fields
    lc.DMQ(### 'old' DMQ, but having only f1 clauses. New tie parameter to aggregate across synonyms.
      lc.TQ(f1:K),
      lc.TQ(f1:G)
    ),
    lc.DMQ(### 'old' DMQ, but having only f2 clauses. New tie parameter to aggregate across synonyms.
      lc.TQ(f2:K),
      lc.TQ(f2:G)
    )
  )
)

Thus the new tie parameter will add an 'expansion tie breaker' to control aggregation across synonyms or other types of expansions, for example including those generated by word compound handling. We will start with a single 'expansion tie breaker' parameter. If required we might be able to implement this per rewriter later (it would require a modification to Querqy's query object model - see #26 - as opposed to changing the Lucene query object building). Users can use the old/current tie parameter to control score aggregation across fields (as opposed to 'across synonyms/expansions'), which is probably how this parameter was intended originally.

The default value of the 'expansion tie breaker' shall be 0.0. Users will be able to re-create the current behaviour by setting the parameter to 1.0.

Activity

  1. self-assigned this
    on Jan 18, 2022
  2. added a commit that references this issue on Feb 17, 2022
  3. renekrie commented on Feb 17, 2022

    @renekrie
    CollaboratorAuthor

    The above approach has the issue that it changes boolean matching semantics.

    lc.DMQ(
      lc.BQ(
            lc.DMQ(
              lc.TQ(f1:X)
            ),
            lc.DMQ(
              lc.TQ(f1:Y)
            )
          ),
    lc.BQ(
            lc.DMQ(
              lc.TQ(f2:X)
            ),
            lc.DMQ(
              lc.TQ(f2:Y)
            )
          )
    )
    

    means that X AND Y have to match both in f1 or both in f2 while in the original structure X could match in one field and Y in the other.

    The following structure fixes the problem:

    lc.BQ(
        lc.DMQ( # new 'multi-match' tie
          lc.DMQ( # old tie param
            lc.TQ(f1:A),
            lc.TQ(f2:A)
          ),
         lc.DMQ(# old tie param
            lc.TQ(f1:B),
            lc.TQ(f2:B),
         )
          lc.BQ(
            lc.DMQ(# old tie param
              lc.TQ(f1:X),
              lc.TQ(f2:X)
            ),
            lc.DMQ(# old tie param
              lc.TQ(f1:Y),
              lc.TQ(f2:Y)
            )
          )
        ),
        lc.DMQ( # new 'multi-match' tie
          lc.DMQ(# old tie param
            lc.TQ(f1:K),
            lc.TQ(f2:K)
          ),
          lc.DMQ(# old tie param
             lc.TQ(f1:G),
             lc.TQ(f2:G)
          )
        )
    )
    

    And that's how it is implemented in f80f822

  4. added this to the querqy-solr-5.3.0 milestone on Feb 22, 2022
  5. renekrie commented on Feb 22, 2022

    @renekrie
    CollaboratorAuthor

    Implemented by #303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions