Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-51059

SEARCH_META().score behaves different from SEARCH_SCORE() in some N1QL queries

    XMLWordPrintable

Details

    • 1

    Description

      SEARCH_META().score should be the same as SEARCH_SCORE() but in some N1QL queries they behave differently.

      I used both "Enterprise Edition 7.0.3 build 7031" and a current Neo build both behave the same.   I load `travel-sample` and then make a full text index as per the attached image.

      Consider the two queries they differ only by ASC and DESC, but the behave the same

      SELECT SEARCH_META() AS meta -- (1)
      FROM `travel-sample`.inventory.hotel AS t1
      WHERE SEARCH(t1, {
        "query": {
          "match": "bathrobes",
          "field": "reviews.content",
          "analyzer": "standard"
        },
        "includeLocations": true -- (2)
      })
      ORDER BY SEARCH_SCORE() ASC
      LIMIT 3;

      and

      SELECT SEARCH_META() AS meta -- (1)
      FROM `travel-sample`.inventory.hotel AS t1
      WHERE SEARCH(t1, {
        "query": {
          "match": "bathrobes",
          "field": "reviews.content",
          "analyzer": "standard"
        },
        "includeLocations": true -- (2)
      })
      ORDER BY SEARCH_SCORE() DESC
      LIMIT 3;

      Both return the same thing

      id    locations.reviews.content.bathrobes    score
      "hotel_17598"    [{"array_positions":[1],"end":228,"pos":46,"start":219}]    0.43525234893144843
      "hotel_38018"    [{"array_positions":[2],"end":495,"pos":93,"start":486}]    0.22043954642603641
      "hotel_3622"    [{"array_positions":[2],"end":615,"pos":107,"start":606}]    0.1765223381254734
      

      and

      id    locations.reviews.content.bathrobes    score
      "hotel_17598"    [{"array_positions":[1],"end":228,"pos":46,"start":219}]    0.43525234893144843
      "hotel_38018"    [{"array_positions":[2],"end":495,"pos":93,"start":486}]    0.22043954642603641
      "hotel_3622"    [{"array_positions":[2],"end":615,"pos":107,"start":606}]    0.1765223381254734
      

      Not the same ordering and also missing items compared to the next two queries

       

      But is we switch from ORDER BY SEARCH_SCORE() ... to ORDER BY SEARCH_META().score ... things look much better.  

      SELECT SEARCH_META() AS meta -- (1)
      FROM `travel-sample`.inventory.hotel AS t1
      WHERE SEARCH(t1, {
        "query": {
          "match": "bathrobes",
          "field": "reviews.content",
          "analyzer": "standard"
        },
        "includeLocations": true -- (2)
      })
      ORDER BY SEARCH_META().score ASC
      LIMIT 3;

      and

      SELECT SEARCH_META() AS meta -- (1)
      FROM `travel-sample`.inventory.hotel AS t1
      WHERE SEARCH(t1, {
        "query": {
          "match": "bathrobes",
          "field": "reviews.content",
          "analyzer": "standard"
        },
        "includeLocations": true -- (2)
      })
      ORDER BY SEARCH_META().score DESC
      LIMIT 3;

      We get the expected results

      id    locations.reviews.content.bathrobes    score
      "hotel_9084"    [{"array_positions":[2],"end":400,"pos":70,"start":391}]    0.17445527106812114
      "hotel_3622"    [{"array_positions":[2],"end":615,"pos":107,"start":606}]    0.1765223381254734
      "hotel_25672"    [{"array_positions":[2],"end":1058,"pos":188,"start":1049}]    0.18795973076338596
      

      and

      id    locations.reviews.content.bathrobes    score
      "hotel_17598"    [{"array_positions":[1],"end":228,"pos":46,"start":219}]    0.43525234893144843
      "hotel_38019"    [{"array_positions":[0],"end":303,"pos":53,"start":294}]    0.398050970471638
      "hotel_40017"    [{"array_positions":[4],"end":875,"pos":157,"start":866}]    0.24657351327024343
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            girish.benakappa Girish Benakappa
            jon.strabala Jon Strabala
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty