分面搜索界面为用户提供了一种通过选择与查询相关的类别来快速缩小搜索结果的方法。
{ "id": 5, "title": "Hard Times", "genres": ["Classics","Fiction", "Victorian", "Literature"], "publisher": "Penguin Classics", "language": "English", "author": "Charles Dickens", "description": "Hard Times is a novel of social […] ", "format": "Hardcover", "rating": 3 }
curl \ -X PUT 'MEILISEARCH_URL/indexes/books/settings/filterable-attributes' \ -H 'Content-Type: application/json' \ --data-binary '[ "genres", "rating", "language" ]'
curl \ -X POST 'MEILISEARCH_URL/indexes/books/search' \ -H 'Content-Type: application/json' \ --data-binary '{ "q": "classic", "facets": [ "genres", "rating", "language" ] }'
{ "hits": [ … ], … "facetDistribution": { "genres": { "Classics": 6, … }, "language": { "English": 6, "French": 1, "Spanish": 1 }, "rating": { "2.5": 1, … } }, "facetStats": { "rating": { "min": 2.5, "max": 4.7 } } }
curl \ -X PATCH 'MEILISEARCH_URL/indexes/books/settings/faceting' \ -H 'Content-Type: application/json' \ --data-binary '{ "sortFacetValuesBy": { "genres": "count" } }'
{ … "facetDistribution": { "genres": { "Fiction": 8, "Literature": 7, "Classics": 6, "Novel": 2, "Horror": 2, "Fantasy": 2, "Victorian": 2, "Vampires": 1, "Tragedy": 1, "Satire": 1, "Romance": 1, "Historical Fiction": 1, "Coming-of-Age": 1, "Comedy": 1 }, … } }
curl \ -X POST 'MEILISEARCH_URL/indexes/books/facet-search' \ -H 'Content-Type: application/json' \ --data-binary '{ "facetQuery": "c", "facetName": "genres" }'
{ … "facetHits": [ { "value": "Children's Literature", "count": 1 }, { "value": "Classics", "count": 6 }, { "value": "Comedy", "count": 2 }, { "value": "Coming-of-Age", "count": 1 } ], "facetQuery": "c", … }
此页面有帮助吗?