本文整理汇总了C#中QueryOptions类的典型用法代码示例。如果您正苦于以下问题:C# QueryOptions类的具体用法?C# QueryOptions怎么用?C# QueryOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryOptions类属于命名空间,在下文中一共展示了QueryOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GroupingSerach
/// <summary>
/// </summary>
/// <param name="dictPars">查询参数字典</param>
/// <param name="start">分页开始标识</param>
/// <param name="rows">每页数量</param>
/// <param name="startTime">开始时间</param>
/// <param name="endTime">结束时间</param>
/// <param name="count">输出参数 总个数</param>
/// <returns></returns>
/// <remarks>peng.li 2015年7月23日14:11:43</remarks>
public static List<int> GroupingSerach(Dictionary<string, string> dictPars, int start, int rows,
DateTime startTime, DateTime endTime, out int count)
{
//定义solr
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<LogItems>>();
var queryOptions = new QueryOptions();
//定义分组
var groupingParameters = new GroupingParameters();
groupingParameters.Fields = new Collection<string> { "logs_id" };
groupingParameters.Ngroups = true; //设置查询分组的总个数为true
//定义过滤条件
var timeRange = new SolrQueryByRange<DateTime>("logs_time", startTime, endTime);
queryOptions.AddFilterQueries(timeRange);
foreach (string key in dictPars.Keys)
{
queryOptions.AddFilterQueries(new SolrQueryByField(key, dictPars[key]));
}
//定义排序
queryOptions.OrderBy = new Collection<SortOrder> { new SortOrder("logs_id", Order.DESC) };
queryOptions.Grouping = groupingParameters;
queryOptions.Start = start;
queryOptions.Rows = rows;
SolrQueryResults<LogItems> res = solr.Query(SolrQuery.All, queryOptions);
GroupedResults<LogItems> items = res.Grouping["logs_id"];
count = items.Ngroups ?? 0;
return items.Groups.Select(item => Convert.ToInt32(item.GroupValue)).ToList();
}
示例2: ExecuteQuery
public ISolrQueryResults<BaseballGame> ExecuteQuery()
{
List<ISolrQuery> fieldQueries = new List<ISolrQuery>();
QueryOptions options = new QueryOptions();
options.Facet = BuildBaseFacetQuery();
options.Rows = 200;
if (this.AppliedFacets.Count > 0)
{
var facetGroups = this.AppliedFacets.Select(t => t.Item1).Distinct().ToList();
foreach(var group in facetGroups)
{
List<ISolrQuery> queries = this.AppliedFacets.Where(fg => fg.Item1 == group).Select(q => new SolrQueryByField(q.Item1, q.Item2) as ISolrQuery).ToList();
SolrMultipleCriteriaQuery smcq =
new SolrMultipleCriteriaQuery(queries,"OR");
fieldQueries.Add(smcq);
}
ISolrQuery multipleCriteriaQuery = new SolrMultipleCriteriaQuery(fieldQueries, "AND");
options.AddFilterQueries(multipleCriteriaQuery);
}
options.OrderBy.Add(new SortOrder(this.CurrentSortTerm, this.SortDirection == "D" ? Order.DESC : Order.ASC));
options.AddFilterQueries(new SolrQueryByField("docType", DocType.BaseballGame.ToString()));
ISolrQuery finalQuery = SolrQuery.All;
if (!string.IsNullOrEmpty(this.SearchTerm))
{
finalQuery = new SolrQuery(this.SearchTerm);
}
return _solrOperations.Query(finalQuery, options);
}
示例3: AddFields
public void AddFields()
{
QueryOptions o = new QueryOptions().AddFields("f1", "f2");
Assert.AreEqual(2, o.Fields.Count);
Assert.AreEqual("f1", o.Fields.First());
Assert.AreEqual("f2", o.Fields.ElementAt(1));
}
示例4: KeepassFilesThatPassOrFail
public async Task KeepassFilesThatPassOrFail()
{
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, new[] { ".kdbx" });
queryOptions.FolderDepth = FolderDepth.Shallow;
var samples = await Package.Current.InstalledLocation.GetFolderAsync("Samples");
var query = samples.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync();
var listOfFails = new List<object>();
foreach (var file in fileList)
{
string lastFileToTry = file.Name;
try
{
await Scenarios.LoadDatabase(file, "password", null);
}
catch (Exception e)
{
listOfFails.Add(lastFileToTry);
}
}
Assert.AreEqual(listOfFails.Count(), 7);
}
示例5: Translate
public virtual object Translate(LinqExpression expression, QueryOptions queryOptions)
{
this.rootCriteria = null;
this.options = queryOptions;
return TranslateInternal(expression);
}
示例6: DoCleanup
sealed protected override async Task DoCleanup(Regex pattern, DateTime threshold)
{
var toDelete = new List<StorageFile>();
foreach (var file in await _logFolder.GetFilesAsync())
{
if (pattern.Match(file.Name).Success && file.DateCreated <= threshold)
toDelete.Add(file);
}
var qo = new QueryOptions(CommonFileQuery.DefaultQuery, new [] {".zip"})
{
FolderDepth = FolderDepth.Shallow,
UserSearchFilter = "System.FileName:~<\"Log -\""
};
var query = ApplicationData.Current.TemporaryFolder.CreateFileQueryWithOptions(qo);
var oldLogs = await query.GetFilesAsync();
toDelete.AddRange(oldLogs);
// walk...
foreach (var file in toDelete)
{
try
{
await file.DeleteAsync();
}
catch (Exception ex)
{
InternalLogger.Current.Warn(string.Format("Failed to delete '{0}'.", file.Path), ex);
}
}
}
示例7: GetRealTimeData
public dynamic GetRealTimeData(QueryOptions queryOptions, string token)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var url = queryOptions.Dimensions == null
? string.Format(
"https://content.googleapis.com/analytics/v3/data/realtime?ids={0}&metrics={1}",
queryOptions.TableId, queryOptions.Metrics)
: string.Format(
"https://content.googleapis.com/analytics/v3/data/realtime?ids={0}&metrics={1}&dimensions={2}",
queryOptions.TableId, queryOptions.Metrics, queryOptions.Dimensions);
var result =
client.GetAsync(url).GetAwaiter().GetResult();
switch (result.StatusCode)
{
case HttpStatusCode.Unauthorized:
throw new UnauthorizedException();
case HttpStatusCode.BadRequest:
throw new Exception("GetRealTimeData: Bad Request");
}
var json =
result.Content.ReadAsStringAsync().GetAwaiter().GetResult();
return JsonConvert.DeserializeObject(json);
}
}
示例8: GetQueryOptions
protected QueryOptions GetQueryOptions()
{
MembershipUser user = Membership.GetUser();
Guid ui;
QueryOptions qo;
if (user == null)
ui = GetGuestId(); // Get the guest user id.
else
ui = (Guid)user.ProviderUserKey;
qo = db.QueryOptions.FirstOrDefault(QueryOptions => QueryOptions.UserId.Equals(ui));
if (qo == null)
{ // create the default user profile
qo = new QueryOptions
{
IncludeExternal = false,
Databases = new List<Database>(),
DataFields = new List<DataField>(),
SortOptionId = 1,
UserId = ui
};
db.QueryOptions.Add(qo);
db.SaveChanges();
}
return qo;
}
示例9: Init
//public ObservableCollection<ImageItem> Source = new ObservableCollection<ImageItem>();
public async Task Init()
{
var queryOptions = new QueryOptions(CommonFileQuery.OrderByDate,
new string[] { ".jpg", ".png", ".jpeg", ".bmp" })
{
FolderDepth = FolderDepth.Deep,
IndexerOption = IndexerOption.OnlyUseIndexer,
UserSearchFilter = "System.Kind:=System.Kind#Picture"
};
queryOptions.SetThumbnailPrefetch(ThumbnailMode.SingleItem, 256, ThumbnailOptions.UseCurrentScale);
var _fileQueryResult = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
var files = await _fileQueryResult.GetFilesAsync();
Debug.WriteLine("Count " + files.Count);
var list = new List<ImageItem>();
foreach (var f in files)
{
list.Add(new ImageItem()
{
LocalPath = f.Path
});
}
Source = new RangeCollection(list);
Source.Init();
}
示例10: GetMatchingFilesByPrefixAsync
public static async Task<List<string>> GetMatchingFilesByPrefixAsync(string prefix, List<string> excludeFiles)
{
try
{
List<string> result = new List<string>();
var folder = ApplicationData.Current.LocalFolder;
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new List<string>() { "*" });
queryOptions.UserSearchFilter = $"{prefix}*.*";
queryOptions.FolderDepth = FolderDepth.Shallow;
queryOptions.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> matchingFiles = await queryResult.GetFilesAsync();
if (matchingFiles.Count > 0)
{
result.AddRange(
matchingFiles.Where(f => !excludeFiles.Contains(f.Name)).Select(f => f.Name)
);
}
return result;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
return null;
}
示例11: QueryOption
public void QueryOption()
{
var queryOption = new QueryOptions<FakeModel>();
queryOption.QueryExpressions.Add(f => f.Property1 == "Property1");
queryOption.QueryExpressions.Should().HaveCount(1);
}
示例12: BrowseButton_Click
private async void BrowseButton_Click(object sender, RoutedEventArgs e)
{
try
{
var folderPicker = new FolderPicker()
{
CommitButtonText = "Open",
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
ViewMode = PickerViewMode.List
};
folderPicker.FileTypeFilter.Add(".shp");
_folder = await folderPicker.PickSingleFolderAsync();
if (_folder != null)
{
var qopts = new QueryOptions(CommonFileQuery.OrderByName, new string[] { ".shp" });
var query = _folder.CreateFileQueryWithOptions(qopts);
var files = await query.GetFilesAsync();
FileListCombo.ItemsSource = files;
FileListCombo.Visibility = (files.Any()) ? Visibility.Visible : Visibility.Collapsed;
}
}
catch (Exception ex)
{
var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
}
}
示例13: Client_SetQueryOptions
public void Client_SetQueryOptions()
{
var client = new Client();
var opts = new QueryOptions()
{
Datacenter = "foo",
Consistency = ConsistencyMode.Consistent,
WaitIndex = 1000,
WaitTime = new TimeSpan(0, 0, 100),
Token = "12345"
};
var request = client.CreateQuery("/v1/kv/foo", opts);
try
{
request.Execute();
}
catch (Exception)
{
// ignored
}
Assert.AreEqual("foo", request.Params["dc"]);
Assert.IsTrue(request.Params.ContainsKey("consistent"));
Assert.AreEqual("1000", request.Params["index"]);
Assert.AreEqual("1m40s", request.Params["wait"]);
Assert.AreEqual("12345", request.Params["token"]);
}
示例14: GivenQueryOptionForFakeModel_ShouldCastToAnotherFakeModel
public void GivenQueryOptionForFakeModel_ShouldCastToAnotherFakeModel()
{
var queryOption = new QueryOptions<FakeModel>();
queryOption.QueryExpressions.Add(f => f.Property1 == "Value of Property1");
var output = queryOption.ToLogString();
Trace.WriteLine(output);
}
示例15: Translate
public virtual object Translate(LinqExpression expression, QueryOptions queryOptions)
{
this.rootCriteria = null;
this.options = queryOptions;
Visit(expression); //ensure criteria
var visitor = new RootVisitor(rootCriteria, session, true);
visitor.Visit(expression);
return visitor.Results;
}