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
|
try
|
||||||
{
|
{
|
||||||
|
@@ -958,6 +958,18 @@ public class ADMLuceneTest extends TestCase
|
|||||||
|
|
||||||
results.close();
|
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>
|
<title>Test Super Type</title>
|
||||||
<parent>sys:container</parent>
|
<parent>sys:container</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
<property name="test:neverIndexed">
|
||||||
|
<type>d:any</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>false</multiple>
|
||||||
|
<index enabled="false"/>
|
||||||
|
</property>
|
||||||
<property name="test:createdDate">
|
<property name="test:createdDate">
|
||||||
<type>d:date</type>
|
<type>d:date</type>
|
||||||
<mandatory>true</mandatory>
|
<mandatory>true</mandatory>
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.search.impl.querymodel.impl.lucene;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.Column;
|
||||||
import org.alfresco.repo.search.impl.querymodel.Constraint;
|
import org.alfresco.repo.search.impl.querymodel.Constraint;
|
||||||
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
|
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
|
||||||
@@ -111,7 +112,7 @@ public class LuceneQuery extends BaseQuery implements LuceneQueryBuilder
|
|||||||
Query constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
Query constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, null, luceneContext, functionContext);
|
||||||
if (constraintQuery != null)
|
if (constraintQuery != null)
|
||||||
{
|
{
|
||||||
switch(constraint.getOccur())
|
switch (constraint.getOccur())
|
||||||
{
|
{
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
case MANDATORY:
|
case MANDATORY:
|
||||||
@@ -139,9 +140,9 @@ public class LuceneQuery extends BaseQuery implements LuceneQueryBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!must && must_not)
|
if (!must && must_not)
|
||||||
{
|
{
|
||||||
luceneQuery.add(new TermQuery(new Term("ISNODE", "T")), BooleanClause.Occur.MUST);
|
luceneQuery.add(new TermQuery(new Term("ISNODE", "T")), BooleanClause.Occur.MUST);
|
||||||
}
|
}
|
||||||
|
|
||||||
return luceneQuery;
|
return luceneQuery;
|
||||||
@@ -182,7 +183,14 @@ public class LuceneQuery extends BaseQuery implements LuceneQueryBuilder
|
|||||||
|
|
||||||
if (luceneField != null)
|
if (luceneField != null)
|
||||||
{
|
{
|
||||||
fields[index++] = new SortField(luceneField, (ordering.getOrder() == Order.DESCENDING));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user