doofinder/php-doofinder

Implement facet sort indicator

Closed this issue · 5 comments

Hy doofinder Team,

is it possible to get the facet sort indicator, when using the Search API?

For example like this:

"facets": {
    "size": {
      "sort": 1,    //_<=_sort_indicator
      "total": {
        "value": 41
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": [
          ...
        ]
      },
      "doc_count": 76
    },
    "price": {
      "sort": 4,
      "range": {
        "buckets": [
          {
            "stats": {
              "sum": 10068.670000076294,
              "min": 10.0,
              "max": 765.0,
              "count": 76,
              "avg": 132.48250000100387
            },
            "key": "0.0-*",
            "from": 0.0,
            "doc_count": 76
          }
        ]
      },
      "doc_count": 76
    },
    "plattform": {
      "sort": 7,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "material": {
      "sort": 6,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "genre": {
      "sort": 8,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "g:availability_label": {
      "sort": 3,
      "total": {
        "value": 76
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    },
    "color": {
      "sort": 2,
      "total": {
        "value": 26
      },
      "terms": {
        "sum_other_doc_count": 8,
        "doc_count_error_upper_bound": 0,
        "buckets": [
          ...
        ]
      },
      "doc_count": 76
    },
    "categories": {
      "sort": 0,
      "total": {
        "value": 77
      },
      "terms": {
        "sum_other_doc_count": 6,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    },
    "brand": {
      "sort": 5,
      "total": {
        "value": 74
      },
      "terms": {
        "sum_other_doc_count": 19,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    }
  }

Hi @sPooKee, sorry for the delay. Do you mean the order of appearance of the facets? Like defined in the Doofinder admin?

@carlosescri yes, exactly ;-)

screen shot 2018-10-22 at 14 49 27

Ok, I understand now. We have an endpoint in the search servers we use for the layers. It's not documented yet because it may change too frequently. For instance, it will change in a few days because we're removing a redirections key that now goes in the search response.

The URL is something like (you'll have to authenticate with a valid API token):

https://<zone>-search.doofinder.com/5/options/<hashid>

In the response you have a facets key which contains an array of facets configuration.

I'm going to make a proposal to normalize and document that endpoint so we can add it to this library.

In the meantime I suggest you to make use of that endpoint by your own means but with code that has some kind of fallback in case the response changes (because if it's not documented, it doesn't exist, you know 😉).

A bit late but we're studying the possibility of adding a score to facets which will help with this ordering issue. We will use it for advanced features but a default value could be based on the definition order in the admin. I don't promise anything.

Facets sorting has been added to the search response so this should be fixed.