Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Olhaholiak/workshop filter tests #258

Merged
merged 12 commits into from
Aug 5, 2021
22 changes: 12 additions & 10 deletions OutOfSchool/OutOfSchool.ElasticsearchData/ESWorkshopProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ private QueryContainer CreateQueryFromFilter(WorkshopFilterES filter)
return queryContainer;
}

if (!string.IsNullOrEmpty(filter.SearchText))
if (!string.IsNullOrWhiteSpace(filter.SearchText))
{
queryContainer &= new MultiMatchQuery()
{
Fields = Infer.Field<WorkshopES>(w => w.Title)
.And(Infer.Field<WorkshopES>(w => w.ProviderTitle))
.And(Infer.Field<WorkshopES>(w => w.Keywords))
.And(Infer.Field<WorkshopES>(w => w.Description))
.And(Infer.Field<WorkshopES>(w => w.ProviderDescription)),
.And(Infer.Field<WorkshopES>(w => w.Description)),
Query = filter.SearchText,
Fuzziness = Fuzziness.Auto,
};
Expand Down Expand Up @@ -95,7 +94,7 @@ private QueryContainer CreateQueryFromFilter(WorkshopFilterES filter)
Value = 0,
};
}
else if (!filter.IsFree && !(filter.MinPrice == 0 || filter.MaxPrice == int.MaxValue))
else if (!filter.IsFree && !(filter.MinPrice == 0 && filter.MaxPrice == int.MaxValue))
{
queryContainer &= new NumericRangeQuery()
{
Expand All @@ -104,7 +103,7 @@ private QueryContainer CreateQueryFromFilter(WorkshopFilterES filter)
LessThanOrEqualTo = filter.MaxPrice,
};
}
else if (filter.IsFree && !(filter.MinPrice == 0 || filter.MaxPrice == int.MaxValue))
else if (filter.IsFree && !(filter.MinPrice == 0 && filter.MaxPrice == int.MaxValue))
{
var tempQuery = new QueryContainer();

Expand Down Expand Up @@ -152,11 +151,14 @@ private QueryContainer CreateQueryFromFilter(WorkshopFilterES filter)
};
}

queryContainer &= new MatchQuery()
if (!string.IsNullOrWhiteSpace(filter.City))
{
Field = Infer.Field<WorkshopES>(w => w.Address.City),
Query = filter.City,
};
queryContainer &= new MatchQuery()
{
Field = Infer.Field<WorkshopES>(w => w.Address.City),
Query = filter.City,
};
}

return queryContainer;
}
Expand Down Expand Up @@ -192,7 +194,7 @@ private List<ISort> CreateSortFromFilter(WorkshopFilterES filter)
break;

default:
sorts.Add(new FieldSort() { Field = Infer.Field<WorkshopES>(w => w.Rating), Order = SortOrder.Descending });
sorts.Add(new FieldSort() { Field = Infer.Field<WorkshopES>(w => w.Id), Order = SortOrder.Ascending });
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 1 addition & 0 deletions OutOfSchool/OutOfSchool.ElasticsearchData/Enums/OrderBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum OrderBy
{
Id,
Statistic,
Rating,
PriceDesc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class WorkshopES

public string ProviderTitle { get; set; }

public string ProviderDescription { get; set; }

public string Description { get; set; }

public int MinAge { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class WorkshopFilterES

public string SearchText { get; set; } = string.Empty;

public string OrderByField { get; set; } = OrderBy.Rating.ToString();
public string OrderByField { get; set; } = OrderBy.Id.ToString();

public int MinAge { get; set; } = 0;

Expand All @@ -23,7 +23,7 @@ public class WorkshopFilterES

public List<long> DirectionIds { get; set; } = new List<long> { 0 };

public string City { get; set; } = "Київ";
public string City { get; set; } = string.Empty;

public bool WithDisabilityOptions { get; set; } = false;

Expand Down
Loading