# Extend search index

**URL:** https://forum.litium.com/t/extend-search-index/1875
**Category:** Questions
**Created:** [February 5, 2021, 12:58pm UTC](https://forum.litium.com/t/extend-search-index/1875 "2021-02-05T12:58:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)
#### Post date: [February 5, 2021, 12:58pm UTC](https://forum.litium.com/t/extend-search-index/1875/1 "2021-02-05T12:58:19Z")

</div>

How can I extend searchindex (per variant) to contain more data than it has today?  
I want to add WareHouseID - InStockQuantity - ErpStatus to easier add a filter for product listning “Only show products in stock”

Litium version: 7.4

---

<div class="post-metadata">

### Author: ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)
#### Post date: [February 5, 2021, 2:27pm UTC](https://forum.litium.com/t/extend-search-index/1875/2 "2021-02-05T14:27:07Z")

</div>

(Assuming you are using [Lucene.NET](http://Lucene.NET))

Quantity for each warehouse and variant is already added into the index. You can add the tag to your query by using `TagNames.GetTagNameForWarehouseQuantity(inventorySystemId)` to resolve the correct tag name.

So filtering on stock balance when searching could look something like:

```auto
var country = _requestModelAccessor.RequestModel.CountryModel;

// get all inventories used for the current country
var inventorySystemIds = _inventoryService.GetAll()
	.Where(inventory => inventory.CountryLinks
		.Any(x => x.CountrySystemId == country.SystemId))
	.Select(x => x.SystemId)
	.ToList();

// add an optional clause where the stock balance should be 1-999999 for any of the connected inventories
var inventoryQuantityClause = new OptionalTagClause();
foreach (var inventory in inventorySystemIds)
{
	inventoryQuantityClause.Tags.Add(new RangeTag(TagNames.GetTagNameForWarehouseQuantity(inventory), 1, 999999));
}

_request.FilterTags.Add(inventoryQuantityClause);

```

You can add an `IIndexingProviderPreProcessor` to add data for `ErpStatus` into the index. In the Accelerator there’s an example called `CampaignIndexingProviderPreProcessor` you could have a look at. There’s an older extension method you could use to resolve a fitting name for the tag, `TagNames.GetTagNameForWarehouseArticleStatus(inventorySystemId);`

Keep in mind that if you’re merging variant data in the index, if any of the merged variant has stock it will be included.

---

<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: [March 5, 2021, 2:27pm UTC](https://forum.litium.com/t/extend-search-index/1875/3 "2021-03-05T14:27:24Z")

</div>

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