---
# System prepended metadata

title: Query matching algorithm 1

---

#  Query matching algorithm 1
Algorithm for matching input query with query template

### pre-processing on query_template

the preprocessing only depends on
- query
- orders_ignored
- synonyms

but does not depend on
- stopwords_ignored
- pubctuations_ignored

```JSON
{
    "query": "the women's jacket",
    "orders_ignored": True,
    "synonyms": {"women's": ["woman"]}
}
```

will be spanned into `spanned query dictionary`
```JSON
{
    "womens jacket": "the women's jacket",
    "woman jacket": "the women's jacket",
    "jacket womens": "the women's jacket",
    "jacket woman": "the women's jacket"
}
```

### matching
input_query will always be normalized such that
- stopwords are ignored
- pubctuations are ignored

the normalized query will be matched with `spanned query dictionary` by exact match, and will be matched to up to one query template

after finding a match, the matched query template needs to be validated, to make sure the `stopwords` and `pubctuations` could be ignored, if needed.

### Advantages
1, this can support stemming as well, which would be treated the same as stopwords/pubctuations
2, we can detect when collisions are present between query templates (when there exists one query text that can match with multiple query templates)

### Disadvantages
1, the algorithm is not very straightforward, and need a lot of caution in implementation
2, it would take more memory, for maintaining the `spanned query dictionary`