mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Support "now" for dates in lucene queries. d📅now d📅"now" d📅[MIN TO NOW] should all be supported
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15226 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -3718,6 +3718,11 @@ public class ADMLuceneTest extends TestCase
|
|||||||
assertEquals(1, results.length());
|
assertEquals(1, results.length());
|
||||||
results.close();
|
results.close();
|
||||||
|
|
||||||
|
sDate = df.format(date);
|
||||||
|
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:created:[MIN TO NOW]", null);
|
||||||
|
assertEquals(1, results.length());
|
||||||
|
results.close();
|
||||||
|
|
||||||
sDate = df.format(date);
|
sDate = df.format(date);
|
||||||
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(ContentModel.PROP_CREATED) + ":[MIN TO " + sDate + "]", null);
|
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(ContentModel.PROP_CREATED) + ":[MIN TO " + sDate + "]", null);
|
||||||
assertEquals(1, results.length());
|
assertEquals(1, results.length());
|
||||||
|
@@ -77,6 +77,12 @@ public class DateTimeTokenFilter extends Tokenizer
|
|||||||
while ((candidate = baseTokeniser.next()) != null)
|
while ((candidate = baseTokeniser.next()) != null)
|
||||||
{
|
{
|
||||||
Date date;
|
Date date;
|
||||||
|
if (candidate.termText().equalsIgnoreCase("now"))
|
||||||
|
{
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
date = df.parse(candidate.termText());
|
date = df.parse(candidate.termText());
|
||||||
@@ -85,6 +91,7 @@ public class DateTimeTokenFilter extends Tokenizer
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(date);
|
cal.setTime(date);
|
||||||
|
@@ -53,9 +53,15 @@ public class DateTokenFilter extends Tokenizer
|
|||||||
SimpleDateFormat df = CachingDateFormat.getDateFormat();
|
SimpleDateFormat df = CachingDateFormat.getDateFormat();
|
||||||
SimpleDateFormat dof = CachingDateFormat.getDateOnlyFormat();
|
SimpleDateFormat dof = CachingDateFormat.getDateOnlyFormat();
|
||||||
Token candidate;
|
Token candidate;
|
||||||
while((candidate = baseTokeniser.next()) != null)
|
while ((candidate = baseTokeniser.next()) != null)
|
||||||
{
|
{
|
||||||
Date date;
|
Date date;
|
||||||
|
if (candidate.termText().equalsIgnoreCase("now"))
|
||||||
|
{
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
date = df.parse(candidate.termText());
|
date = df.parse(candidate.termText());
|
||||||
@@ -64,9 +70,9 @@ public class DateTokenFilter extends Tokenizer
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String valueString = dof.format(date);
|
String valueString = dof.format(date);
|
||||||
Token integerToken = new Token(valueString, candidate.startOffset(), candidate.startOffset(),
|
Token integerToken = new Token(valueString, candidate.startOffset(), candidate.startOffset(), candidate.type());
|
||||||
candidate.type());
|
|
||||||
return integerToken;
|
return integerToken;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user