Merged HEAD-BUG-FIX (Cloud33/4.3) to HEAD (Cloud33/4.3)

62901: Merged PLATFORM1 (Cloud33) to HEAD-BUG-FIX (Cloud33/4.3)
      61252: ACE-479  Provide Search Adapter
       - Reintegrated BRANCHES/DEV/PLATFORM1 from BRANCHES/DEV/PLATFORM1-AHIND


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62955 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-20 14:21:16 +00:00
parent edcd570731
commit 30b1d43c90
11 changed files with 343 additions and 684 deletions

View File

@@ -24,10 +24,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import org.alfresco.repo.dictionary.IndexTokenisationMode;
import org.alfresco.repo.search.MLAnalysisMode;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParserAdaptor;
import org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -36,7 +34,7 @@ import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.lucene.index.IndexReader.FieldOption;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.springframework.extensions.surf.util.I18NUtil;
/**
@@ -91,7 +89,7 @@ public class DirectProperty extends AbstractSimpleProperty
* @see org.alfresco.cmis.mapping.AbstractSimpleProperty#getLuceneSortField()
*/
@Override
public String getLuceneSortField(AbstractLuceneQueryParser lqp)
public <Q, S, E extends Throwable> String getLuceneSortField(LuceneQueryParserAdaptor<Q, S, E> lqpa) throws E
{
String field = getLuceneFieldName();
@@ -102,30 +100,67 @@ public class DirectProperty extends AbstractSimpleProperty
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
throw new SearcherException("Order on content properties is not curently supported");
throw new CmisInvalidArgumentException("Order on content properties is not curently supported");
}
else if(propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))
else if ((propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) || (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)))
{
if(propertyDef.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
{
return field;
}
String noLocalField = field+".no_locale";
for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED))
{
String currentString = (String) current;
if (currentString.equals(noLocalField))
{
return noLocalField;
}
}
return findSortField(lqp, field);
}
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
{
field = findSortField(lqp, field);
// List<Locale> locales = lqpa.getSearchParameters().getLocales();
// if (((locales == null) || (locales.size() == 0)))
// {
// locales = Collections.singletonList(I18NUtil.getLocale());
// }
//
// if (locales.size() > 1)
// {
// throw new CmisInvalidArgumentException("Order on text/mltext properties with more than one locale is not curently supported");
// }
//
// sortLocale = locales.get(0);
// // find best field match
//
// HashSet<String> allowableLocales = new HashSet<String>();
// MLAnalysisMode analysisMode = lqpa.getDefaultSearchMLAnalysisMode();
// for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false))
// {
// allowableLocales.add(l.toString());
// }
field = lqpa.getSortField(field);
// String sortField = field;
//
// for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED))
// {
// String currentString = (String) current;
// if (currentString.startsWith(field) && currentString.endsWith(".sort"))
// {
// String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - 5);
// if (allowableLocales.contains(fieldLocale))
// {
// if (fieldLocale.equals(sortLocale.toString()))
// {
// sortField = currentString;
// break;
// }
// else if (sortLocale.toString().startsWith(fieldLocale))
// {
// if (sortField.equals(field) || (currentString.length() < sortField.length()))
// {
// sortField = currentString;
// }
// }
// else if (fieldLocale.startsWith(sortLocale.toString()))
// {
// if (sortField.equals(field) || (currentString.length() < sortField.length()))
// {
// sortField = currentString;
// }
// }
// }
// }
// }
//
// field = sortField;
}
else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME))
{
@@ -144,66 +179,68 @@ public class DirectProperty extends AbstractSimpleProperty
* @param field
* @return
*/
private String findSortField(AbstractLuceneQueryParser lqp, String field)
{
Locale sortLocale;
List<Locale> locales = lqp.getSearchParameters().getLocales();
if (((locales == null) || (locales.size() == 0)))
{
locales = Collections.singletonList(I18NUtil.getLocale());
}
if (locales.size() > 1)
{
throw new SearcherException("Order on text/mltext properties with more than one locale is not curently supported");
}
sortLocale = locales.get(0);
// find best field match
HashSet<String> allowableLocales = new HashSet<String>();
MLAnalysisMode analysisMode = lqp.getDefaultSearchMLAnalysisMode();
for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false))
{
allowableLocales.add(l.toString());
}
String sortField = field;
for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED))
{
String currentString = (String) current;
if (currentString.startsWith(field) && currentString.endsWith(".sort"))
{
String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - 5);
if (allowableLocales.contains(fieldLocale))
{
if (fieldLocale.equals(sortLocale.toString()))
{
sortField = currentString;
break;
}
else if (sortLocale.toString().startsWith(fieldLocale))
{
if (sortField.equals(field) || (currentString.length() < sortField.length()))
{
sortField = currentString;
}
}
else if (fieldLocale.startsWith(sortLocale.toString()))
{
if (sortField.equals(field) || (currentString.length() < sortField.length()))
{
sortField = currentString;
}
}
}
}
}
field = sortField;
return field;
}
// private <Q, S, E extends Throwable> String findSortField(LuceneQueryParserAdaptor<Q, S, E> lqpa, String field)
// {
// Locale sortLocale;
// List<Locale> locales = lqpa.getSearchParameters().getLocales();
// if (((locales == null) || (locales.size() == 0)))
// {
// locales = Collections.singletonList(I18NUtil.getLocale());
// }
//
// if (locales.size() > 1)
// {
// throw new SearcherException("Order on text/mltext properties with more than one locale is not curently supported");
// }
//
// sortLocale = locales.get(0);
// // find best field match
//
// HashSet<String> allowableLocales = new HashSet<String>();
// MLAnalysisMode analysisMode = lqpa.getDefaultSearchMLAnalysisMode();
// for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false))
// {
// allowableLocales.add(l.toString());
// }
//
// field = lqpa.getSortField(field);
//
// String sortField = field;
//
// for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED))
// {
// String currentString = (String) current;
// if (currentString.startsWith(field) && currentString.endsWith(".sort"))
// {
// String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - 5);
// if (allowableLocales.contains(fieldLocale))
// {
// if (fieldLocale.equals(sortLocale.toString()))
// {
// sortField = currentString;
// break;
// }
// else if (sortLocale.toString().startsWith(fieldLocale))
// {
// if (sortField.equals(field) || (currentString.length() < sortField.length()))
// {
// sortField = currentString;
// }
// }
// else if (fieldLocale.startsWith(sortLocale.toString()))
// {
// if (sortField.equals(field) || (currentString.length() < sortField.length()))
// {
// sortField = currentString;
// }
// }
// }
// }
// }
//
// field = sortField;
// return field;
// }
private QName alfrescoName;