# Find products by field value

**URL:** <https://forum.litium.com/t/find-products-by-field-value/3149>\
**Category:** Questions\
**Tags:** litium-8\
**Created:** [November 15, 2023, 4:01pm UTC](https://forum.litium.com/t/find-products-by-field-value/3149 "2023-11-15T16:01:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/samuel/32/479_2.png) [@samuel](https://forum.litium.com/u/samuel)\
**Post date:** [November 15, 2023, 4:01pm UTC](https://forum.litium.com/t/find-products-by-field-value/3149/1 "2023-11-15T16:01:35Z")

</div>

What would be the most efficient way to find products with a specific field value? We need to do it from a place where there’s no channel, country or anything like that.

Litium version: 8.12

---

<div class="post-metadata">

**Author:** ![erlin93](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@erlin93](https://forum.litium.com/u/erlin93)\
**Post date:** [November 17, 2023, 8:01am UTC](https://forum.litium.com/t/find-products-by-field-value/3149/2 "2023-11-17T08:01:56Z")

</div>

Can try a search like

```auto
      var searchQuery = new SearchQuery
                {
                    Tags = new Dictionary<string, ISet<string>>
                    {
                       { "Id", new HashSet<string> { "value" }}
                    }
                };

                var searchResult = _productSearchService.SearchAsync(searchQuery, searchQuery.Tags).Result;
                var result = searchResult.Items.Value.Cast<ProductSearchResult>()
                    .Select(c => _productItemViewModelBuilder.Build(c.Item));

```

---

<div class="post-metadata">

**Author:** ![samuel](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/samuel/32/479_2.png) [@samuel](https://forum.litium.com/u/samuel)\
**Post date:** [November 17, 2023, 9:05am UTC](https://forum.litium.com/t/find-products-by-field-value/3149/3 "2023-11-17T09:05:41Z")

</div>

That was my first approach. It works fine as long as the call originates from a controller or somewhere else where channel and country are set (might be some other values as well) and can be accessed from RouteRequestLookupInfoAccessor and RequestModelAccessor. ProductSearchService.SearchAsync calls SearchQueryBuilder that needs these values when building the query.

In our case we need to call it from an EventBroker event and then we don’t have any channel or country. This makes SearchQueryBuilder to throw an error.

We can use DataService of course but I was hoping for an other way.

---

<div class="post-metadata">

**Author:** ![Totte](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@Totte](https://forum.litium.com/u/Totte)\
**Post date:** [November 27, 2023, 9:28am UTC](https://forum.litium.com/t/find-products-by-field-value/3149/4 "2023-11-27T09:28:43Z")

</div>

My code might differ with yours, but when I look in the `BuildQuery` function in `ProductSearchServiceDecorator.cs` I can pass a bool `addDefaultQuery` and set it to `false`.

Then atleast my code will skip all the channel context specific data, like `channelSystemId`.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [December 25, 2023, 9:28am UTC](https://forum.litium.com/t/find-products-by-field-value/3149/5 "2023-12-25T09:28:57Z")

</div>

Closed on December 25, 2023, 9:28am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
