Using Facet Information

You can display facet information to enable users to more easily browse search results and zero in on the information they are interested in. For example, if a user is trying to find a reading standard, but can't remember the full description, he might start by searching for "read". If you want to display top facets for subject and education level, you would specify those facets in the query, along with the number of facet values you want to retrieve for each facet:

../search?q=read&facet=fct_education_level,fct_subject&facet-fct_education_level-top-n=10&facet-fct_subject-top-n=5&size=5

This gives you the following information in the search response:

{
  "results": {
    "rank": "-text_relevance",
    "match-expr": "(label 'read')",
    "hits": {
      "-found": "13164",
      "-start": "0",
      "hit": [
        { "-id": "s2375097" },
        { "-id": "s2375078" },
        { "-id": "s2375081" },
        { "-id": "s2375083" },
        { "-id": "s2375080" }
      ]
    },
    "facets": {
      "facet": [
        {
          "-name": "fct_education_level",
          "constraint": [
            {
              "-value": "6",
              "-count": "2147"
            },
            {
              "-value": "7",
              "-count": "2088"
            },
            {
              "-value": "8",
              "-count": "2068"
            },
            {
              "-value": "9",
              "-count": "2056"
            },
            {
              "-value": "10",
              "-count": "2048"
            },
            {
              "-value": "3",
              "-count": "1988"
            },
            {
              "-value": "5",
              "-count": "1983"
            },
            {
              "-value": "4",
              "-count": "1948"
            },
            {
              "-value": "1",
              "-count": "1876"
            },
            {
              "-value": "11",
              "-count": "1862"
            }
          ]
        },
        {
          "-name": "fct_subject",
          "constraint": [
            {
              "-value": "English",
              "-count": "10644"
            },
            {
              "-value": "The Arts",
              "-count": "1331"
            },
            {
              "-value": "Math",
              "-count": "746"
            },
            {
              "-value": "Social Studies",
              "-count": "184"
            },
            {
              "-value": "Science",
              "-count": "104"
            }
          ]
        }
      ]
    },
    "info": {
      "-rid": "9aef9a529c6e9b0b6069cc55e0fc5ede31b58ce864edcbfdd0858a89a302e401ef5c76d7ff569716",
      "-time-ms": "92",
      "-cpu-time-ms": "0"
    }
  }
}

Using the item ids, you can retrieve the data you want to display for each hit from a separate system. By displaying the facet information, you can provide a way for the user to zero on the item they are looking for. To retrieve a subset, you can use the bq search parameter to perform a fielded search against education_level '9' and find the matches.

../search?bq=(and 'read' fct_education_level:'9')&facet=fct_subject&facet-fct_subject-top-n=10

This retrieves the subset of hits along with the subject facet information:

{
  "results": {
    "rank": "-text_relevance",
    "match-expr": "(and 'read' fct_education_level:'9')",
    "hits": {
      "-found": "2056",
      "-start": "0",
      "hit": [
        { "-id": "s2375097" },
        { "-id": "s2375083" },
        { "-id": "s2375081" },
        { "-id": "s2375078" },
        { "-id": "s2375080" },
        { "-id": "s1049e29" },
        { "-id": "s1049e28" },
        { "-id": "s1049e25" },
        { "-id": "s104ad24" },
        { "-id": "s1138705" }
      ]
    },
    "facets": {
      "facet": {
        "-name": "fct_subject",
        "constraint": [
          {
            "-value": "English",
            "-count": "1209"
          },
          {
            "-value": "The Arts",
            "-count": "596"
          },
          {
            "-value": "Science",
            "-count": "59"
          },
          {
            "-value": "Math",
            "-count": "48"
          },
          {
            "-value": "Foreign Languange",
            "-count": "47"
          },
          {
            "-value": "Social Studies",
            "-count": "44"
          },
          {
            "-value": "Career Education",
            "-count": "16"
          },
          {
            "-value": "Technology",
            "-count": "4"
          },
          {
            "-value": "Historical Understanding",
            "-count": "2"
          },
          {
            "-value": "Economics",
            "-count": "1"
          }
        ]
      }
    },
    "info": {
      "-rid": "9aef9a529c6e9b0b6069cc55e0fc5ede81500673fb17dd2d81a4d2c3dc255d472126af81feba4228",
      "-time-ms": "11",
      "-cpu-time-ms": "0"
    }
  }
}

At this point, the user might filter to only subject English. Again, you would use his selection to further refine the query:

../search?bq=(and 'read' fct_education_level:'9' fct_subject:'English')

Which results in:

{
  "results": {
    "rank": "-text_relevance",
    "match-expr": "(and 'read' fct_education_level:'9' fct_subject:'English')",
    "hits": {
      "-found": "1209",
      "-start": "0",
      "hit": [
        { "-id": "s1138705" },
        { "-id": "s100090e" },
        { "-id": "s113869b" },
        { "-id": "s100b1aa" },
        { "-id": "s1023f5f" },
        { "-id": "s100108e" },
        { "-id": "s1015cb0" },
        { "-id": "s100495e" },
        { "-id": "s1039eda" },
        { "-id": "s100e2e2" }
      ]
    },
    "info": {
      "-rid": "9aef9a529c6e9b0b6069cc55e0fc5ede5d4e9207ba8681cf1637f764b3c1f74c5b5034d372191dd3",
      "-time-ms": "10",
      "-cpu-time-ms": "0"
    }
  }
}