本文整理汇总了C#中Lucene.Net.Search.Query类的典型用法代码示例。如果您正苦于以下问题:C# Query类的具体用法?C# Query怎么用?C# Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于Lucene.Net.Search命名空间,在下文中一共展示了Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HandleMethods
private static Query HandleMethods(Query query)
{
var termQuery = query as TermQuery;
if (termQuery != null && termQuery.Term.Field.StartsWith("@"))
{
return HandleMethodsForQueryAndTerm(query, termQuery.Term);
}
var wildcardQuery = query as WildcardQuery;
if (wildcardQuery != null)
{
return HandleMethodsForQueryAndTerm(query, wildcardQuery.Term);
}
var booleanQuery = query as BooleanQuery;
if (booleanQuery != null)
{
foreach (var c in booleanQuery.Clauses)
{
c.Query = HandleMethods(c.Query);
}
var requiresMerging = booleanQuery.Clauses.All(x => x.Query is IRavenLuceneMethodQuery);
if (requiresMerging == false)
return booleanQuery;
if (booleanQuery.Clauses.Count == 0)
return booleanQuery;
var first = (IRavenLuceneMethodQuery)booleanQuery.Clauses[0].Query;
var ravenLuceneMethodQuery = booleanQuery.Clauses.Skip(1).Aggregate(first, (methodQuery, clause) => methodQuery.Merge(clause.Query));
return (Query)ravenLuceneMethodQuery;
}
return query;
}
开发者ID:Trebornide,项目名称:ravendb,代码行数:30,代码来源:QueryBuilder.cs
示例2: Search
public SearchResult Search(Query searchQuery, int maxHits, string NameField = "Name", Sort sort = null)
{
SearchResult result = new SearchResult();
TopDocs hits = null;
result.SearchResultItems = new List<SearchResultItem>();
if(sort != null)
{
hits = seacher.Search(searchQuery, null, maxHits, sort);
}
else
{
hits = seacher.Search(searchQuery, null, maxHits);
}
for (int i = 0; i < hits.ScoreDocs.Count(); i++)
{
Document doctemp = seacher.Doc(hits.ScoreDocs[i].Doc);
result.SearchResultItems.Add(new SearchResultItem
{
Id = int.Parse(doctemp.Get("Id")),
Name = doctemp.Get(NameField),
Type = (DocumentType) Enum.Parse(typeof(DocumentType), doctemp.Get("Type"))
});
}
result.Hits = hits.ScoreDocs.Count();
return result;
}
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:27,代码来源:Seacher.cs
示例3: RunQuery
public virtual List<SkinnyItem> RunQuery(Query query, bool showAllVersions)
{
Assert.ArgumentNotNull(Index, "Aqueduct.SitecoreLib");
var items = new List<SkinnyItem>();
try
{
using (var context = new IndexSearchContext(Index))
{
var hits = context.Search(query);
if (hits == null)
{
return null;
}
var resultCollection = hits.FetchResults(0, hits.Length);
SearchHelper.GetItemsFromSearchResult(resultCollection, items, showAllVersions);
}
}
catch (Exception exception)
{
Log.Error("Aqueduct.SitecoreLib. There was a problem while running a search query. Details: " + exception.Message, this);
Log.Error(exception.StackTrace, this);
throw;
}
return items;
}
开发者ID:aqueduct,项目名称:Aqueduct.SitecoreLib,代码行数:30,代码来源:Searcher.cs
示例4: Get
public List<int> Get(Query searchQuery)
{
var indexSearcher = _productSearcher.IndexSearcher;
var name = FieldDefinition.GetFieldName<ProductSearchCategoriesDefinition>();
var valueCollector = new ValueCollector(indexSearcher, name);
indexSearcher.Search(searchQuery, valueCollector);
var categoryIds = valueCollector.Values[name].Select(s => Convert.ToInt32(s)).Distinct().ToList();
if (!categoryIds.Any())
return categoryIds;
var mainQuery = new BooleanQuery();
var idsQuery = new BooleanQuery();
const string idFieldName = "id";
foreach (var categoryId in categoryIds)
{
idsQuery.Add(new TermQuery(new Term(idFieldName, categoryId.ToString())), Occur.SHOULD);
}
mainQuery.Add(idsQuery, Occur.MUST);
var publishedOn = FieldDefinition.GetFieldName<PublishedOnFieldDefinition>();
mainQuery.Add(new TermRangeQuery(
publishedOn, null,
DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true), Occur.MUST);
var webpageSearcher = _indexSearcher.IndexSearcher;
var webpageValueCollector = new ValueCollector(webpageSearcher, idFieldName);
webpageSearcher.Search(mainQuery, null, webpageValueCollector);
return webpageValueCollector.Values[idFieldName].Select(s => Convert.ToInt32(s))
.Intersect(categoryIds)
.ToList();
}
开发者ID:neozhu,项目名称:Ecommerce,代码行数:32,代码来源:GetProductCategories.cs
示例5: SetUp
public override void SetUp()
{
base.SetUp();
INDEX_SIZE = AtLeast(2000);
Index = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Index);
RandomGen random = new RandomGen(this, Random());
for (int i = 0; i < INDEX_SIZE; ++i) // don't decrease; if to low the
{
// problem doesn't show up
Document doc = new Document();
if ((i % 5) != 0) // some documents must not have an entry in the first
{
// sort field
doc.Add(NewStringField("publicationDate_", random.LuceneDate, Field.Store.YES));
}
if ((i % 7) == 0) // some documents to match the query (see below)
{
doc.Add(NewTextField("content", "test", Field.Store.YES));
}
// every document has a defined 'mandant' field
doc.Add(NewStringField("mandant", Convert.ToString(i % 3), Field.Store.YES));
writer.AddDocument(doc);
}
Reader = writer.Reader;
writer.Dispose();
Query = new TermQuery(new Term("content", "test"));
}
开发者ID:joyanta,项目名称:lucene.net,代码行数:28,代码来源:TestCustomSearcherSort.cs
示例6: Filter
public List<FacetReturn> Filter(Query query, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
{
var buckets = new List<SitecoreItem>();
using (var searcher = new IndexSearcher(Constants.Index.Name))
{
if (locationFilter.IsNotEmpty())
{
buckets.AddRange(
searcher.GetItemsViaFieldQuery("isbucket", "1", 200).Value.Where(item => item.GetItem().IsNotNull()).Where(
itm => Context.ContentDatabase.GetItem(locationFilter).Axes.IsAncestorOf(itm.GetItem())));
}
}
var bucketsSelectToList = buckets.OrderBy(i => i.GetItem().Name).Select(item => item.GetItem().ID.ToString()).ToList();
var returnFacets = this.GetSearch(query, bucketsSelectToList, searchQuery, locationFilter, baseQuery).Select(
facet =>
new FacetReturn
{
KeyName = Context.ContentDatabase.GetItem(facet.Key).Name,
Value = facet.Value.ToString(),
Type = "location",
ID = facet.Key
});
return returnFacets.ToList();
}
开发者ID:csteeg,项目名称:Sitecore-Item-Buckets,代码行数:27,代码来源:LocationFacet.cs
示例7: Hits
internal Hits(Searcher s, Query q, Filter f)
{
weight = q.Weight(s);
searcher = s;
filter = f;
GetMoreDocs(50); // retrieve 100 initially
}
开发者ID:vineelkovvuri,项目名称:ExtendableDesktopSearch,代码行数:7,代码来源:Hits.cs
示例8: RunQuery
private IList<SearchResult> RunQuery(Query query)
{
// If two threads ran this method simultaneously, there would be issues with this.IndexReader.
// Alternatively, there could be one RAMDirectory per filesystem directory.
lock (this)
{
IndexReader newReader = this.indexReader.Reopen();
if (newReader != this.indexReader)
{
this.indexReader.Dispose();
this.indexReader = newReader;
}
IndexSearcher searcher; searcher = new IndexSearcher(newReader);
if (query == null)
{
return new List<SearchResult>();
}
TopDocs hits = searcher.Search(query, 1000);
return hits.ScoreDocs
.Select(scoreDoc => searcher.Doc(scoreDoc.Doc).Get(FullTextFieldType.Path.ToString()))
.Select(path => new SearchResult(path))
.ToList();
}
}
开发者ID:c0ns0le,项目名称:PsISEProjectExplorer,代码行数:26,代码来源:FullTextDirectory.cs
示例9: 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);
}
开发者ID:sameerkattel,项目名称:vc-community,代码行数:15,代码来源:LuceneSearchResults.cs
示例10: CheckHits_
public static void CheckHits_(Query query, System.String defaultFieldName, Searcher searcher, int[] results, TestCase testCase)
{
Hits hits = searcher.Search(query);
System.Collections.Hashtable correct = new System.Collections.Hashtable();
for (int i = 0; i < results.Length; i++)
{
correct.Add((System.Int32) results[i], null);
}
System.Collections.Hashtable actual = new System.Collections.Hashtable();
for (int i = 0; i < hits.Length(); i++)
{
actual.Add((System.Int32) hits.Id(i), null);
}
//Assert.AreEqual(correct, actual, query.ToString(defaultFieldName));
if (correct.Count != 0)
{
System.Collections.IDictionaryEnumerator iter = correct.GetEnumerator();
bool status = false;
while (iter.MoveNext())
{
status = actual.ContainsKey(iter.Key);
if (status == false)
break;
}
Assert.IsTrue(status, query.ToString(defaultFieldName));
}
}
开发者ID:emtees,项目名称:old-code,代码行数:30,代码来源:CheckHits.cs
示例11: ToChildBlockJoinQuery
/// <summary>
/// Create a ToChildBlockJoinQuery.
/// </summary>
/// <param name="parentQuery">Query that matches parent documents</param>
/// <param name="parentsFilter">Filter (must produce FixedBitSet per-segment, like <see cref="FixedBitSetCachingWrapperFilter"/>)
/// identifying the parent documents.</param>
/// <param name="doScores">True if parent scores should be calculated.</param>
public ToChildBlockJoinQuery(Query parentQuery, Filter parentsFilter, bool doScores)
{
_origParentQuery = parentQuery;
_parentQuery = parentQuery;
_parentsFilter = parentsFilter;
_doScores = doScores;
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:ToChildBlockJoinQuery.cs
示例12: BoostingQuery
private readonly Query match; // query to match
#endregion Fields
#region Constructors
public BoostingQuery(Query match, Query context, float boost)
{
this.match = match;
this.context = (Query) context.Clone(); // clone before boost
this.boost = boost;
this.context.Boost = 0.0f; // ignore context-only matches
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:BoostingQuery.cs
示例13: BuildQuery
/// <summary>
/// 构建Query、Filter、Sort
/// </summary>
/// <param name="query"><see cref="Query"/></param>
/// <param name="filter"><see cref="Filter"/></param>
/// <param name="sort"><see cref="Sort"/></param>
public void BuildQuery(out Query query, out Filter filter, out Sort sort)
{
BooleanQuery q = new BooleanQuery();
foreach (var clause in clauses)
{
q.Add(clause);
}
query = q;
if (filters.Count > 0)
{
BooleanQuery filterQuery = new BooleanQuery();
foreach (var _filter in filters)
filterQuery.Add(_filter);
filter = new QueryWrapperFilter(filterQuery);
}
else
{
filter = null;
}
if (sortFields.Count > 0)
sort = new Sort(sortFields.ToArray());
else
sort = null;
}
开发者ID:ClaytonWang,项目名称:Dw3cSNS,代码行数:33,代码来源:LuceneSearchBuilder.cs
示例14: SearchResults
internal SearchResults(Query query, IEnumerable<SortField> sortField, Searcher searcher, int maxResults)
{
LuceneQuery = query;
LuceneSearcher = searcher;
DoSearch(query, sortField, maxResults);
}
开发者ID:rhayesbite,项目名称:Examine,代码行数:7,代码来源:SearchResults.cs
示例15: TermsQuery
/// <summary>
///
/// </summary>
/// <param name="field">The field that should contain terms that are specified in the previous parameter.</param>
/// <param name="fromQuery"></param>
/// <param name="terms">The terms that matching documents should have. The terms must be sorted by natural order.</param>
internal TermsQuery(string field, Query fromQuery, BytesRefHash terms)
: base(field)
{
_fromQuery = fromQuery;
_terms = terms;
_ords = terms.Sort(BytesRef.UTF8SortedAsUnicodeComparer);
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:TermsQuery.cs
示例16: Visit
private static void Visit(Query query, AzureQueryLogger.IndentedTextWriter writer)
{
writer.WriteLine("Query Type: {0}", (object)query.GetType().FullName);
++writer.Indent;
writer.WriteLine("Boost: {0}", (object)query.Boost);
if (query is BooleanQuery)
AzureQueryLogger.VisitQuery((BooleanQuery)query, writer);
if (query is TermQuery)
AzureQueryLogger.VisitQuery((TermQuery)query, writer);
if (query is PhraseQuery)
AzureQueryLogger.VisitQuery((PhraseQuery)query, writer);
if (query is MultiTermQuery)
AzureQueryLogger.VisitQuery((MultiTermQuery)query, writer);
if (query is MultiPhraseQuery)
AzureQueryLogger.VisitQuery((MultiPhraseQuery)query, writer);
if (query is MatchAllDocsQuery)
AzureQueryLogger.VisitQuery((MatchAllDocsQuery)query, writer);
if (query is FieldScoreQuery)
AzureQueryLogger.VisitQuery((FieldScoreQuery)query, writer);
if (query is ValueSourceQuery)
AzureQueryLogger.VisitQuery((ValueSourceQuery)query, writer);
if (query is CustomScoreQuery)
AzureQueryLogger.VisitQuery((CustomScoreQuery)query, writer);
if (query is FilteredQuery)
AzureQueryLogger.VisitQuery((FilteredQuery)query, writer);
if (query is DisjunctionMaxQuery)
AzureQueryLogger.VisitQuery((DisjunctionMaxQuery)query, writer);
if (query is ConstantScoreQuery)
AzureQueryLogger.VisitQuery((ConstantScoreQuery)query, writer);
if (query is SpanQuery)
AzureQueryLogger.VisitQuery((SpanQuery)query, writer);
--writer.Indent;
}
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:33,代码来源:AzureQueryLogger.cs
示例17: Visit
public virtual Query Visit(Query q)
{
var booleanq = q as BooleanQuery; if (booleanq != null) return VisitBooleanQuery(booleanq);
//var boostingq = q as BoostingQuery; if (boostingq != null) return VisitBoostingQuery(boostingq);
var constantScoreq = q as ConstantScoreQuery; if (constantScoreq != null) return VisitConstantScoreQuery(constantScoreq);
var constantScoreRangeq = q as ConstantScoreRangeQuery; if (constantScoreRangeq != null) return VisitConstantScoreRangeQuery(constantScoreRangeq);
var customScoreq = q as CustomScoreQuery; if (customScoreq != null) return VisitCustomScoreQuery(customScoreq);
var disjunctionMaxq = q as DisjunctionMaxQuery; if (disjunctionMaxq != null) return VisitDisjunctionMaxQuery(disjunctionMaxq);
var filteredq = q as FilteredQuery; if (filteredq != null) return VisitFilteredQuery(filteredq);
//var fuzzyLikeThisq = q as FuzzyLikeThisQuery; if (fuzzyLikeThisq != null) return VisitFuzzyLikeThisQuery(fuzzyLikeThisq);
var matchAllDocsq = q as MatchAllDocsQuery; if (matchAllDocsq != null) return VisitMatchAllDocsQuery(matchAllDocsq);
//var moreLikeThisq = q as MoreLikeThisQuery; if (moreLikeThisq != null) return VisitMoreLikeThisQuery(moreLikeThisq);
var multiPhraseq = q as MultiPhraseQuery; if (multiPhraseq != null) return VisitMultiPhraseQuery(multiPhraseq);
var fuzzyq = q as FuzzyQuery; if (fuzzyq != null) return VisitFuzzyQuery(fuzzyq);
var wildcardq = q as WildcardQuery; if (wildcardq != null) return VisitWildcardQuery(wildcardq);
var phraseq = q as PhraseQuery; if (phraseq != null) return VisitPhraseQuery(phraseq);
var prefixq = q as PrefixQuery; if (prefixq != null) return VisitPrefixQuery(prefixq);
var rangeq = q as RangeQuery; if (rangeq != null) return VisitRangeQuery(rangeq);
var spanFirstq = q as SpanFirstQuery; if (spanFirstq != null) return VisitSpanFirstQuery(spanFirstq);
var spanNearq = q as SpanNearQuery; if (spanNearq != null) return VisitSpanNearQuery(spanNearq);
var spanNotq = q as SpanNotQuery; if (spanNotq != null) return VisitSpanNotQuery(spanNotq);
var spanOrq = q as SpanOrQuery; if (spanOrq != null) return VisitSpanOrQuery(spanOrq);
var spanTermq = q as SpanTermQuery; if (spanTermq != null) return VisitSpanTermQuery(spanTermq);
var termq = q as TermQuery; if (termq != null) return VisitTermQuery(termq);
var valueSourceq = q as ValueSourceQuery; if (valueSourceq != null) return VisitValueSourceQuery(valueSourceq);
var fieldScoreq = q as FieldScoreQuery; if (fieldScoreq != null) return VisitFieldScoreQuery(fieldScoreq);
// <V2.9.2>
var termRangeq = q as TermRangeQuery; if (termRangeq != null) return VisitTermRangeQuery(termRangeq);
var numericRangeq = q as NumericRangeQuery; if (numericRangeq != null) return VisitNumericRangeQuery(numericRangeq);
// </V2.9.2>
throw new NotImplementedException("Unknown query type: " + q.GetType().FullName);
}
开发者ID:jhuntsman,项目名称:FlexNet,代码行数:33,代码来源:LucQueryVisitor.cs
示例18: Filter
public List<FacetReturn> Filter(Query query, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
{
var refinement = new SafeDictionary<string> { { "is facet", "1" } };
int hitsCount;
var facetFields =
Context.ContentDatabase.GetItem(ItemIDs.TemplateRoot)
.Search(refinement, out hitsCount, location: ItemIDs.TemplateRoot.ToString(),
numberOfItemsToReturn: 2000, pageNumber: 1)
.ToList()
.Select((item, sitecoreItem) =>
new
{
FieldId = item.ItemId,
Facet = new Facet(item.Name)
})
.ToList();
facetFields.Sort((f1, f2) => System.String.Compare(f1.Facet.FieldName, f2.Facet.FieldName, System.StringComparison.Ordinal));
var returnFacets = (from facetField in facetFields
from facet in facetField.Facet.GetValues(query, locationFilter, baseQuery).Select(facet => new FacetReturn
{
KeyName = facet.Key,
Value = facet.Value.ToString(),
Type = facetField.Facet.FieldName.ToLower(),
ID = facetField.FieldId + "|" + facet.Key
})
select facet).ToList();
return returnFacets.ToList();
}
开发者ID:csteeg,项目名称:Sitecore-Item-Buckets,代码行数:32,代码来源:FieldFacet.cs
示例19: MakeQuery
public static Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
double distanceErrorPct = 0.025)
{
SpatialOperation spatialOperation;
var shape = ReadShape(shapeWKT);
switch (relation)
{
case SpatialRelation.Within:
spatialOperation = SpatialOperation.IsWithin;
break;
case SpatialRelation.Contains:
spatialOperation = SpatialOperation.Contains;
break;
case SpatialRelation.Disjoint:
spatialOperation = SpatialOperation.IsDisjointTo;
break;
case SpatialRelation.Intersects:
spatialOperation = SpatialOperation.Intersects;
break;
case SpatialRelation.Nearby:
// only sort by this, do not filter
return new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter()));
default:
throw new ArgumentOutOfRangeException("relation");
}
var args = new SpatialArgs(spatialOperation, shape) { DistErrPct = distanceErrorPct };
if(existingQuery is MatchAllDocsQuery)
return new CustomScoreQuery(spatialStrategy.MakeQuery(args), new ValueSourceQuery(spatialStrategy.MakeRecipDistanceValueSource(shape)));
return spatialStrategy.MakeQuery(args);
}
开发者ID:nberardi,项目名称:ravendb,代码行数:32,代码来源:SpatialIndex.cs
示例20: MergeQueries
public static Query MergeQueries(Query queryA, Query queryB, BooleanClause.Occur queryAOccurence, BooleanClause.Occur queryBOccurence)
{
BooleanQuery compoundQuery = new BooleanQuery();
compoundQuery.Add(new BooleanClause(queryA, queryAOccurence));
compoundQuery.Add(new BooleanClause(queryB, queryBOccurence));
return compoundQuery;
}
开发者ID:aqueduct,项目名称:Aqueduct.SitecoreLib,代码行数:8,代码来源:QueryHelper.cs
注:本文中的Lucene.Net.Search.Query类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论