SetDateResolution() public method

Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with {@link #SetDateResolution(String, DateTools.Resolution)}.
public SetDateResolution ( Lucene.Net.Documents.DateTools dateResolution ) : void
dateResolution Lucene.Net.Documents.DateTools the default date resolution to set ///
return void
Ejemplo n.º 1
0
		public virtual void  TestDateRange()
		{
			System.String startDate = GetLocalizedDate(2002, 1, 1, false);
			System.String endDate = GetLocalizedDate(2002, 1, 4, false);
			System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar();
            System.DateTime endDateExpected = new System.DateTime(2002, 1, 4, 23, 59, 59, 999, calendar);
			System.String defaultField = "default";
			System.String monthField = "month";
			System.String hourField = "hour";
			QueryParser qp = new QueryParser("field", new SimpleAnalyzer());
			
			// Don't set any date resolution and verify if DateField is used
			System.DateTime tempAux = endDateExpected;
			AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux, null);
			
			// set a field specific date resolution
			qp.SetDateResolution(monthField, DateTools.Resolution.MONTH);
			
			// DateField should still be used for defaultField
			System.DateTime tempAux2 = endDateExpected;
			AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux2, null);
			
			// set default date resolution to MILLISECOND 
			qp.SetDateResolution(DateTools.Resolution.MILLISECOND);
			
			// set second field specific date resolution    
			qp.SetDateResolution(hourField, DateTools.Resolution.HOUR);
			
			// for this field no field specific date resolution has been set,
			// so verify if the default resolution is used
			System.DateTime tempAux3 = endDateExpected;
			AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux3, DateTools.Resolution.MILLISECOND);
			
			// verify if field specific date resolutions are used for these two fields
			System.DateTime tempAux4 = endDateExpected;
			AssertDateRangeQueryEquals(qp, monthField, startDate, endDate, tempAux4, DateTools.Resolution.MONTH);
			
			System.DateTime tempAux5 = endDateExpected;
			AssertDateRangeQueryEquals(qp, hourField, startDate, endDate, tempAux5, DateTools.Resolution.HOUR);
		}