本文整理汇总了C#中Lucene.Net.Search.TermRangeQuery类的典型用法代码示例。如果您正苦于以下问题:C# TermRangeQuery类的具体用法?C# TermRangeQuery怎么用?C# TermRangeQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TermRangeQuery类属于Lucene.Net.Search命名空间,在下文中一共展示了TermRangeQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Process
public override Query Process(RangeQueryOptions options, AzureQueryMapper mapper)
{
string lowerTerm = (string)null;
string upperTerm = (string)null;
if (options.FieldFromValue != null)
lowerTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldFromValue, options.FieldName).ToString(), mapper);
if (options.FieldToValue != null)
upperTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldToValue, options.FieldName).ToString(), mapper);
TermRangeQuery termRangeQuery = new TermRangeQuery(options.FieldName, lowerTerm, upperTerm, options.IncludeLower, options.IncludeUpper);
termRangeQuery.Boost = options.Boost;
return (Query)termRangeQuery;
}
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:12,代码来源:DefaultRangeQueryProcessor.cs
示例2: MakeQuery
public BooleanQuery MakeQuery()
{
//Fill BooleanQeury with anonymous terms. term.Field=critList.Key term.Term=critList.Value
foreach (var pair in _searchCriterion)
{
string searchString = pair.Value.ToString();
if (!String.IsNullOrEmpty(searchString))
{
switch (pair.Key)
{
case "FindAll":
string[] searchFields = { "CardKind", "CardName", "CardEdition" };
var multiFieldQueryParser = new MultiFieldQueryParser(Version.LUCENE_30, searchFields,
_analyzer);
_finalQuery.Add(ParseQuery(searchString, multiFieldQueryParser),
searchString.Contains("+") ? Occur.MUST : Occur.SHOULD);
break;
case "CardAdoptionDateMin": //must be compile time constant!
string upperDate = DateTools.DateToString((DateTime)_kvpMax.Value, DateTools.Resolution.DAY);
var lowerRange = new TermRangeQuery("CardAdoptionDate", null, upperDate, true, true);
//{CardAdoptionDate:[* TO 20140718]}
_finalQuery.Add(new BooleanClause(lowerRange, Occur.MUST));
break;
case "CardAdoptionDateMax":
string lowerDate = DateTools.DateToString((DateTime)_kvpMin.Value, DateTools.Resolution.DAY);
var upperRange = new TermRangeQuery("CardAdoptionDate", lowerDate, null, true, true);
//{CardAdoptionDate:[20140718 TO *]}
_finalQuery.Add(new BooleanClause(upperRange, Occur.MUST));
break;
default:
_finalQuery.Add(new TermQuery(new Term(pair.Key, (string)pair.Value)), Occur.MUST);
break;
}
#region Source and links
//http://stackoverflow.com/questions/17503119/how-to-index-search-the-datetime-searchField-in-lucene-net
//http://stackoverflow.com/questions/3294772/storing-datetime-searchField-in-lucene-document
#endregion
}
}
return _finalQuery;
}
开发者ID:antgerasim,项目名称:ArmProtoClean,代码行数:52,代码来源:QueryMaker.cs
示例3: TestInclusive
public void TestInclusive()
{
using (var dir = FSDirectory.Open(TestEnvironment.TestIndexDirectory))
using (var indexSearcher = new IndexSearcher(dir))
{
var termRangeQuery = new TermRangeQuery(field: "title2", lowerTerm: "d", upperTerm: "j", includeLower: true, includeUpper: true);
var topDocs = indexSearcher.Search(termRangeQuery, 100);
Assert.Equal(3, topDocs.TotalHits);
// foreach (var scoreDoc in topDocs.ScoreDocs)
// {
// Console.WriteLine(" match: {0}:{1}", indexSearcher.Doc(scoreDoc.Doc).Get("author"));
// }
}
}
开发者ID:joshball,项目名称:Lucene.In.Action.NET,代码行数:16,代码来源:NumericRangeQueryTest.cs
示例4: TestMultiValuedNRQ
public virtual void TestMultiValuedNRQ()
{
System.Random rnd = NewRandom();
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, MaxFieldLength.UNLIMITED);
//DecimalFormat format = new DecimalFormat("00000000000", new System.Globalization.CultureInfo("en-US").NumberFormat);
for (int l = 0; l < 5000; l++)
{
Document doc = new Document();
for (int m = 0, c = rnd.Next(10); m <= c; m++)
{
int value_Renamed = rnd.Next(System.Int32.MaxValue);
doc.Add(new Field("asc", value_Renamed.ToString().PadLeft(11, '0'), Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.Add(new NumericField("trie", Field.Store.NO, true).SetIntValue(value_Renamed));
}
writer.AddDocument(doc);
}
writer.Close();
Searcher searcher = new IndexSearcher(directory, true);
for (int i = 0; i < 50; i++)
{
int lower = rnd.Next(System.Int32.MaxValue);
int upper = rnd.Next(System.Int32.MaxValue);
if (lower > upper)
{
int a = lower; lower = upper; upper = a;
}
TermRangeQuery cq = new TermRangeQuery("asc", lower.ToString().PadLeft(11, '0'), upper.ToString().PadLeft(11, '0'), true, true);
System.Int32 tempAux = (System.Int32) lower;
System.Int32 tempAux2 = (System.Int32) upper;
NumericRangeQuery tq = NumericRangeQuery.NewIntRange("trie", tempAux, tempAux2, true, true);
TopDocs trTopDocs = searcher.Search(cq, 1);
TopDocs nrTopDocs = searcher.Search(tq, 1);
Assert.AreEqual(trTopDocs.totalHits, nrTopDocs.totalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
}
searcher.Close();
directory.Close();
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:43,代码来源:TestMultiValuedNumericRangeQuery.cs
示例5: TestAllDocs
public virtual void TestAllDocs()
{
InitializeIndex(new string[] { "A", "B", "C", "D" });
IndexReader reader = DirectoryReader.Open(Dir);
IndexSearcher searcher = NewSearcher(reader);
TermRangeQuery query = new TermRangeQuery("content", null, null, true, true);
Terms terms = MultiFields.GetTerms(searcher.IndexReader, "content");
Assert.IsFalse(query.GetTermsEnum(terms) is TermRangeTermsEnum);
Assert.AreEqual(4, searcher.Search(query, null, 1000).ScoreDocs.Length);
query = new TermRangeQuery("content", null, null, false, false);
Assert.IsFalse(query.GetTermsEnum(terms) is TermRangeTermsEnum);
Assert.AreEqual(4, searcher.Search(query, null, 1000).ScoreDocs.Length);
query = TermRangeQuery.NewStringRange("content", "", null, true, false);
Assert.IsFalse(query.GetTermsEnum(terms) is TermRangeTermsEnum);
Assert.AreEqual(4, searcher.Search(query, null, 1000).ScoreDocs.Length);
// and now anothe one
query = TermRangeQuery.NewStringRange("content", "B", null, true, false);
Assert.IsTrue(query.GetTermsEnum(terms) is TermRangeTermsEnum);
Assert.AreEqual(3, searcher.Search(query, null, 1000).ScoreDocs.Length);
reader.Dispose();
}
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:21,代码来源:TestTermRangeQuery.cs
示例6: TestExclusive
public virtual void TestExclusive()
{
Query query = new TermRangeQuery("content", "A", "C", false, false);
InitializeIndex(new System.String[]{"A", "B", "C", "D"});
IndexSearcher searcher = new IndexSearcher(dir);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "A,B,C,D, only B in range");
searcher.Close();
InitializeIndex(new System.String[]{"A", "B", "D"});
searcher = new IndexSearcher(dir);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "A,B,D, only B in range");
searcher.Close();
AddDoc("C");
searcher = new IndexSearcher(dir);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "C added, still only B in range");
searcher.Close();
}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:21,代码来源:TestTermRangeQuery.cs
示例7: TestInclusive
public virtual void TestInclusive()
{
Query query = new TermRangeQuery("content", "A", "C", true, true);
InitializeIndex(new System.String[]{"A", "B", "C", "D"});
IndexSearcher searcher = new IndexSearcher(dir, true);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length, "A,B,C,D - A,B,C in range");
searcher.Close();
InitializeIndex(new System.String[]{"A", "B", "D"});
searcher = new IndexSearcher(dir, true);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(2, hits.Length, "A,B,D - A and B in range");
searcher.Close();
AddDoc("C");
searcher = new IndexSearcher(dir, true);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length, "C added - A, B, C in range");
searcher.Close();
}
开发者ID:synhershko,项目名称:lucene.net,代码行数:22,代码来源:TestTermRangeQuery.cs
示例8: TestExclusiveLowerNull
public virtual void TestExclusiveLowerNull()
{
Analyzer analyzer = new SingleCharAnalyzer();
//http://issues.apache.org/jira/browse/LUCENE-38
Query query = new TermRangeQuery("content", null, "C", false, false);
InitializeIndex(new System.String[]{"A", "B", "", "C", "D"}, analyzer);
IndexSearcher searcher = new IndexSearcher(dir, true);
int numHits = searcher.Search(query, null, 1000).TotalHits;
// When Lucene-38 is fixed, use the assert on the next line:
Assert.AreEqual(3, numHits, "A,B,<empty string>,C,D => A, B & <empty string> are in range");
// until Lucene-38 is fixed, use this assert:
//Assert.AreEqual(2, hits.length(),"A,B,<empty string>,C,D => A, B & <empty string> are in range");
searcher.Close();
InitializeIndex(new System.String[]{"A", "B", "", "D"}, analyzer);
searcher = new IndexSearcher(dir, true);
numHits = searcher.Search(query, null, 1000).TotalHits;
// When Lucene-38 is fixed, use the assert on the next line:
Assert.AreEqual(3, numHits, "A,B,<empty string>,D => A, B & <empty string> are in range");
// until Lucene-38 is fixed, use this assert:
//Assert.AreEqual(2, hits.length(), "A,B,<empty string>,D => A, B & <empty string> are in range");
searcher.Close();
AddDoc("C");
searcher = new IndexSearcher(dir, true);
numHits = searcher.Search(query, null, 1000).TotalHits;
// When Lucene-38 is fixed, use the assert on the next line:
Assert.AreEqual(3, numHits, "C added, still A, B & <empty string> are in range");
// until Lucene-38 is fixed, use this assert
//Assert.AreEqual(2, hits.length(), "C added, still A, B & <empty string> are in range");
searcher.Close();
}
开发者ID:synhershko,项目名称:lucene.net,代码行数:31,代码来源:TestTermRangeQuery.cs
示例9: TestRandomTrieAndClassicRangeQuery
private void TestRandomTrieAndClassicRangeQuery(int precisionStep)
{
System.Random rnd = NewRandom();
System.String field = "field" + precisionStep;
int termCountT = 0, termCountC = 0;
for (int i = 0; i < 50; i++)
{
long lower = (long) (rnd.NextDouble() * noDocs * distance) + startOffset;
long upper = (long) (rnd.NextDouble() * noDocs * distance) + startOffset;
if (lower > upper)
{
long a = lower; lower = upper; upper = a;
}
// test inclusive range
System.Int64 tempAux = (long) lower;
System.Int64 tempAux2 = (long) upper;
NumericRangeQuery tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
TermRangeQuery cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, true);
TopDocs tTopDocs = searcher.Search(tq, 1);
TopDocs cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test exclusive range
System.Int64 tempAux3 = (long) lower;
System.Int64 tempAux4 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux3, tempAux4, false, false);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, false);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test left exclusive range
System.Int64 tempAux5 = (long) lower;
System.Int64 tempAux6 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux5, tempAux6, false, true);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, true);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test right exclusive range
System.Int64 tempAux7 = (long) lower;
System.Int64 tempAux8 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux7, tempAux8, true, false);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, false);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
}
if (precisionStep == System.Int32.MaxValue)
{
Assert.AreEqual(termCountT, termCountC, "Total number of terms should be equal for unlimited precStep");
}
else
{
System.Console.Out.WriteLine("Average number of terms during random search on '" + field + "':");
System.Console.Out.WriteLine(" Trie query: " + (((double) termCountT) / (50 * 4)));
System.Console.Out.WriteLine(" Classical query: " + (((double) termCountC) / (50 * 4)));
}
}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:65,代码来源:TestNumericRangeQuery64.cs
示例10: Csrq
/// <summary>macro for readability </summary>
public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, System.Globalization.CompareInfo c)
{
TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih, c);
query.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
return query;
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:7,代码来源:TestMultiTermConstantScore.cs
示例11: TestDanish
public virtual void TestDanish()
{
System.Globalization.CompareInfo collator = new System.Globalization.CultureInfo("da" + "-" + "dk").CompareInfo;
// Danish collation orders the words below in the given order (example taken
// from TestSort.testInternationalSort() ).
System.String[] words = new System.String[]{"H\u00D8T", "H\u00C5T", "MAND"};
Query query = new TermRangeQuery("content", "H\u00D8T", "MAND", false, false, collator);
// Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ],
// but Danish collation does.
InitializeIndex(words);
IndexSearcher searcher = new IndexSearcher(dir);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "The index Term should be included.");
query = new TermRangeQuery("content", "H\u00C5T", "MAND", false, false, collator);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(0, hits.Length, "The index Term should not be included.");
searcher.Close();
}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:20,代码来源:TestTermRangeQuery.cs
示例12: MultiTermQuery
private static void MultiTermQuery(TermRangeQuery query, AzureQueryLogger.IndentedTextWriter writer)
{
writer.WriteLine("Field: {0}", (object)query.Field);
writer.WriteLine("Collator: {0}", (object)query.Collator);
writer.WriteLine("IncludesLower: {0}", (query.IncludesLower ? 1 : 0));
writer.WriteLine("IncludesUpper: {0}", (query.IncludesUpper ? 1 : 0));
writer.WriteLine("LowerTerm: {0}", (object)query.LowerTerm);
writer.WriteLine("UpperTerm: {0}", (object)query.UpperTerm);
}
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:9,代码来源:AzureQueryLogger.cs
示例13: WithinRange
/// <summary>
/// 添加字符串类型的RangeQuery.
/// </summary>
/// <param name="fieldName">字段名称</param>
/// <param name="min">最小值</param>
/// <param name="max">最大值 </param>
/// <returns>LuceneSearchBuilder</returns>
public LuceneSearchBuilder WithinRange(string fieldName, string min, string max, bool asFilter = false)
{
Query query = new TermRangeQuery(fieldName, min, max, true, true);
if (asFilter)
filters.Add(new BooleanClause(query, BooleanClause.Occur.MUST));
else
clauses.Add(new BooleanClause(query, BooleanClause.Occur.MUST));
return this;
}
开发者ID:ClaytonWang,项目名称:Dw3cSNS,代码行数:18,代码来源:LuceneSearchBuilder.cs
示例14: TestRangeQuery
public virtual void TestRangeQuery()
{
TermRangeQuery rq = new TermRangeQuery("sorter", "b", "d", true, true);
Query filteredquery = new FilteredQuery(rq, filter);
ScoreDoc[] hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
Assert.AreEqual(2, hits.Length);
QueryUtils.Check(filteredquery, searcher);
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:9,代码来源:TestFilteredQuery.cs
示例15: RangeQuery
/// <summary>Constructs a query selecting all terms greater than
/// <c>lowerTerm</c> but less than <c>upperTerm</c>.
/// There must be at least one term and either term may be null,
/// in which case there is no bound on that side, but if there are
/// two terms, both terms <b>must</b> be for the same field.
/// <p/>
/// If <c>collator</c> is not null, it will be used to decide whether
/// index terms are within the given range, rather than using the Unicode code
/// point order in which index terms are stored.
/// <p/>
/// <strong>WARNING:</strong> Using this constructor and supplying a non-null
/// value in the <c>collator</c> parameter will cause every single
/// index Term in the Field referenced by lowerTerm and/or upperTerm to be
/// examined. Depending on the number of index Terms in this Field, the
/// operation could be very slow.
///
/// </summary>
/// <param name="lowerTerm">The Term at the lower end of the range
/// </param>
/// <param name="upperTerm">The Term at the upper end of the range
/// </param>
/// <param name="inclusive">If true, both <c>lowerTerm</c> and
/// <c>upperTerm</c> will themselves be included in the range.
/// </param>
/// <param name="collator">The collator to use to collate index Terms, to determine
/// their membership in the range bounded by <c>lowerTerm</c> and
/// <c>upperTerm</c>.
/// </param>
public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive, System.Globalization.CompareInfo collator)
{
if (lowerTerm == null && upperTerm == null)
throw new System.ArgumentException("At least one term must be non-null");
if (lowerTerm != null && upperTerm != null && (System.Object) lowerTerm.Field() != (System.Object) upperTerm.Field())
throw new System.ArgumentException("Both terms must have the same field");
delegate_Renamed = new TermRangeQuery((lowerTerm == null)?upperTerm.Field():lowerTerm.Field(), (lowerTerm == null)?null:lowerTerm.Text(), (upperTerm == null)?null:upperTerm.Text(), inclusive, inclusive, collator);
delegate_Renamed.SetRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE);
}
开发者ID:sinsay,项目名称:SSE,代码行数:38,代码来源:RangeQuery.cs
示例16: BuildQuery
/// <summary>
/// Builds the query.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <returns></returns>
public override object BuildQuery(ISearchCriteria criteria)
{
var builder = base.BuildQuery(criteria) as QueryBuilder;
var query = builder.Query as BooleanQuery;
var analyzer = new StandardAnalyzer(u.Version.LUCENE_30);
if (criteria is CatalogIndexedSearchCriteria)
{
var c = criteria as CatalogIndexedSearchCriteria;
var datesFilterStart = new TermRangeQuery(
"startdate", c.StartDateFrom.HasValue ? DateTools.DateToString(c.StartDateFrom.Value, DateTools.Resolution.SECOND) : null, DateTools.DateToString(c.StartDate, DateTools.Resolution.SECOND), false, true);
query.Add(datesFilterStart, Occur.MUST);
if (c.EndDate.HasValue)
{
var datesFilterEnd = new TermRangeQuery(
"enddate",
DateTools.DateToString(c.EndDate.Value, DateTools.Resolution.SECOND),
null,
true,
false);
query.Add(datesFilterEnd, Occur.MUST);
}
if (c.Outlines != null && c.Outlines.Count > 0)
{
AddQuery("__outline", query, c.Outlines);
}
query.Add(new TermQuery(new Term("__hidden", "false")), Occur.MUST);
if (!String.IsNullOrEmpty(c.Catalog))
{
AddQuery("catalog", query, c.Catalog);
}
// Add search
if (!String.IsNullOrEmpty(c.SearchPhrase))
{
var searchPhrase = c.SearchPhrase;
if (c.IsFuzzySearch)
{
var keywords = c.SearchPhrase.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
searchPhrase = string.Empty;
searchPhrase = keywords.Aggregate(
searchPhrase,
(current, keyword) =>
current + String.Format("{0}~{1}", keyword.Replace("~", ""), c.FuzzyMinSimilarity.ToString(CultureInfo.InvariantCulture)));
}
var fields = new List<string> { "__content" };
if (c.Locale != null)
{
var contentField = string.Format("__content_{0}", c.Locale.ToLower());
fields.Add(contentField);
}
var parser = new MultiFieldQueryParser(u.Version.LUCENE_30, fields.ToArray(), analyzer)
{
DefaultOperator =
QueryParser
.Operator.OR
};
var searchQuery = parser.Parse(searchPhrase);
query.Add(searchQuery, Occur.MUST);
}
}
//else if (criteria is OrderSearchCriteria)
//{
// var c = criteria as OrderSearchCriteria;
// if (!String.IsNullOrEmpty(c.CustomerId))
// {
// AddQuery("customerid", query, c.CustomerId);
// }
//}
return builder;
}
开发者ID:adwardliu,项目名称:vc-community,代码行数:89,代码来源:LuceneSearchQueryBuilder.cs
示例17: TestBooleanOrderUnAffected
public virtual void TestBooleanOrderUnAffected()
{
// NOTE: uses index build in *this* setUp
IndexReader reader = IndexReader.Open(small);
IndexSearcher search = new IndexSearcher(reader);
// first do a regular TermRangeQuery which uses term expansion so
// docs with more terms in range get higher scores
Query rq = new TermRangeQuery("data", "1", "4", T, T);
ScoreDoc[] expected = search.Search(rq, null, 1000).scoreDocs;
int numHits = expected.Length;
// now do a boolean where which also contains a
// ConstantScoreRangeQuery and make sure hte order is the same
BooleanQuery q = new BooleanQuery();
q.Add(rq, BooleanClause.Occur.MUST); // T, F);
q.Add(Csrq("data", "1", "6", T, T), BooleanClause.Occur.MUST); // T, F);
ScoreDoc[] actual = search.Search(q, null, 1000).scoreDocs;
AssertEquals("wrong numebr of hits", numHits, actual.Length);
for (int i = 0; i < numHits; i++)
{
AssertEquals("mismatch in docid for hit#" + i, expected[i].doc, actual[i].doc);
}
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:30,代码来源:TestMultiTermConstantScore.cs
示例18: TestEqualsHashcode
public virtual void TestEqualsHashcode()
{
Query query = new TermRangeQuery("content", "A", "C", true, true);
query.SetBoost(1.0f);
Query other = new TermRangeQuery("content", "A", "C", true, true);
other.SetBoost(1.0f);
Assert.AreEqual(query, query, "query equals itself is true");
Assert.AreEqual(query, other, "equivalent queries are equal");
Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
other.SetBoost(2.0f);
Assert.IsFalse(query.Equals(other), "Different boost queries are not equal");
other = new TermRangeQuery("notcontent", "A", "C", true, true);
Assert.IsFalse(query.Equals(other), "Different fields are not equal");
other = new TermRangeQuery("content", "X", "C", true, true);
Assert.IsFalse(query.Equals(other), "Different lower terms are not equal");
other = new TermRangeQuery("content", "A", "Z", true, true);
Assert.IsFalse(query.Equals(other), "Different upper terms are not equal");
query = new TermRangeQuery("content", null, "C", true, true);
other = new TermRangeQuery("content", null, "C", true, true);
Assert.AreEqual(query, other, "equivalent queries with null lowerterms are equal()");
Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
query = new TermRangeQuery("content", "C", null, true, true);
other = new TermRangeQuery("content", "C", null, true, true);
Assert.AreEqual(query, other, "equivalent queries with null upperterms are equal()");
Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode returns same value");
query = new TermRangeQuery("content", null, "C", true, true);
other = new TermRangeQuery("content", "C", null, true, true);
Assert.IsFalse(query.Equals(other), "queries with different upper and lower terms are not equal");
query = new TermRangeQuery("content", "A", "C", false, false);
other = new TermRangeQuery("content", "A", "C", true, true);
Assert.IsFalse(query.Equals(other), "queries with different inclusive are not equal");
query = new TermRangeQuery("content", "A", "C", false, false);
other = new TermRangeQuery("content", "A", "C", false, false, System.Globalization.CultureInfo.CurrentCulture.CompareInfo);
Assert.IsFalse(query.Equals(other), "a query with a collator is not equal to one without");
}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:46,代码来源:TestTermRangeQuery.cs
示例19: TestFarsi
public virtual void TestFarsi()
{
// Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
// RuleBasedCollator. However, the Arabic Locale seems to order the Farsi
// characters properly.
System.Globalization.CompareInfo collator = new System.Globalization.CultureInfo("ar").CompareInfo;
Query query = new TermRangeQuery("content", "\u062F", "\u0698", true, true, collator);
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
// orders the U+0698 character before the U+0633 character, so the single
// index Term below should NOT be returned by a TermRangeQuery with a Farsi
// Collator (or an Arabic one for the case when Farsi is not supported).
InitializeIndex(new System.String[]{"\u0633\u0627\u0628"});
IndexSearcher searcher = new IndexSearcher(dir);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(0, hits.Length, "The index Term should not be included.");
query = new TermRangeQuery("content", "\u0633", "\u0638", true, true, collator);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "The index Term should be included.");
searcher.Close();
}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:21,代码来源:TestTermRangeQuery.cs
示例20: QueryCaseSensitiveTermRange
public void QueryCaseSensitiveTermRange()
{
BooleanQuery originalQuery = new BooleanQuery();
TermRangeQuery termRangeQuery = new TermRangeQuery("field", "Lower", "Upper", true, true);
originalQuery.Add(termRangeQuery, Occur.MUST);
string queryString = originalQuery.ToString();
QueryBuilder builder = new QueryBuilder{CaseSensitive = true};
builder.Setup(x => x.TermRange("field", "Lower", "Upper"));
Query replacementQuery = builder.Build();
string newQueryString = replacementQuery.ToString();
Assert.AreEqual(queryString, newQueryString);
Console.Write(queryString);
}
开发者ID:modulexcite,项目名称:Lucinq,代码行数:15,代码来源:EquivalencyTests.cs
注:本文中的Lucene.Net.Search.TermRangeQuery类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论