本文整理汇总了C#中ISearchCriteria类的典型用法代码示例。如果您正苦于以下问题:C# ISearchCriteria类的具体用法?C# ISearchCriteria怎么用?C# ISearchCriteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISearchCriteria类属于命名空间,在下文中一共展示了ISearchCriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LuceneSearchResults
/// <summary>
/// Initializes a new instance of the <see cref="SearchResults" /> class.
/// </summary>
/// <param name="searcher">The searcher.</param>
/// <param name="reader">The reader.</param>
/// <param name="docs">The hits.</param>
/// <param name="criteria">The criteria.</param>
/// <param name="query">The query.</param>
public LuceneSearchResults(Searcher searcher, IndexReader reader, TopDocs docs, ISearchCriteria criteria, Query query)
{
Results = new SearchResults(criteria, null);
CreateDocuments(searcher, docs);
CreateFacets(reader, query);
CreateSuggestions(reader, criteria);
}
示例2: BuildQuery
/// <summary>
/// Builds the query.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <returns></returns>
public virtual object BuildQuery(ISearchCriteria criteria)
{
var query = new BooleanQuery();
if (criteria.CurrentFilterValues != null)
{
for (var index = 0; index < criteria.CurrentFilterFields.Length; index++)
{
var filter = criteria.CurrentFilters.ElementAt(index);
var value = criteria.CurrentFilterValues.ElementAt(index);
var field = criteria.CurrentFilterFields.ElementAt(index);
// Skip currencies that are not part of the filter
if (filter.GetType() == typeof(PriceRangeFilter)) // special filtering
{
var currency = (filter as PriceRangeFilter).Currency;
if (!currency.Equals(criteria.Currency, StringComparison.OrdinalIgnoreCase))
{
continue;
}
}
var filterQuery = filter.GetType() == typeof(PriceRangeFilter)
? LuceneQueryHelper.CreateQuery(criteria, field, value as RangeFilterValue)
: LuceneQueryHelper.CreateQuery(field, value);
if (filterQuery != null)
{
query.Add(filterQuery, Occur.MUST);
}
}
}
return query;
}
示例3: CreateQueryForValue
public static BoolFilter<ESDocument> CreateQueryForValue(ISearchCriteria criteria, ISearchFilter filter, ISearchFilterValue value)
{
var query = new BoolFilter<ESDocument>();
var field = filter.Key.ToLower();
if (filter.GetType() == typeof(PriceRangeFilter))
{
var tempQuery = CreatePriceRangeFilter(criteria, field, value as RangeFilterValue);
if (tempQuery != null)
{
query.Must(q => q.Bool(b => tempQuery));
}
}
else
{
if (value.GetType() == typeof(AttributeFilterValue))
{
query.Must(q => q.Term(t=>t.Field(field).Value(((AttributeFilterValue)value).Value)));
}
else if (value.GetType() == typeof(RangeFilterValue))
{
var tempValue = value as RangeFilterValue;
var tempFilter = new RangeFilter<ESDocument>();
tempFilter.Field(field).From(tempValue.Lower).To(tempValue.Upper).IncludeLower(true).IncludeUpper(false);
query.Should(q => q.Range(r => tempFilter));
}
}
return query;
}
示例4: ExcludedSearchCriteria
public ExcludedSearchCriteria(ISearchCriteria searchCriteria)
{
if (searchCriteria == null)
throw new ArgumentNullException("searchCriteria");
this.searchCriteria = searchCriteria;
}
示例5: CatalogItemSearchResults
public CatalogItemSearchResults(ISearchCriteria criteria, Dictionary<string, Dictionary<string, object>> items, SearchResults results)
{
_Items = items;
_TotalCount = results.TotalCount;
_Count = results.DocCount;
_FacetGroups = results.FacetGroups;
_SearchCriteria = criteria;
}
示例6: Request
public Request(ISearchCriteria criteria, int depth, ReceiveResponse callback)
{
Identifier = Environment.MachineName + Peer.Self.Name + DateTime.UtcNow;
SearchCriteria = criteria;
Requester = Peer.Self;
Depth = depth;
Callback = callback;
}
示例7: SearchCriteriaViewModel
/// <summary>
/// Initializes a new instance of the <see cref="SearchCriteriaViewModel"/> class.
/// </summary>
/// <param name="criterea">The criterea.</param>
public SearchCriteriaViewModel(ISearchCriteria criterea)
{
if (criterea != null)
{
this.SearchFor = criterea.SearchFor;
this.CategoryID = criterea.CategoryID;
this.OSID = criterea.OSID;
this.OrderBy = criterea.OrderBy;
this.Page = 1;
//todo: add additional criterea here
}
}
示例8: CreateQuery
public static Filter CreateQuery(ISearchCriteria criteria, ISearchFilter filter, Occur clause)
{
var values = GetFilterValues(filter);
if (values == null) return null;
var query = new BooleanFilter();
foreach (var value in values)
{
var valueQuery = CreateQueryForValue(criteria, filter, value);
query.Add(new FilterClause(valueQuery, Occur.SHOULD));
}
return query;
}
示例9: SearchOrders
public OrderSearchResults SearchOrders(string scope, ISearchCriteria criteria)
{
var results = _searchService.Search(scope, criteria) as SearchResults;
if (results != null)
{
var resultIds = results.GetKeyFieldValues<string>();
var orders = _orderRepository.Orders.Where(x => resultIds.Contains(x.OrderGroupId)).ToArray();
var retVal = new OrderSearchResults(criteria, orders, results);
return retVal;
}
return null;
}
示例10: CreateQuery
public static BoolFilter<ESDocument> CreateQuery(ISearchCriteria criteria, ISearchFilter filter)
{
var values = GetFilterValues(filter);
if (values == null) return null;
var query = new BoolFilter<ESDocument>();
foreach (var value in values)
{
var valueQuery = CreateQueryForValue(criteria, filter, value);
//var boolQuery = new Query<ESDocument>();
//boolQuery.Bool(x => valueQuery);
query.Should(x=>x.Bool(y=>valueQuery));
}
return query;
}
示例11: Search
public ISearchResults Search(string scope, ISearchCriteria criteria)
{
// Build query
var builder = (SearchQuery)_queryBuilder.BuildQuery(criteria);
SearchQueryResult resultDocs;
// Add some error handling
//try
{
var searchResponse = Client.Search(scope, builder).Result;
if (!searchResponse.IsSuccess)
{
throw new AzureSearchException(AzureSearchHelper.FormatSearchException(searchResponse));
}
resultDocs = searchResponse.Body;
}
/*
catch (Exception ex)
{
throw ex;
}
* */
// Parse documents returned
var documents = new ResultDocumentSet { TotalCount = resultDocs.Count };
var docList = new List<ResultDocument>();
foreach (var indexDoc in resultDocs.Records)
{
var document = new ResultDocument();
foreach (var field in indexDoc.Properties.Keys)
{
document.Add(new DocumentField(field, indexDoc.Properties[field]));
}
docList.Add(document);
}
documents.Documents = docList.ToArray();
// Create search results object
var results = new SearchResults(criteria, new[] { documents });
return results;
}
示例12: CreatePriceRangeFilter
/// <summary>
/// Creates the price range filter.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <param name="field">The field.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public static BoolFilter<ESDocument> CreatePriceRangeFilter(ISearchCriteria criteria, string field, RangeFilterValue value)
{
var query = new BoolFilter<ESDocument>();
var lowerbound = value.Lower;
var upperbound = value.Upper;
var lowerboundincluded = true;
var upperboundincluded = false;
var currency = criteria.Currency.ToLower();
// format is "fieldname_store_currency_pricelist"
string[] pls = null;
if (criteria is CatalogItemSearchCriteria)
{
pls = ((CatalogItemSearchCriteria)criteria).Pricelists;
}
var parentPriceList = String.Empty;
// Create filter of type
// price_USD_pricelist1:[100 TO 200} (-price_USD_pricelist1:[* TO *} +(price_USD_pricelist2:[100 TO 200} (-price_USD_pricelist2:[* TO *} (+price_USD_pricelist3[100 TO 200}))))
if (pls == null || pls.Count() == 0)
return null;
var priceListId = pls[0].ToLower();
var filter = new RangeFilter<ESDocument>();
filter.Field(String.Format("{0}_{1}_{2}", field, currency, priceListId)).From(lowerbound).To(upperbound).IncludeLower(lowerboundincluded).IncludeUpper(upperboundincluded);
//query.Should(q => q.ConstantScore(c => c.Filter(f => f.Range(r => filter))));
query.Should(q => q.Range(r => filter));
if (pls.Count() > 1)
{
var temp = CreatePriceRangeFilter(pls, 1, field, currency, lowerbound, upperbound, lowerboundincluded, upperboundincluded);
query.Should(q => q.Bool(b => temp));
}
//Query query = new ConstantScoreQuery(filter);
return query;
}
示例13: CreateQueryForValue
public static Filter CreateQueryForValue(ISearchCriteria criteria, ISearchFilter filter, ISearchFilterValue value)
{
Filter q = null;
var priceQuery = filter is PriceRangeFilter;
if (value is RangeFilterValue && priceQuery)
{
q = LuceneQueryHelper.CreateQuery(
criteria, filter.Key, value as RangeFilterValue);
}
else if (value is CategoryFilterValue)
{
q = CreateQuery(filter.Key, value as CategoryFilterValue);
}
else
{
q = CreateQuery(filter.Key, value);
}
return q;
}
示例14: CreateQueryForValue
public static Filter CreateQueryForValue(ISearchCriteria criteria, ISearchFilter filter, ISearchFilterValue value)
{
Filter q;
var priceQuery = filter is PriceRangeFilter;
var rangeFilterValue = value as RangeFilterValue;
if (rangeFilterValue != null && priceQuery)
{
q = CreateQuery(criteria, filter.Key, rangeFilterValue);
}
else if (value is CategoryFilterValue)
{
q = CreateQuery(filter.Key, (CategoryFilterValue)value);
}
else
{
q = CreateQuery(filter.Key, value);
}
return q;
}
示例15: BuildQuery
public static ISearchCriteria BuildQuery(string[] textFields, string searchString, ISearchCriteria criteria)
{
List<SearchTerm> Terms = new List<SearchTerm>();
if ((searchString.Contains(@"""")) && (searchString.Count(t => t == '"') % 2 == 0)) // even number of quotes, more than zero
{
Regex quoteRegex = new Regex(@""".+?"""); // look for any content between quotes
foreach (Match item in quoteRegex.Matches(searchString))
{
Terms.Add(new SearchTerm() { Term = item.Value.Replace('"', ' ').Trim(), TermType = SearchTermType.MultiWord });
searchString = Regex.Replace(searchString, item.Value, string.Empty); // remove them from search string for subsequent parsing
}
}
List<string> singleTerms = new List<string>();
singleTerms = searchString.Split(' ').ToList();
singleTerms.ForEach(t => Terms.Add(new SearchTerm() { Term = t, TermType = SearchTermType.SingleWord }));
foreach (SearchTerm t in Terms)
{
if (!string.IsNullOrEmpty(t.Term))
{
switch (t.TermType)
{
case SearchTermType.SingleWord:
criteria.GroupedOr(textFields,
new IExamineValue[] { Examine.LuceneEngine.SearchCriteria.LuceneSearchExtensions.Fuzzy(t.Term, 0.4F) });
break;
case SearchTermType.MultiWord:
criteria.GroupedOr(textFields,
new IExamineValue[] { Examine.LuceneEngine.SearchCriteria.LuceneSearchExtensions.Escape(t.Term) });
break;
default:
break;
}
}
}
return criteria;
}