mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for MOB-1221: Sorting on an indexed field that has not yet been applied to any node causes an exception in the SearchService
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15702 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -502,7 +502,7 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean fieldHasTerm(IndexReader indexReader, String field)
|
||||
public static boolean fieldHasTerm(IndexReader indexReader, String field)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -958,6 +958,18 @@ public class ADMLuceneTest extends TestCase
|
||||
|
||||
results.close();
|
||||
|
||||
sp = new SearchParameters();
|
||||
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
|
||||
sp.addStore(rootNodeRef.getStoreRef());
|
||||
sp.setQuery("-eager or -dog");
|
||||
sp.addQueryTemplate("ANDY", "%cm:content");
|
||||
sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
sp.excludeDataInTheCurrentTransaction(true);
|
||||
sp.addSort("test:neverIndexed", false);
|
||||
results = searcher.query(sp);
|
||||
assertEquals(15, results.length());
|
||||
results.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,12 @@
|
||||
<title>Test Super Type</title>
|
||||
<parent>sys:container</parent>
|
||||
<properties>
|
||||
<property name="test:neverIndexed">
|
||||
<type>d:any</type>
|
||||
<mandatory>false</mandatory>
|
||||
<multiple>false</multiple>
|
||||
<index enabled="false"/>
|
||||
</property>
|
||||
<property name="test:createdDate">
|
||||
<type>d:date</type>
|
||||
<mandatory>true</mandatory>
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.search.impl.querymodel.impl.lucene;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl;
|
||||
import org.alfresco.repo.search.impl.querymodel.Column;
|
||||
import org.alfresco.repo.search.impl.querymodel.Constraint;
|
||||
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
|
||||
@@ -181,10 +182,17 @@ public class LuceneQuery extends BaseQuery implements LuceneQueryBuilder
|
||||
String luceneField = functionContext.getLuceneSortField(luceneContext.getLuceneQueryParser(), propertyName);
|
||||
|
||||
if (luceneField != null)
|
||||
{
|
||||
if (ADMLuceneSearcherImpl.fieldHasTerm(luceneContext.getLuceneQueryParser().getIndexReader(), luceneField))
|
||||
{
|
||||
fields[index++] = new SortField(luceneField, (ordering.getOrder() == Order.DESCENDING));
|
||||
}
|
||||
else
|
||||
{
|
||||
fields[index++] = new SortField(null, SortField.DOC, (ordering.getOrder() == Order.DESCENDING));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
Reference in New Issue
Block a user