Фильтрующие поляFilter fields
Числа и даты, по которым можно фильтровать результаты поиска.
Numbers and dates you can filter search results by.
Фильтрующие поля есть только в индексах с хранением текста (Memory, Disk, Shard; в API-хосте — "IndexFormat": "Legacy"). В сегментном индексе индексируйте атрибуты как текстовые поля и добавляйте их в запрос.
Filter fields exist only in indexes that store text (Memory, Disk, Shard; in the API host — "IndexFormat": "Legacy"). In the segment index index attributes as text fields and add them to the query.
Добавьте значения через GetFilterField (int, long, float, DateTime) и задайте цепочку условий FilterClause через Next.
Add values with GetFilterField (int, long, float, DateTime) and chain FilterClause conditions via Next.
C#
var field = "*";
var documentIndex = new DiskDocumentIndex(Directory.GetCurrentDirectory(), "test");
while (!documentIndex.IsReady)
{
Thread.Sleep(500);
}
var searchService = new SearchServiceEngine(documentIndex);
var doc = new IndexDocument("ExternalId");
doc.Add("content".GetField("one two one two second try to welcome"));
doc.Add("intValue".GetFilterField(10));
doc.Add("longValue".GetFilterField(20L));
doc.Add("dateValue".GetFilterField(DateTime.UtcNow));
searchService.Index(new IndexDocument[] { doc });
var request = new SearchQueryRequest()
{
Query = "one | two".Parse(field),
Field = field,
ShowHighlight = true,
OrderField = SortOrderFields.Relevance,
Order = SortOrder.Desc,
Size = 20,
// which stored fields to return
Fields = new List<string>() { "content", "id" },
// intValue == 10 AND longValue > 21
Filter = new FilterClause()
{
Condition = FilterCondition.Equal,
Value = "intValue".GetFilterField(10),
Next = new FilterClause()
{
Condition = FilterCondition.Great,
Value = "longValue".GetFilterField(21L)
}
}
};
var result = searchService.Search(request);