Optional first characters

I’m attempting to search by SKU number on my index. The tricky part that I’m attempting to figure out is how to allow Algolia to look at the first characters as potentially optional. In our world the first two characters represent material. Many users are accustomed to perform searches like “__6340-02-0.250-00”. That type of search should yield 5 results given my dataset. However, I receive zero results. By simply adding a character in front I get results.

Is is possible to make the first characters as optional so I can have all results returned to me?

Here is an example of a successful search query.

index.search("br6350-0_-0.250-34", {
 "hitsPerPage": "10",
 "page": "0",
 "analytics": "false",
 "attributesToRetrieve": "*",
 "facets": "[\"material.description\",\"measurement.description\",\"outsideDiameter.description\",\"profile.description\",\"screw.description\",\"unitOfMeasurement.description\"]"
});

My results from the search above are…

    {
  "hits": [
    {
      "code": "BR6350-04-0.250-34",
      "qty_on_hand": 0,
      "qty_in_demand": 0,
      "description": "3/16\" Brass Hex Spacer 1/8\" long 0.114-0.124 clearance range",
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/hexagon_brass_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-brass-hexagon-spacer-1-4in-long-0.114-0.124-clearance-range-zinc-clear-chromate-with-blue-tint/pn/BR6350-04-0.250-34",
      "material": {
        "id": 2,
        "code": "BR",
        "description": "Brass",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "brass",
        "rank": 10
      },
      "basePartId": {
        "id": 8,
        "code": "6350",
        "is_web": true,
        "status_id": 1
      },
      "clearanceHole": {
        "id": 5,
        "code": "04",
        "description": "0.114\"-0.124\"",
        "tolerance_low": 0,
        "tolerance_high": 0,
        "filter_uri": "0.114-0.124",
        "rank": 50,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 5,
        "screw_id": 15
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "overallLength": 0,
      "finish": {
        "id": 29,
        "code": "34",
        "description": "Zinc Clear Chromate with Blue Tint",
        "finish_family_id": 11,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "zinc-clear-chromate-with-blue-tint",
        "rank": 140,
        "is_rohs": true,
        "leadtime_business_days": 5
      },
      "screw": {
        "id": 15,
        "code": "4",
        "description": "#4 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "4-un",
        "rank": 25,
        "unit_of_measurement_id": 1
      },
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "profile": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "objectID": "25267",
      "_highlightResult": {
        "code": {
          "value": "<em>BR6350-0</em>4-<em>0</em><em>.250-34</em>",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "br6350",
            "0",
            "0",
            "250",
            "34"
          ]
        },
        "material": {
          "code": {
            "value": "BR",
            "matchLevel": "none",
            "matchedWords": []
          }
        },
        "basePartId": {
          "code": {
            "value": "6350",
            "matchLevel": "none",
            "matchedWords": []
          }
        },
        "clearanceHole": {
          "code": {
            "value": "<em>0</em>4",
            "matchLevel": "partial",
            "fullyHighlighted": false,
            "matchedWords": [
              "0"
            ]
          }
        },
        "measurement": {
          "code": {
            "value": "<em>0</em>.250",
            "matchLevel": "partial",
            "fullyHighlighted": false,
            "matchedWords": [
              "0"
            ]
          }
        },
        "finish": {
          "code": {
            "value": "34",
            "matchLevel": "none",
            "matchedWords": []
          }
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 0,
        "proximityDistance": 4,
        "userScore": 37482,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 4,
        "words": 5,
        "filters": 0
      }
    },
    {
      "code": "BR6350-02-0.250-34",
      "qty_on_hand": 0,
      "qty_in_demand": 0,
      "description": "3/16\" Brass Hex Spacer 1/8\" long 0.088-0.098 clearance range",
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/hexagon_brass_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-brass-hexagon-spacer-1-4in-long-0.088-0.098-clearance-range-zinc-clear-chromate-with-blue-tint/pn/BR6350-02-0.250-34",
      "material": {
        "id": 2,
        "code": "BR",
        "description": "Brass",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "brass",
        "rank": 10
      },
      "basePartId": {
        "id": 8,
        "code": "6350",
        "is_web": true,
        "status_id": 1
      },
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "overallLength": 0,
      "finish": {
        "id": 29,
        "code": "34",
        "description": "Zinc Clear Chromate with Blue Tint",
        "finish_family_id": 11,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "zinc-clear-chromate-with-blue-tint",
        "rank": 140,
        "is_rohs": true,
        "leadtime_business_days": 5
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "profile": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "objectID": "25012",
      "_highlightResult": {
        "code": {
          "value": "<em>BR6350-0</em>2-<em>0</em><em>.250-34</em>",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "br6350",
            "0",
            "0",
            "250",
            "34"
          ]
        },
        "material": {
          "code": {
            "value": "BR",
            "matchLevel": "none",
            "matchedWords": []
          }
        },
        "basePartId": {
          "code": {
            "value": "6350",
            "matchLevel": "none",
            "matchedWords": []
          }
        },
        "clearanceHole": {
          "code": {
            "value": "<em>0</em>2",
            "matchLevel": "partial",
            "fullyHighlighted": false,
            "matchedWords": [
              "0"
            ]
          }
        },
        "measurement": {
          "code": {
            "value": "<em>0</em>.250",
            "matchLevel": "partial",
            "fullyHighlighted": false,
            "matchedWords": [
              "0"
            ]
          }
        },
        "finish": {
          "code": {
            "value": "34",
            "matchLevel": "none",
            "matchedWords": []
          }
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 0,
        "proximityDistance": 4,
        "userScore": 37227,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 4,
        "words": 5,
        "filters": 0
      }
    }
  ],
  "nbHits": 2,
  "page": 0,
  "nbPages": 1,
  "hitsPerPage": 10,
  "processingTimeMS": 1,
  "facets": {
    "screw.description": {
      "#2 UN": 1,
      "#4 UN": 1
    },
    "profile.description": {
      "Spacer": 2
    },
    "material.description": {
      "Brass": 2
    },
    "measurement.description": {
      "1/4\"": 2
    },
    "outsideDiameter.description": {
      "3/16\"": 2
    },
    "unitOfMeasurement.description": {
      "Standard": 2
    }
  },
  "exhaustiveFacetsCount": true,
  "exhaustiveNbHits": true,
  "query": "br6350-0_-0.250-34",
  "params": "query=br6350-0_-0.250-34&hitsPerPage=10&page=0&analytics=false&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22material.description%22%2C%22measurement.description%22%2C%22outsideDiameter.description%22%2C%22profile.description%22%2C%22screw.description%22%2C%22unitOfMeasurement.description%22%5D&tagFilters=",
  "index": "dev-SPR",
  "serverUsed": "c7-usw-2.algolia.net",
  "indexUsed": "dev-SPR",
  "parsedQuery": "\"br6350 0\" 0 \"250 34\"",
  "timeoutCounts": false,
  "timeoutHits": false
}

Hi @jnichols,

Thanks for contacting Algolia.

Algolia was designed for prefix matching, rather than “infix” matching. But there are times, such as yours, when it can be useful. In such cases, we recommend that you create a new indexed attribute that will have an array of all the combinations of the attributes you need to partially match.

For example, if your primary attribute is sku, we recommend that you create an extra attribute called alternative_sku and add both of these attributes as Indexed attributes:

{
  "sku": "abcdef",
  "alternative_sku": ["bcdef", "cdef", "def", "ef", "f"]
}

Read more about this here.

Let us know how it goes and happy coding with Algolia!

@ajay.david,

That’s great information and I’ll certainly review it. In further research I think I found possible solution but can’t seem to implement it.

Our SKUs always include a dash. I been running into this issue when I’m missing the first two characters AND the SKU has dashes in it. The solution that produces correct results from Algolia is removing the dashes. For example a query of a SKU like “6350 02 0.250 01” produces all possible and correct results. See below for some raw examples of success.

{
  "hits": [
    ... omitted for brevity...
  },
  "exhaustiveFacetsCount": true,
  "exhaustiveNbHits": true,
  "query": "6350 02 0.250 01",
  "params": "query=6350%2002%200.250%2001&hitsPerPage=10&page=0&analytics=false&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22material.description%22%2C%22measurement.description%22%2C%22outsideDiameter.description%22%2C%22profile.description%22%2C%22screw.description%22%2C%22unitOfMeasurement.description%22%5D&tagFilters=",
  "index": "dev-SPR",
  "serverUsed": "c7-usw-2.algolia.net",
  "indexUsed": "dev-SPR",
  "parsedQuery": "6350 02 0 250 01",
  "timeoutCounts": false,
  "timeoutHits": false
}

Where I fail is when the query string includes dashes.

{
    ...
    "parsedQuery": "6350-02-0.250-01"
    ...
}

The problem is that our users will most always include the dashes as that’s how the SKU is built. But, I’m getting successful results without the dash and unfortunately just can’t modify the user’s input to omit the dashes.

How can I replace all characters that are dashes with spaces in the search query? Full disclosure that I just updated a question I asked a while ago pertaining to this situation

Hi @jnichols,

Perhaps you can give Query Expansion a shot. As Haroen mentioned, the “-” dashes actually are not the character throwing a wrench in the search (we “normalize” and do not consider punctuation at query time).

In your Dashboard, navigate to Ranking tab > scroll down to Advanced Settings > set Remove words if no results to firstWords

What is this doing? Based on your description you get zero results when you type in the first two leading letters like “BR” to create “BR6350”. Using the above rule, you’ve instructed the engine to continually remove the “first leading word in the query” until it gets results.

Why does this work? You are working around the natural language normalization of Algolia, which includes removing punctuation.

Your query of "BR6350-04-0.250-34" is actually considered a multi-word query with 5 words (“BR6350” “04” “0” “250” “34”) and Algolia is trying to match all words. The moment you include “BR6350”, Algolia cannot find a record that exactly matches all words. By removing the first word, “BR6350”, you are left with the remaining words that Algolia can match.

Let us know how it goes,
Happy coding with Algolia!

Morning @ajay.david,

Giving you an update on my dilemma. I have been UNABLE to solve my problem. I’ve been spending a couple of days attempting to get things working as I need them to and here’s what I’ve been able to determine

I needed to add appropriate suffix objects to my index. This worked out great when a user searches for “_”. In my case that was for the preceding characters for a couple of known values that customers would search for.

...
"materialSuffix": [
    "__",
    "_R",
    "B_"
  ],
  "matBaseSuffix": [
    "63_0",
    "634_"
  ],
...

I know that you say the “-” isn’t throwing a wrench in my works but when I test by leaving the dash in place my I receive zero results. Below is an example of what’s getting posted.

index.search("__6340-02-0.250-00", {
 "hitsPerPage": "10",
 "page": "0",
 "analytics": "false",
 "attributesToRetrieve": "*",
 "facets": "[\"material.description\",\"measurement.description\",\"outsideDiameter.description\",\"profile.description\",\"screw.description\",\"unitOfMeasurement.description\"]"
});

{
  "hits": [],
  "nbHits": 0,
  "page": 0,
  "nbPages": 0,
  "hitsPerPage": 10,
  "processingTimeMS": 2,
  "facets": {},
  "exhaustiveFacetsCount": true,
  "exhaustiveNbHits": true,
  "query": "__6340-02-0.250-00",
  "params": "query=__6340-02-0.250-00&hitsPerPage=10&page=0&analytics=false&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22material.description%22%2C%22measurement.description%22%2C%22outsideDiameter.description%22%2C%22profile.description%22%2C%22screw.description%22%2C%22unitOfMeasurement.description%22%5D&tagFilters=",
  "index": "spacer",
  "serverUsed": "c7-usw-2.algolia.net",
  "indexUsed": "spacer",
  "parsedQuery": "\"6340 - 02 - 0 . 250 - 00\"",
  "timeoutCounts": false,
  "timeoutHits": false
}

What has me confused is the “parsedQuery” object from the results. It appears Algolia attempting to query my index for entire string, "\"6340 - 02 - 0 . 250 - 00\"".

However, when I remove the dashes from the search Algolia is returning exactly what I expect.

index.search("__6340 02 0.250 00", {
 "hitsPerPage": "10",
 "page": "0",
 "analytics": "false",
 "attributesToRetrieve": "*",
 "facets": "[\"material.description\",\"measurement.description\",\"outsideDiameter.description\",\"profile.description\",\"screw.description\",\"unitOfMeasurement.description\"]"
});

{
  "hits": [
    {
      "code": "AA6340-02-0.250-00",
      "description": "3/16\" Aluminum Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
      "quantityAvailable": 0,
      "material": {
        "id": 1,
        "code": "AA",
        "description": "Aluminum",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "aluminum",
        "rank": 5
      },
      "profile": {
        "id": 2,
        "code": "RD",
        "description": "Round",
        "is_web": true,
        "filter_uri": "round",
        "rank": 10
      },
      "basePartId": {
        "id": 1,
        "code": "6340",
        "is_web": true,
        "status_id": 1
      },
      "overallLength": 0.25,
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "partFamily": {
        "id": 1,
        "code": "SPACER",
        "description": "Spacer",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "spacer",
        "rank": 5,
        "isSingularDescription": 0
      },
      "finish": {
        "id": 118,
        "code": "00",
        "description": "Unplated",
        "finish_family_id": 18,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "unplated",
        "rank": 585,
        "is_rohs": true,
        "leadtime_business_days": 0
      },
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/round_aluminum_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-aluminum-rohs-round-spacer-1-4in-long-0.088-0.098-clearance-range-unplated/pn/AA6340-02-0.250-00",
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0.25,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "materialSuffix": [
        "__",
        "_A",
        "A_"
      ],
      "matBaseSuffix": [
        "63_0",
        "634_"
      ],
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0.01,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "objectID": "19",
      "_highlightResult": {
        "code": {
          "value": "AA6340-<em>02</em>-<em>0.250</em>-<em>00</em>",
          "matchLevel": "partial",
          "fullyHighlighted": false,
          "matchedWords": [
            "02",
            "0",
            ".",
            "250",
            "00"
          ]
        },
        "description": {
          "value": "3/16\" Aluminum Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
          "matchLevel": "none",
          "matchedWords": []
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 2,
        "proximityDistance": 14,
        "userScore": 830,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 6,
        "words": 6,
        "filters": 0
      }
    },
    {
      "code": "BR6340-02-0.250-00",
      "description": "3/16\" Brass Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
      "quantityAvailable": 100,
      "material": {
        "id": 2,
        "code": "BR",
        "description": "Brass",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "brass",
        "rank": 10
      },
      "profile": {
        "id": 2,
        "code": "RD",
        "description": "Round",
        "is_web": true,
        "filter_uri": "round",
        "rank": 10
      },
      "basePartId": {
        "id": 1,
        "code": "6340",
        "is_web": true,
        "status_id": 1
      },
      "overallLength": 0.25,
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "partFamily": {
        "id": 1,
        "code": "SPACER",
        "description": "Spacer",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "spacer",
        "rank": 5,
        "isSingularDescription": 0
      },
      "finish": {
        "id": 118,
        "code": "00",
        "description": "Unplated",
        "finish_family_id": 18,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "unplated",
        "rank": 585,
        "is_rohs": true,
        "leadtime_business_days": 0
      },
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/round_brass_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-brass-round-spacer-1-4in-long-0.088-0.098-clearance-range-unplated/pn/BR6340-02-0.250-00",
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0.25,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "materialSuffix": [
        "__",
        "_R",
        "B_"
      ],
      "matBaseSuffix": [
        "63_0",
        "634_"
      ],
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0.01,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "objectID": "305",
      "_highlightResult": {
        "code": {
          "value": "BR6340-<em>02</em>-<em>0.250</em>-<em>00</em>",
          "matchLevel": "partial",
          "fullyHighlighted": false,
          "matchedWords": [
            "02",
            "0",
            ".",
            "250",
            "00"
          ]
        },
        "description": {
          "value": "3/16\" Brass Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
          "matchLevel": "none",
          "matchedWords": []
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 2,
        "proximityDistance": 14,
        "userScore": 254,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 6,
        "words": 6,
        "filters": 0
      }
    },
    {
      "code": "NY6340-02-0.250-00",
      "description": "3/16\" Nylon Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
      "quantityAvailable": 3608,
      "material": {
        "id": 6,
        "code": "NY",
        "description": "Nylon",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "nylon",
        "rank": 15
      },
      "profile": {
        "id": 2,
        "code": "RD",
        "description": "Round",
        "is_web": true,
        "filter_uri": "round",
        "rank": 10
      },
      "basePartId": {
        "id": 1,
        "code": "6340",
        "is_web": true,
        "status_id": 1
      },
      "overallLength": 0.25,
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "partFamily": {
        "id": 1,
        "code": "SPACER",
        "description": "Spacer",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "spacer",
        "rank": 5,
        "isSingularDescription": 0
      },
      "finish": {
        "id": 118,
        "code": "00",
        "description": "Unplated",
        "finish_family_id": 18,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "unplated",
        "rank": 585,
        "is_rohs": true,
        "leadtime_business_days": 0
      },
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/round_nylon_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-nylon-round-spacer-1-4in-long-0.088-0.098-clearance-range-unplated/pn/NY6340-02-0.250-00",
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0.25,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "materialSuffix": [
        "__",
        "_Y",
        "N_"
      ],
      "matBaseSuffix": [
        "63_0",
        "634_"
      ],
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0.01,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "objectID": "783",
      "_highlightResult": {
        "code": {
          "value": "NY6340-<em>02</em>-<em>0.250</em>-<em>00</em>",
          "matchLevel": "partial",
          "fullyHighlighted": false,
          "matchedWords": [
            "02",
            "0",
            ".",
            "250",
            "00"
          ]
        },
        "description": {
          "value": "3/16\" Nylon Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
          "matchLevel": "none",
          "matchedWords": []
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 2,
        "proximityDistance": 14,
        "userScore": 192,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 6,
        "words": 6,
        "filters": 0
      }
    },
    {
      "code": "SS6340-02-0.250-00",
      "description": "3/16\" Stainless Steel Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
      "quantityAvailable": 0,
      "material": {
        "id": 9,
        "code": "SS",
        "description": "Stainless Steel",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "stainless-steel",
        "rank": 20
      },
      "profile": {
        "id": 2,
        "code": "RD",
        "description": "Round",
        "is_web": true,
        "filter_uri": "round",
        "rank": 10
      },
      "basePartId": {
        "id": 1,
        "code": "6340",
        "is_web": true,
        "status_id": 1
      },
      "overallLength": 0.25,
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "partFamily": {
        "id": 1,
        "code": "SPACER",
        "description": "Spacer",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "spacer",
        "rank": 5,
        "isSingularDescription": 0
      },
      "finish": {
        "id": 118,
        "code": "00",
        "description": "Unplated",
        "finish_family_id": 18,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "unplated",
        "rank": 585,
        "is_rohs": true,
        "leadtime_business_days": 0
      },
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/round_stainless-steel_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-stainless-steel-round-spacer-1-4in-long-0.088-0.098-clearance-range-unplated/pn/SS6340-02-0.250-00",
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0.25,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "materialSuffix": [
        "__",
        "_S",
        "S_"
      ],
      "matBaseSuffix": [
        "63_0",
        "634_"
      ],
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0.01,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "objectID": "817",
      "_highlightResult": {
        "code": {
          "value": "SS6340-<em>02</em>-<em>0.250</em>-<em>00</em>",
          "matchLevel": "partial",
          "fullyHighlighted": false,
          "matchedWords": [
            "02",
            "0",
            ".",
            "250",
            "00"
          ]
        },
        "description": {
          "value": "3/16\" Stainless Steel Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
          "matchLevel": "none",
          "matchedWords": []
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 2,
        "proximityDistance": 14,
        "userScore": 106,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 6,
        "words": 6,
        "filters": 0
      }
    },
    {
      "code": "ST6340-02-0.250-00",
      "description": "3/16\" Steel Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
      "quantityAvailable": 0,
      "material": {
        "id": 10,
        "code": "ST",
        "description": "Steel",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "steel",
        "rank": 25
      },
      "profile": {
        "id": 2,
        "code": "RD",
        "description": "Round",
        "is_web": true,
        "filter_uri": "round",
        "rank": 10
      },
      "basePartId": {
        "id": 1,
        "code": "6340",
        "is_web": true,
        "status_id": 1
      },
      "overallLength": 0.25,
      "unitOfMeasurement": {
        "id": 1,
        "code": "IN",
        "description": "Standard",
        "is_web": true,
        "filter_uri": "inch",
        "rank": 5
      },
      "partType": {
        "id": 1,
        "part_family_id": 1,
        "code": "SPR",
        "description": "Spacer",
        "status_id": 1,
        "is_family": true,
        "is_web": true,
        "filter_uri": "spacer",
        "regex_format": "/(?<Material>[A-Z]{2})(?<PartBasePart>[0-9]{4})-(?<ClearanceHole>[0-9]{2})-(?<Measurement>[0-9]*\\.[0-9]{1,3})-(?<Finish>[0-9A-Z]{2,4})/",
        "rank": null,
        "is_list_viewable": false,
        "customize_me_layout_id": 4,
        "is_customizable": true,
        "isDescriptionSingular": false
      },
      "partFamily": {
        "id": 1,
        "code": "SPACER",
        "description": "Spacer",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "spacer",
        "rank": 5,
        "isSingularDescription": 0
      },
      "finish": {
        "id": 118,
        "code": "00",
        "description": "Unplated",
        "finish_family_id": 18,
        "status_id": 1,
        "is_web": true,
        "filter_uri": "unplated",
        "rank": 585,
        "is_rohs": true,
        "leadtime_business_days": 0
      },
      "image": "https://lyntron-images.s3.amazonaws.com/products/spacer/iso/round_steel_spacer_medium.png",
      "url": "https://www.lyntron.com/3-16in-steel-round-spacer-1-4in-long-0.088-0.098-clearance-range-unplated/pn/ST6340-02-0.250-00",
      "outsideDiameter": {
        "id": 4,
        "description": "3/16\"",
        "rank": 20,
        "filter_uri": "3-16",
        "is_web": true,
        "status_id": 1,
        "unit_of_measurement_id": 1,
        "unit_of_measurement_suffix_id": 1,
        "decimal": "0.187",
        "code": null
      },
      "measurement": {
        "id": 299,
        "code": "0.250",
        "fractional": "1/4",
        "decimal": 0.25,
        "unit_of_measurement_id": 1,
        "millimeter": null,
        "is_web": true,
        "rank": 110,
        "description": "1/4\"",
        "filter_uri": "1-4in"
      },
      "materialSuffix": [
        "__",
        "_T",
        "S_"
      ],
      "matBaseSuffix": [
        "63_0",
        "634_"
      ],
      "clearanceHole": {
        "id": 3,
        "code": "02",
        "description": "0.088\"-0.098\"",
        "tolerance_low": 0,
        "tolerance_high": 0.01,
        "filter_uri": "0.088-0.098",
        "rank": 30,
        "is_web": true,
        "unit_of_measurement_id": 1,
        "tolerance_id": 3,
        "screw_id": 8
      },
      "screw": {
        "id": 8,
        "code": "2",
        "description": "#2 UN",
        "status_id": 1,
        "is_web": true,
        "filter_uri": "2-un",
        "rank": 15,
        "unit_of_measurement_id": 1
      },
      "objectID": "933",
      "_highlightResult": {
        "code": {
          "value": "ST6340-<em>02</em>-<em>0.250</em>-<em>00</em>",
          "matchLevel": "partial",
          "fullyHighlighted": false,
          "matchedWords": [
            "02",
            "0",
            ".",
            "250",
            "00"
          ]
        },
        "description": {
          "value": "3/16\" Steel Round Spacer 1/8\" Long 0.088\"-0.098\" Clearance Range Unplated",
          "matchLevel": "none",
          "matchedWords": []
        }
      },
      "_rankingInfo": {
        "nbTypos": 0,
        "firstMatchedWord": 2,
        "proximityDistance": 14,
        "userScore": 33,
        "geoDistance": 0,
        "geoPrecision": 1,
        "nbExactWords": 6,
        "words": 6,
        "filters": 0
      }
    }
  ],
  "nbHits": 5,
  "page": 0,
  "nbPages": 1,
  "hitsPerPage": 10,
  "processingTimeMS": 1,
  "facets": {
    "screw.description": {
      "#2 UN": 5
    },
    "profile.description": {
      "Round": 5
    },
    "material.description": {
      "Aluminum": 1,
      "Brass": 1,
      "Nylon": 1,
      "Stainless Steel": 1,
      "Steel": 1
    },
    "measurement.description": {
      "1/4\"": 5
    },
    "outsideDiameter.description": {
      "3/16\"": 5
    },
    "unitOfMeasurement.description": {
      "Standard": 5
    }
  },
  "exhaustiveFacetsCount": true,
  "exhaustiveNbHits": true,
  "query": "__6340 02 0.250 00",
  "params": "query=__6340%2002%200.250%2000&hitsPerPage=10&page=0&analytics=false&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22material.description%22%2C%22measurement.description%22%2C%22outsideDiameter.description%22%2C%22profile.description%22%2C%22screw.description%22%2C%22unitOfMeasurement.description%22%5D&tagFilters=",
  "index": "spacer",
  "serverUsed": "c7-usw-2.algolia.net",
  "indexUsed": "spacer",
  "parsedQuery": "6340 02 \"0 . 250\" 00",
  "timeoutCounts": false,
  "timeoutHits": false
}

So, because of these results I started to investigate the way I could remove dashes from my search item before I post to Algolia. Further research showed that I couldn’t do that. Where do I go from here?

Hey @jnichols,

How about trying to add the “alternative_code” field which we talked about above. It’s an array of values, where each value removes one character from the “code” attribute.

As shown below, in a test index with objects based on yours, it seems to do the trick. I get 5 hits when I search without hyphens, and I get 5 hits when I search with hyphens.

Let me know how it goes!

THANK YOU @ajay.david for getting back to me.

I created a new index and implemented your suggestion. I modified my JSON object to include a new array called “codeSuffix” that mimics your “alternative_code” field.

As you can see with my attachment things work as you described. Right up until I introduce the “" as a placeholder. The combination with the "” and the “-” (dashes) produce zero results. As soon as I remove the dashes the correct result is found.

For example, when I put a complete SKU (br6340-02-0.250-00) into search, exactly one result found. As expected. When I replace a selected character for the “_” the correct return result count is 2. As expected. This only happens when I remove the dashes from the query string.

All the help you’ve been able to provide is greatly appreciated. I feel that I’m missing something obviously with this problem.

What do you think?

Hi @jnichols,

Let’s give this a shot - we’ll add another attribute to help recognize the new query word that results from the blank space (" “) you put in AND we’ll turn of advanced syntax, otherwise the leading hyphen (”-") tells the search engine to remove results that contain the query word leading with the hyphen (e.g., “-0.250-00” means do not give me results with this word):

  • codePrefix - Just like you made “codeSuffix”, create the “codePrefix” array of values which does the opposite, removing one character from the back one-by-one. For example, “B6340-02-0.250-00” would have:

    “codePrefix”: [
    “BR6340-02-0.250-0”,
    “BR6340-02-0.250-”,
    “BR6340-02-0.250”,
    “BR6340-02-0.25”,
    “BR6340-02-0.2”,
    “BR6340-02-0”,
    “BR6340-02-”,
    “BR6340-02”,
    “BR6340-0”,
    “BR6340-”,
    “BR6340”,
    “BR634”,
    “BR63”,
    “BR6”
    ]

  • Ranking Tab - try these settings: Prefix Search => prefixAll ; Advanced syntax => FALSE

Let us know how it goes!

@ajay.david

I think that did it! I put it through QA here and the users approve of the format. Perfect!

1 Like

You can create a custom source for autocomplete, the current Algolia one is pretty straightforward so you can copy it, replace the characters and send the query.

@haroen -
Thanks for the feedback. I believe that the previous suggestion from @ajay.david made appears to be working for us.

1 Like