<!-- Source: https://docs.squirro.com/en/latest/api/squirro.lib.nlp.apps.query_processing.QueryModifier.html -->
# QueryModifier

**`class QueryModifier(config)`**

Bases: [`BatchedStep`](../technical/libnlp/steps/standard.md#squirro.lib.nlp.steps.batched_step.BatchedStep)

Modify raw query using metadata collected from prior steps.

Parameters

- `step` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"app"`) – app
- `type` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"query_processing"`) – query_processing
- `name` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"query_modifier"`) – query_modifier
- `raw_input_field` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"query"`) – raw user query to modify
- `term_mutations_metadata` ([`list`](https://docs.python.org/3.11/library/stdtypes.html#list)`, ``[``"term_expansion_mutations"``,``"pos_mutations"``]`) – mutations applied, order matters
- `output_field` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"enriched_query"`) – the modified query string
- `path` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``"."`) – schema expects path where step file is located. not used actually

Attributes SummaryMethods SummaryAttributes Documentation

**`REMOVE_PUNCTUATION = '!"\\#\\$%\\&\'\\(\\)\\*\\+,\\-\\./:;<=>\\?@\\[\\\\\\]\\^_`\\{\\|\\}\\~'`**

Methods Documentation

**`static append_string(raw_query_string, mutations)`**

Concatenate mutations (act as filter) with raw-query-string.

**`process_doc(doc)`**

Process a document

Parameters

`doc` ([`Document`](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)) – Document

Returns

Processed document

Return type

[Document](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)

**`replace_by_key_value(raw_query_string, mutations)`**

Apply mutations as defined from prior steps on raw_query_string.

Return type

[`str`](https://docs.python.org/3.11/library/stdtypes.html#str)

**Note: The whole approach of mutation-dicts & regex-matching on the raw-query-string is not ideal.**

Reason for that approach is to consider/keep to user’s original query syntax in place, like logical
grouping clauses.
user query:           (phone AND apple)
possible rewritten:   (phone^10 AND (apple^5 OR “Apple Inc.”^0.7)
