本文整理汇总了C#中IClient.Search方法的典型用法代码示例。如果您正苦于以下问题:C# IClient.Search方法的具体用法?C# IClient.Search怎么用?C# IClient.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IClient
的用法示例。
在下文中一共展示了IClient.Search方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilteringComplexCollections
/// <summary>
/// Using MatchContained on the complex object OR using Sizes collection
/// Note: While it is possible to filter on several fields in objects in collections using MatchContained
/// several times it is not possible to specify that those conditions should apply to the same object in the list.
/// That is: We can find size S and items with stock larger than 2, we cannot require that those conditions should apply to the same object.
/// In practice this limitation can often be worked around by filtering on some unique value of the objects in the list.
/// Also note that while MatchContained works for filtering on complex objects it's best practice to "denormalize" indexed objects by including
/// fields at indexing time to make querying less complex.
/// </summary>
private static void FilteringComplexCollections(IClient client)
{
// Example: All products in Size XL
var result = client.Search<Product>()
.Filter(p => p.Skus.MatchContained(s => s.Size, "XL"))
//.Filter(p => p.Sizes().Match("XL"))
.GetCachedResults();
ShowProductResults(result);
}
示例2: FilterDemo
/// <summary>
/// String: Match, Prefix, AnyWordBeginsWith, MatchFuzzy
/// Number: Range
/// DateTime: MatchYear etc
/// 1: Knitwear
/// 3: Size S or M
/// 4: Price Range 10-50
/// </summary>
private static void FilterDemo(IClient client)
{
var yesterday = DateTime.Now.AddDays(-1);
var result = client.Search<Product>()
// Category knitwear, Size "S" OR "M", Price 10-50
.GetResult();
ShowProductResults(result);
}
示例3: FiltersCombinedExample
/// <summary>
/// Using filters on Enum, collections and boolean
/// When using Match on a list of strings we require that at least one of the strings in the list matches the value specified.
/// Note: OrderBy orders null values last while OrderByDecending orders them first.
/// Use the second argument of type SortMissing to override the default behavior
/// </summary>
private static void FiltersCombinedExample(IClient client)
{
// Example: All womens jeans that are not sold out,
// order by price, then by name
var result = client.Search<Product>()
.Filter(p => p.Gender.Match(Gender.Womens))
.Filter(p => p.CategoryEnum.Match(CategoryEnum.Jeans))
.Filter(p => p.InStock.Match(true))
.OrderBy(p => p.Price)
.ThenBy(p => p.Name, SortMissing.Last)
.GetCachedResults();
ShowProductResults(result);
}
示例4: FilterUsingBuildFilter
/// <summary>
/// Sometimes, especially when reacting to user input filter has to be dynamically composed.
/// For this we can use the BuildFilter method.
/// </summary>
private static void FilterUsingBuildFilter(IClient client)
{
Console.WriteLine("What colors should we filter on? (Use ',' to separate.) ");
string colors = Console.ReadLine();
if (string.IsNullOrEmpty(colors) == false)
{
FilterBuilder<Product> colorFilter = client.BuildFilter<Product>();
foreach (var filterColor in colors.Split(',').ToList())
{
string c = filterColor;
colorFilter = colorFilter.Or(x => x.Color.MatchCaseInsensitive(c));
}
var result = client.Search<Product>()
.Filter(colorFilter)
.GetCachedResults();
ShowProductResults(result);
}
}
示例5: StoresCloseToOurLocation
/// <summary>
/// Geographic distance facets: grouping documents with a GeoLocation type property by distance from a location.
/// Request the number of stores within 1, 5, and 10 kilometers/miles of a location via the GeoDistanceFacetFor method
/// </summary>
/// <returns></returns>
private static void StoresCloseToOurLocation(IClient client)
{
// Location of The Cosmopolitan Hotel, Las Vegas, Nevada
var theCosmopolitanHotelLasVegas = new GeoLocation(36.109308, -115.175291);
var ranges = new List<NumericRange> {
new NumericRange {From = 0, To = 1},
new NumericRange {From = 0, To = 5},
new NumericRange {From = 0, To = 10}
};
var result = client.Search<Store>()
.Filter(s => s.Location.WithinDistanceFrom(theCosmopolitanHotelLasVegas, new Kilometers(10)))
.GeoDistanceFacetFor(s => s.Location, theCosmopolitanHotelLasVegas, ranges.ToArray())
.GetCachedResults();
ShowStoreResults(result);
}
示例6: ShowCachingWithDateTimeInQuery
/// <summary>
///
/// </summary>
/// <param name="client"></param>
private static void ShowCachingWithDateTimeInQuery(IClient client)
{
int timerBatchOne = 0;
Console.WriteLine("String first batch");
for (int i = 0; i < 50; i++)
{
var resultOne = client.Search<Product>()
.Filter(p => p.CategoryEnum.Match(CategoryEnum.Jeans))
.Filter(p => p.Gender.Match(Gender.Womens))
.Filter(p => p.InStock.Match(true))
.StaticallyCacheFor(TimeSpan.FromMinutes(10))
.GetResult();
timerBatchOne += resultOne.ProcessingInfo.ServerDuration;
Console.Write(".");
}
Console.WriteLine("\nTotal time {0} ms", timerBatchOne);
int timerBatchTwo = 0;
Console.WriteLine("********************");
Console.WriteLine("String second batch");
for (int i = 0; i < 50; i++)
{
var result = client.Search<Product>()
.Filter(p => p.CategoryEnum.Match(CategoryEnum.Jeans))
.Filter(p => p.Gender.Match(Gender.Womens))
.Filter(p => p.InStock.Match(true))
.StaticallyCacheFor(TimeSpan.FromMinutes(10))
.GetResult();
timerBatchTwo += result.ProcessingInfo.ServerDuration;
Console.Write(".");
}
Console.WriteLine("\nTotal time {0} ms\n", timerBatchTwo);
}
示例7: ProjectIfYouCan
/// <summary>
/// Example: Find sizes and stock for product named 'Mio cardigan'
/// Tailor the objects to your need: Less data transfered = smaller response
/// </summary>
private static void ProjectIfYouCan(IClient client)
{
var result = client.Search<Product>()
.Filter(p => p.Name.Match("Mio cardigan"))
.Select(r => new { Id = r.ProductId, Skus = r.Skus})
.GetCachedResults();
foreach (var hit in result)
{
Console.WriteLine(hit.Id);
foreach (var sku in hit.Skus)
{
Console.WriteLine("\t Size {0} Stock {1}", sku.Size, sku.Stock);
}
}
}
示例8: ProductFacetsExample
/// <summary>
/// Adds facets for specific parameters that gets aggregated across all results
/// NB: Make sure you know the difference in use of Filter and FilterHits.
/// Filters added using Filter are applied BEFORE calculating facets, while FilterHits are added AFTER calculating facets
/// Filter is better performance wise.
/// </summary>
private static void ProductFacetsExample(IClient client)
{
var query = client.Search<Product>()
.Filter(p => p.CategoryEnum.Match(CategoryEnum.Knitwear))
.TermsFacetFor(p => p.Sizes()) //Size
.TermsFacetFor(p => p.Color) //Color
.RangeFacetFor(p => p.Price,
new NumericRange(20, 50),
new NumericRange(51, 100),
new NumericRange(101, 500)) //Price
.FilterFacet("Womens knitwear",
p => p.Gender.Match(Gender.Womens)
& p.CategoryEnum.Match(CategoryEnum.Knitwear));
var result = query.Take(0).GetCachedResults();
ShowProductResults(result);
}