mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-3776: Query sorting is not support on .size and .mimetype properties of content.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20934 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -316,6 +316,32 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
|
||||
field = expandAttributeFieldName(field);
|
||||
PropertyDefinition propertyDef = getDictionaryService().getProperty(QName.createQName(field.substring(1)));
|
||||
|
||||
// Handle .size and .mimetype
|
||||
if(propertyDef == null)
|
||||
{
|
||||
if(field.endsWith(".size"))
|
||||
{
|
||||
propertyDef = getDictionaryService().getProperty(QName.createQName(field.substring(1, field.length()-5)));
|
||||
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order for .size only supported on content properties");
|
||||
}
|
||||
}
|
||||
else if (field.endsWith(".mimetype"))
|
||||
{
|
||||
propertyDef = getDictionaryService().getProperty(QName.createQName(field.substring(1, field.length()-9)));
|
||||
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order for .mimetype only supported on content properties");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order on content properties is not curently supported");
|
||||
@@ -393,8 +419,9 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
|
||||
requiresPostSort = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (fieldHasTerm(searcher.getReader(), field))
|
||||
{
|
||||
fields[index++] = new SortField(field, sortLocale, !sd.isAscending());
|
||||
|
@@ -1229,6 +1229,38 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener
|
||||
ftsQueryWithCount(searcher, "modified:[MIN TO NOW]", 2, Arrays.asList(new NodeRef[]{n14,n15}));
|
||||
}
|
||||
|
||||
|
||||
private ADMLuceneSearcherImpl buildSearcher()
|
||||
{
|
||||
ADMLuceneSearcherImpl searcher = ADMLuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher);
|
||||
searcher.setNodeService(nodeService);
|
||||
searcher.setDictionaryService(dictionaryService);
|
||||
searcher.setTenantService(tenantService);
|
||||
searcher.setNamespacePrefixResolver(getNamespacePrefixResolver("namespace"));
|
||||
searcher.setQueryRegister(queryRegisterComponent);
|
||||
searcher.setQueryLanguages(((AbstractLuceneIndexerAndSearcherFactory) indexerAndSearcher).queryLanguages);
|
||||
return searcher;
|
||||
}
|
||||
|
||||
public void testFTSandSort() throws Exception
|
||||
{
|
||||
luceneFTS.pause();
|
||||
buildBaseIndex();
|
||||
ADMLuceneSearcherImpl searcher = buildSearcher();
|
||||
|
||||
SearchParameters sp = new SearchParameters();
|
||||
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
|
||||
sp.addStore(rootNodeRef.getStoreRef());
|
||||
sp.setQuery( "PATH:\"//.\"");
|
||||
sp.addQueryTemplate("ANDY", "%cm:content");
|
||||
sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
sp.excludeDataInTheCurrentTransaction(true);
|
||||
sp.addSort("@"+ContentModel.PROP_CONTENT.toString()+".size", true);
|
||||
ResultSet results = searcher.query(sp);
|
||||
assertEquals(16, results.length());
|
||||
results.close();
|
||||
}
|
||||
|
||||
public void ftsQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count)
|
||||
{
|
||||
SearchParameters sp = new SearchParameters();
|
||||
@@ -2960,6 +2992,10 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener
|
||||
}
|
||||
results.close();
|
||||
|
||||
// sort by content size
|
||||
|
||||
|
||||
|
||||
// sort by ML text
|
||||
|
||||
//Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH, Locale.CHINESE };
|
||||
@@ -3030,6 +3066,58 @@ public class ADMLuceneTest extends TestCase implements DictionaryListener
|
||||
results.close();
|
||||
|
||||
luceneFTS.resume();
|
||||
|
||||
|
||||
// sort by content size
|
||||
|
||||
SearchParameters sp20 = new SearchParameters();
|
||||
sp20.addStore(rootNodeRef.getStoreRef());
|
||||
sp20.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
sp20.setQuery("PATH:\"//.\"");
|
||||
sp20.addSort("@" + ContentModel.PROP_CONTENT+".size", false);
|
||||
results = searcher.query(sp20);
|
||||
|
||||
Long size = null;
|
||||
for (ResultSetRow row : results)
|
||||
{
|
||||
ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
|
||||
// System.out.println(currentBun);
|
||||
if ((size != null) && (currentBun != null))
|
||||
{
|
||||
assertTrue(size.compareTo(currentBun.getSize()) >= 0);
|
||||
}
|
||||
if(currentBun != null)
|
||||
{
|
||||
size = currentBun.getSize();
|
||||
}
|
||||
}
|
||||
results.close();
|
||||
|
||||
// sort by content mimetype
|
||||
|
||||
SearchParameters sp21 = new SearchParameters();
|
||||
sp21.addStore(rootNodeRef.getStoreRef());
|
||||
sp21.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
sp21.setQuery("PATH:\"//.\"");
|
||||
sp21.addSort("@" + ContentModel.PROP_CONTENT+".mimetype", false);
|
||||
results = searcher.query(sp21);
|
||||
|
||||
String mimetype = null;
|
||||
for (ResultSetRow row : results)
|
||||
{
|
||||
ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
|
||||
// System.out.println(currentBun);
|
||||
if ((mimetype != null) && (currentBun != null))
|
||||
{
|
||||
assertTrue(mimetype.compareTo(currentBun.getMimetype()) >= 0);
|
||||
}
|
||||
if(currentBun != null)
|
||||
{
|
||||
mimetype = currentBun.getMimetype();
|
||||
}
|
||||
}
|
||||
results.close();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -157,6 +157,40 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
|
||||
{
|
||||
PropertyDefinition propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1)));
|
||||
|
||||
// Handle .size and .mimetype
|
||||
if(propertyDef == null)
|
||||
{
|
||||
if(field.endsWith(".size"))
|
||||
{
|
||||
propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1, field.length()-5)));
|
||||
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order for .size only supported on content properties");
|
||||
}
|
||||
else
|
||||
{
|
||||
return field;
|
||||
}
|
||||
}
|
||||
else if (field.endsWith(".mimetype"))
|
||||
{
|
||||
propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1, field.length()-9)));
|
||||
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order for .mimetype only supported on content properties");
|
||||
}
|
||||
else
|
||||
{
|
||||
return field;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return field;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
throw new SearcherException("Order on content properties is not curently supported");
|
||||
@@ -229,7 +263,7 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
|
||||
field = field + ".sort";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
Reference in New Issue
Block a user