mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Fixing search unit tests
--HG-- branch : dev
This commit is contained in:
@@ -166,12 +166,12 @@ namespace Orchard.Tests.Modules.Indexing {
|
||||
_provider.Store("default", _provider.New(2).Add("date", new DateTime(2010, 05, 28, 12, 30, 30)).Store());
|
||||
_provider.Store("default", _provider.New(3).Add("date", new DateTime(2010, 05, 28, 12, 30, 45)).Store());
|
||||
|
||||
var date = _searchBuilder.SortBy("date").Search().ToList();
|
||||
var date = _searchBuilder.SortByDateTime("date").Search().ToList();
|
||||
Assert.That(date.Count(), Is.EqualTo(3));
|
||||
Assert.That(date[0].GetDateTime("date") > date[1].GetDateTime("date"), Is.True);
|
||||
Assert.That(date[1].GetDateTime("date") > date[2].GetDateTime("date"), Is.True);
|
||||
|
||||
date = _searchBuilder.SortBy("date").Ascending().Search().ToList();
|
||||
date = _searchBuilder.SortByDateTime("date").Ascending().Search().ToList();
|
||||
Assert.That(date.Count(), Is.EqualTo(3));
|
||||
Assert.That(date[0].GetDateTime("date") < date[1].GetDateTime("date"), Is.True);
|
||||
Assert.That(date[1].GetDateTime("date") < date[2].GetDateTime("date"), Is.True);
|
||||
@@ -184,12 +184,12 @@ namespace Orchard.Tests.Modules.Indexing {
|
||||
_provider.Store("default", _provider.New(2).Add("downloads", 2222).Store());
|
||||
_provider.Store("default", _provider.New(3).Add("downloads", 3).Store());
|
||||
|
||||
var number = _searchBuilder.SortBy("downloads").Search().ToList();
|
||||
var number = _searchBuilder.SortByInteger("downloads").Search().ToList();
|
||||
Assert.That(number.Count(), Is.EqualTo(3));
|
||||
Assert.That(number[0].GetInt("downloads") > number[1].GetInt("downloads"), Is.True);
|
||||
Assert.That(number[1].GetInt("downloads") > number[2].GetInt("downloads"), Is.True);
|
||||
|
||||
number = _searchBuilder.SortBy("downloads").Ascending().Search().ToList();
|
||||
number = _searchBuilder.SortByInteger("downloads").Ascending().Search().ToList();
|
||||
Assert.That(number.Count(), Is.EqualTo(3));
|
||||
Assert.That(number[0].GetInt("downloads") < number[1].GetInt("downloads"), Is.True);
|
||||
Assert.That(number[1].GetInt("downloads") < number[2].GetInt("downloads"), Is.True);
|
||||
|
@@ -23,6 +23,7 @@ namespace Lucene.Services {
|
||||
private int _count;
|
||||
private int _skip;
|
||||
private string _sort;
|
||||
private int _comparer;
|
||||
private bool _sortDescending;
|
||||
private bool _asFilter;
|
||||
|
||||
@@ -43,6 +44,7 @@ namespace Lucene.Services {
|
||||
_clauses = new List<BooleanClause>();
|
||||
_filters = new List<BooleanClause>();
|
||||
_sort = String.Empty;
|
||||
_comparer = 0;
|
||||
_sortDescending = true;
|
||||
|
||||
InitPendingClause();
|
||||
@@ -107,13 +109,13 @@ namespace Lucene.Services {
|
||||
|
||||
public ISearchBuilder WithField(string field, DateTime value) {
|
||||
CreatePendingClause();
|
||||
_query = new TermQuery(new Term(field, DateTools.DateToString(value, DateTools.Resolution.SECOND)));
|
||||
_query = new TermQuery(new Term(field, DateTools.DateToString(value, DateTools.Resolution.MILLISECOND)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder WithinRange(string field, DateTime min, DateTime max) {
|
||||
CreatePendingClause();
|
||||
_query = new TermRangeQuery(field, DateTools.DateToString(min, DateTools.Resolution.SECOND), DateTools.DateToString(max, DateTools.Resolution.SECOND), true, true);
|
||||
_query = new TermRangeQuery(field, DateTools.DateToString(min, DateTools.Resolution.MILLISECOND), DateTools.DateToString(max, DateTools.Resolution.MILLISECOND), true, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -159,6 +161,8 @@ namespace Lucene.Services {
|
||||
_query = null;
|
||||
_boost = 0;
|
||||
_asFilter = false;
|
||||
_sort = String.Empty;
|
||||
_comparer = 0;
|
||||
}
|
||||
|
||||
private void CreatePendingClause() {
|
||||
@@ -184,12 +188,40 @@ namespace Lucene.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public ISearchBuilder SortBy(string name) {
|
||||
public ISearchBuilder SortBy(string name)
|
||||
{
|
||||
_sort = name;
|
||||
_comparer = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder Ascending() {
|
||||
public ISearchBuilder SortByInteger(string name) {
|
||||
_sort = name;
|
||||
_comparer = SortField.INT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByString(string name) {
|
||||
_sort = name;
|
||||
_comparer = SortField.STRING;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByFloat(string name) {
|
||||
_sort = name;
|
||||
_comparer = SortField.FLOAT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByDateTime(string name)
|
||||
{
|
||||
_sort = name;
|
||||
_comparer = SortField.LONG;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder Ascending()
|
||||
{
|
||||
_sortDescending = false;
|
||||
return this;
|
||||
}
|
||||
@@ -267,7 +299,7 @@ namespace Lucene.Services {
|
||||
try {
|
||||
var sort = String.IsNullOrEmpty(_sort)
|
||||
? Sort.RELEVANCE
|
||||
: new Sort(new SortField(_sort, CultureInfo.InvariantCulture, _sortDescending));
|
||||
: new Sort(new SortField(_sort, _comparer, _sortDescending));
|
||||
var collector = TopFieldCollector.create(
|
||||
sort,
|
||||
_count + _skip,
|
||||
|
@@ -47,6 +47,10 @@ namespace Orchard.Indexing {
|
||||
ISearchBuilder AsFilter();
|
||||
|
||||
ISearchBuilder SortBy(string name);
|
||||
ISearchBuilder SortByInteger(string name);
|
||||
ISearchBuilder SortByString(string name);
|
||||
ISearchBuilder SortByFloat(string name);
|
||||
ISearchBuilder SortByDateTime(string name);
|
||||
ISearchBuilder Ascending();
|
||||
|
||||
ISearchBuilder Slice(int skip, int count);
|
||||
|
@@ -92,7 +92,24 @@ namespace Orchard.Indexing {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder Ascending() {
|
||||
public ISearchBuilder SortByInteger(string name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByString(string name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByFloat(string name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder SortByDateTime(string name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISearchBuilder Ascending()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user