> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# QueryService

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/5/app-studio/reference/services/lightning.QueryService

[mintlify link]: https://doc.lucidworks.com/docs/5/app-studio/reference/services/lightning.QueryService

[old doc.lw link]: https://doc.lucidworks.com/app-studio/4.2/1207

<LwTemplate />

## Description

Twigkit service for queries

## Methods

### clearQueries()

Will remove all the queries from the factory.

#### Example

```js wrap  theme={"dark"}
QueryService.clearQueries();
```

### convertHttpParamsToQuery(httpParams)

Converts http params to query value..

#### Parameters

| Param      | Type   | Details                      |
| ---------- | ------ | ---------------------------- |
| httpParams | object | The httpParams of the query. |

#### Example

```js wrap  theme={"dark"}
QueryService.convertHttpParamsToQuery(value);
```

### convertHttpParamsToUrl(httpParams)

Converts http params into a URL.

#### Parameters

| Param      | Type   | Details                       |
| ---------- | ------ | ----------------------------- |
| httpParams | object | A query object as http params |

#### Example

```js wrap  theme={"dark"}
QueryService.convertHttpParamsToUrl(query, true);
```

### convertQueryToHttpParams(query, excludeHiddenFilters)

Converts an object based query to HTTP Params.

#### Parameters

| Param                             | Type    | Details                                          |
| --------------------------------- | ------- | ------------------------------------------------ |
| query                             | object  | Query to convert                                 |
| excludeHiddenFilters *(optional)* | boolean | Whether to include hidden filters in the params. |

#### Returns

|        |                                          |
| ------ | ---------------------------------------- |
| object | Returns the query object as http params. |

#### Example

```js wrap  theme={"dark"}
QueryService.convertQueryToHttpParams(query);
```

### convertQueryToUrl(query, includeHiddenFilters)

Converts query object into a URL, encoding necessary values correctly and optionally removing hidden filters

#### Parameters

| Param                | Type    | Details                                      |
| -------------------- | ------- | -------------------------------------------- |
| query                | object  | The query object.                            |
| includeHiddenFilters | boolean | Whether to include hidden filters in the URL |

#### Example

```js wrap  theme={"dark"}
QueryService.convertQueryToUrl(query, true);
```

### convertSortObjectToParam()

Will convert sort object into a parameter.

#### Example

```js wrap  theme={"dark"}
QueryService.convertSortObjectToParam(obj);
```

### convertSortParamToObject()

Will convert sort parameter into an object.

#### Example

```js wrap  theme={"dark"}
QueryService.convertSortParamToObject(param);
```

### getQuery(name)

Gets the value of the query from the factory. If no query is found, the factory will return null.

#### Parameters

| Param | Type   | Details                        |
| ----- | ------ | ------------------------------ |
| name  | string | Name of the query to retrieve. |

#### Returns

|        |                                                                          |
| ------ | ------------------------------------------------------------------------ |
| object | Returns the query object, if no query object exists it will return null. |

#### Example

```js wrap  theme={"dark"}
QueryService.getQuery(name);
```

### getQueryAsHttpParams(name, excludeHiddenFilters)

Gets the value of the query from the factory. If no query is found, the factory will return null.

#### Parameters

| Param                             | Type    | Details                                          |
| --------------------------------- | ------- | ------------------------------------------------ |
| name                              | string  | Name of the query to retrieve.                   |
| excludeHiddenFilters *(optional)* | boolean | Whether to include hidden filters in the params. |

#### Returns

|        |                                                                          |
| ------ | ------------------------------------------------------------------------ |
| object | Returns the query object, if no query object exists it will return null. |

#### Example

```js wrap  theme={"dark"}
QueryService.getQueryAsHttpParams(name);
```

### queryContainsFilterForField(query, fieldName, filter)

Will identify if the query contains the filter.

#### Parameters

| Param     | Type   | Details               |
| --------- | ------ | --------------------- |
| query     | object | The query object.     |
| fieldName | string | The name of the field |
| filter    | object | The filter object     |

#### Example

```js wrap  theme={"dark"}
QueryService.queryContainsFilterForField(query, fieldName, filter);
```

### removeFiltersForField(query, fieldName)

Will remove any filters relating to the field name

#### Parameters

| Param     | Type   | Details               |
| --------- | ------ | --------------------- |
| query     | object | The query object.     |
| fieldName | string | The name of the field |

#### Example

```js wrap  theme={"dark"}
QueryService.removeFiltersForField(query, fieldName);
```

### setQuery(name, value)

Adds the query value to the factory.

#### Parameters

| Param | Type   | Details                        |
| ----- | ------ | ------------------------------ |
| name  | string | Name to store the query under. |
| value | object | The value of the query.        |

#### Example

```js wrap  theme={"dark"}
QueryService.setQuery(name,value);
```

## Events

### query\_name\_updated

When the query is set or changed Lightning will broadcast this message where name is the name of your query `query_name_updated`

#### Type:

broadcast

#### Target:

root scope
