Sorting and Filtering your Queries using Attributes

Modified on Thu, 18 May 2023 at 02:27 PM

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_id variable. If a part matches any of the names or 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_id: ["Infineon"],  numberofpins: ["(8__16)"] }){
        hits
        results{
              ....


Here is a full example to copy and try.


query{
  supSearch(
    filters: {manufacturer_id: ["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.


Filtering Behaviour

There is some behaviour worth noting when filtering. Our API supports lists of individual values as seen in example 1, or a single range, seen in example 2.

Whilst you are able to carry out OR behaviour in a filter, there are caveats when it comes to working with ranges, as seen in examples 3 and 4.


Example 1:

This will return the number of parts that have 8 pins, or that have 16 pins. 

numberofpins: ["8", "16"] 

 

Example 2:
This will return the number of parts that have 8 to 16 pins.
numberofpins: ["(8__16)"]


Example 3: 

These will return 0 results. In the case where you want to filter for example 8 to 16 pin OR 24 pin components, we would recommend a catch-all on components with 8 to 24 pins, before users can apply post-filtering on the results of the query.

numberofpins: ["(8__16)", "24"]

numberofpins:["(__16)", "24"]


Example 4:

This will return components with 16 pins only. 

numberofpins: ["(8__16)", "(16__24)"]

Units

Filtering also works with SI Units, following the OR behaviour as above.

capacitance: ["(1.5E-12__1.6E-12)"] 


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