Lucene - Core
  1. Lucene - Core
  2. LUCENE-1608

CustomScoreQuery should support arbitrary Queries

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core/query/scoring
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      CustomScoreQuery only allows the secondary queries to be of type ValueSourceQuery instead of allowing them to be any type of Query. As a result, what you can do with CustomScoreQuery is pretty limited.

      It would be nice to extend CustomScoreQuery to allow arbitrary Query objects. Most of the code should stay about the same, though a little more care would need to be taken in CustomScorer.score() to use 0.0 when the sub-scorer does not produce a score for the current document.

      1. LUCENE-1608.patch
        11 kB
        Doron Cohen
      2. CustomScoreQueryWithSubqueries.java
        47 kB
        Fernando Wasylyszyn

        Issue Links

          Activity

          Hide
          Fernando Wasylyszyn added a comment - - edited

          I upload a class (for demonstration purposes only, is not clean enough for a patch, that is why is not one) that allows secondary queries to be any type of query, not only ValueSourceQuery. For example, the main query could be (field1:value OR field2:value) and one secondary query (field3:anotherValue). There are more optimizations to be done on this class: continuing the previous example, if the secondary query would be (field1:value), then some type of "scorer cache" would be useful in order to avoid keeping two scorers for the same query (first clause in main query and secondary query). Comments are more than welcome.

          Show
          Fernando Wasylyszyn added a comment - - edited I upload a class (for demonstration purposes only, is not clean enough for a patch, that is why is not one) that allows secondary queries to be any type of query, not only ValueSourceQuery. For example, the main query could be (field1:value OR field2:value) and one secondary query (field3:anotherValue). There are more optimizations to be done on this class: continuing the previous example, if the secondary query would be (field1:value), then some type of "scorer cache" would be useful in order to avoid keeping two scorers for the same query (first clause in main query and secondary query). Comments are more than welcome.
          Hide
          Steven Bethard added a comment -

          Sorry it took so long for me to try this out, but yes, this does exactly what I need. I'd love to see the package reorganized so that this kind of thing would be easier. I'm far from a Lucene expert, but if there's anything I can do to help, let me know and I'll try to make some time for it.

          Show
          Steven Bethard added a comment - Sorry it took so long for me to try this out, but yes, this does exactly what I need. I'd love to see the package reorganized so that this kind of thing would be easier. I'm far from a Lucene expert, but if there's anything I can do to help, let me know and I'll try to make some time for it.
          Hide
          Doron Cohen added a comment -

          Patch for passing arbitrary queries to custom-score-query.
          Not intended for committing.
          See TestQueryWrapperValueSource for usage of this wrapper.

          • Doron
          Show
          Doron Cohen added a comment - Patch for passing arbitrary queries to custom-score-query. Not intended for committing. See TestQueryWrapperValueSource for usage of this wrapper. Doron
          Hide
          Doron Cohen added a comment -

          I thought I had written a class exactly for this purpose but I was wrong - my class was different in that it had an actual value source, just that it was sparse - values for quite many docs were missing. It is similar in a way, but different since here the input is a query.

          But I did promise... so I wrote a quick wrapper for a query to create a value source.
          That value source can be used to create a value source query.

          Although the patch coming soon is tested and all, I am not considering to commit this patch, because it is not clean.

          I would like to reorganize this package to take better care of this request and other related issues (like LUCENE-850) and to make it worth for Solr to move to use this package. (last time I checked it wasn't). But this is a different issue...

          Show
          Doron Cohen added a comment - I thought I had written a class exactly for this purpose but I was wrong - my class was different in that it had an actual value source, just that it was sparse - values for quite many docs were missing. It is similar in a way, but different since here the input is a query. But I did promise... so I wrote a quick wrapper for a query to create a value source. That value source can be used to create a value source query. Although the patch coming soon is tested and all, I am not considering to commit this patch, because it is not clean. I would like to reorganize this package to take better care of this request and other related issues (like LUCENE-850 ) and to make it worth for Solr to move to use this package. (last time I checked it wasn't). But this is a different issue...
          Hide
          Mike Klaas added a comment -

          This is probably related to my attempt at refactoring DisjunctionMaxQuery to be a query that performs an arbitrary function on its constituent subqueries.

          Show
          Mike Klaas added a comment - This is probably related to my attempt at refactoring DisjunctionMaxQuery to be a query that performs an arbitrary function on its constituent subqueries.

            People

            • Assignee:
              Doron Cohen
              Reporter:
              Steven Bethard
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Development