Sorting and Filtering your Queries using Attributes

Modified on Thu, 02 Feb 2023 at 10:25 AM

To get the information you need from your supply query you can use attributes which are listed here on Octopart. You can either sort or filter your query results by these attributes. 


Sorting:


In the example below using a supSearch the "sort" function is used. You can also use the "sortDIr" function to sort in the order you would like it to (asc/desc).  


query SupSearch{
     supSearch(sort: "maxoutputvoltage", sortDir: desc) {
          hits
          results{
                ....


Filtering:



Below is an example using filtering. In this example there are two filters divided by a comma. The first filter looks for exact matches for the manufacturer_name variable. If a part matches any of the ids listed it will come up in the query. The second filter looks for parts with between 8 and 16 "numberofpins" inclusive. The syntax is:


                   numberofpins: ["(8__16)"]  == numberofpins in range 8 to 16 inclusive

                    

                   numberofpins: ["(__8)"]  == numberofpins less than or equal to 8


                    numberofpins: ["(16__)"]  == numberofpins greater than or equal to 16


Note: it's a double underscore between the numbers.


query{
  supSearch(
    filters: { manufacturer_name: ["Infineon"],  numberofpins: ["(8__16)"] }){
        hits
        results{
              ....


Here is a full example to copy and try.


query{
  supSearch(
    filters: {manufacturer_name: ["Infineon"],  numberofpins:["(8__16)"]}
    limit: 4
    sort: "numberofpins"
    sortDir: asc
  ) {
    hits
    results {
      part {
        mpn
        manufacturer {
          name
          id
        }
        specs{
          attribute {
            shortname
          }
          displayValue
        }
      }
    }
  }
}


Note: filtering by sellers will return all offers for parts that are sold by that seller not just the offers for that seller.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article