mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Merge branch 'fix/SEARCH_1666' into 'master'
Fix/search 1666 See merge request search_discovery/insightengine!120
This commit is contained in:
+55
-60
@@ -18,6 +18,17 @@
|
||||
*/
|
||||
package org.alfresco.solr.tracker;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.stream.IntStream.range;
|
||||
import static org.alfresco.repo.search.adaptor.lucene.QueryConstants.FIELD_DOC_TYPE;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAcl;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAclReaders;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getNode;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.index.shard.ShardMethodEnum;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
@@ -31,9 +42,9 @@ import org.alfresco.solr.client.Node;
|
||||
import org.alfresco.solr.client.NodeMetaData;
|
||||
import org.alfresco.solr.client.StringPropertyValue;
|
||||
import org.alfresco.solr.client.Transaction;
|
||||
import org.alfresco.util.CachingDateFormat;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.junit.AfterClass;
|
||||
@@ -49,40 +60,23 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.alfresco.repo.search.adaptor.lucene.QueryConstants.FIELD_DOC_TYPE;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAcl;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getAclReaders;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getNode;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet;
|
||||
import static org.alfresco.solr.AlfrescoSolrUtils.list;
|
||||
|
||||
/**
|
||||
* @author Joel
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@SolrTestCaseJ4.SuppressSSL
|
||||
@LuceneTestCase.SuppressCodecs({"Appending","Lucene3x","Lucene40","Lucene41","Lucene42","Lucene43", "Lucene44", "Lucene45","Lucene46","Lucene47","Lucene48","Lucene49"})
|
||||
public class DistributedDateMonthAlfrescoSolrTrackerTest extends AbstractAlfrescoDistributedTest
|
||||
{
|
||||
@BeforeClass
|
||||
private static void initData() throws Throwable
|
||||
@SuppressWarnings("unused")
|
||||
public static void initData() throws Throwable
|
||||
{
|
||||
initSolrServers(5, "DistributedDateMonthAlfrescoSolrTrackerTest", getShardMethod());
|
||||
initSolrServers(5, DistributedDateMonthAlfrescoSolrTrackerTest.class.getSimpleName(), getShardMethod());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
private static void destroyData() throws Throwable
|
||||
@SuppressWarnings("unused")
|
||||
public static void destroyData()
|
||||
{
|
||||
dismissSolrServers();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDateMonth() throws Exception
|
||||
{
|
||||
@@ -91,58 +85,57 @@ public class DistributedDateMonthAlfrescoSolrTrackerTest extends AbstractAlfresc
|
||||
int numAcls = 25;
|
||||
AclChangeSet bulkAclChangeSet = getAclChangeSet(numAcls);
|
||||
|
||||
List<Acl> bulkAcls = new ArrayList();
|
||||
List<AclReaders> bulkAclReaders = new ArrayList();
|
||||
List<Acl> bulkAcls = new ArrayList<>();
|
||||
List<AclReaders> bulkAclReaders = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < numAcls; i++) {
|
||||
for (int i = 0; i < numAcls; i++)
|
||||
{
|
||||
Acl bulkAcl = getAcl(bulkAclChangeSet);
|
||||
bulkAcls.add(bulkAcl);
|
||||
bulkAclReaders.add(getAclReaders(bulkAclChangeSet,
|
||||
bulkAcl,
|
||||
list("joel" + bulkAcl.getId()),
|
||||
list("phil" + bulkAcl.getId()),
|
||||
singletonList("joel" + bulkAcl.getId()),
|
||||
singletonList("phil" + bulkAcl.getId()),
|
||||
null));
|
||||
}
|
||||
|
||||
indexAclChangeSet(bulkAclChangeSet,
|
||||
bulkAcls,
|
||||
bulkAclReaders);
|
||||
indexAclChangeSet(bulkAclChangeSet, bulkAcls, bulkAclReaders);
|
||||
|
||||
int numNodes = 1000;
|
||||
List<Node> nodes = new ArrayList();
|
||||
List<NodeMetaData> nodeMetaDatas = new ArrayList();
|
||||
List<Node> nodes = new ArrayList<>();
|
||||
List<NodeMetaData> nodeMetaData = new ArrayList<>();
|
||||
|
||||
Transaction bigTxn = getTransaction(0, numNodes);
|
||||
|
||||
Date[] dates = new Date[5];
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
for (int i = 0; i < dates.length; i++) {
|
||||
|
||||
cal.set(1980, i, 21);
|
||||
dates[i] = cal.getTime();
|
||||
}
|
||||
Date[] dates = range(0, 5)
|
||||
.peek(index -> calendar.set(1980, index, 21))
|
||||
.mapToObj(index -> calendar.getTime())
|
||||
.toArray(Date[]::new);
|
||||
|
||||
int[] counts = new int[dates.length];
|
||||
|
||||
for (int i = 0; i < numNodes; i++) {
|
||||
for (int i = 0; i < numNodes; i++)
|
||||
{
|
||||
int aclIndex = i % numAcls;
|
||||
int dateIndex = i % dates.length;
|
||||
String dateString = DefaultTypeConverter.INSTANCE.convert(String.class, dates[dateIndex]);
|
||||
|
||||
counts[dateIndex]++;
|
||||
|
||||
Node node = getNode(bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
|
||||
node.setShardPropertyValue(dateString);
|
||||
nodes.add(node);
|
||||
NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
|
||||
nodeMetaData.getProperties().put(ContentModel.PROP_CREATED,
|
||||
new StringPropertyValue(dateString));
|
||||
|
||||
nodeMetaDatas.add(nodeMetaData);
|
||||
NodeMetaData metadata = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
|
||||
metadata.getProperties().put(ContentModel.PROP_CREATED, new StringPropertyValue(dateString));
|
||||
|
||||
nodeMetaData.add(metadata);
|
||||
}
|
||||
|
||||
indexTransaction(bigTxn, nodes, nodeMetaDatas);
|
||||
indexTransaction(bigTxn, nodes, nodeMetaData);
|
||||
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), numNodes, 100000);
|
||||
waitForDocCountAllCores(new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL)), numAcls, 100000);
|
||||
|
||||
@@ -150,9 +143,7 @@ public class DistributedDateMonthAlfrescoSolrTrackerTest extends AbstractAlfresc
|
||||
AlfrescoSolrDataModel.FieldInstance fieldInstance = fieldInstanceList.get(0);
|
||||
String fieldName = fieldInstance.getField();
|
||||
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
SimpleDateFormat format = CachingDateFormat.getSolrDatetimeFormatWithoutMsecs();
|
||||
for (int i = 0; i < dates.length; i++)
|
||||
{
|
||||
String startDate = format.format(dates[i]);
|
||||
@@ -161,32 +152,36 @@ public class DistributedDateMonthAlfrescoSolrTrackerTest extends AbstractAlfresc
|
||||
gcal.add(Calendar.SECOND, 1);
|
||||
String endDate = format.format(gcal.getTime());
|
||||
|
||||
SolrQuery solrQuery = new SolrQuery("{!lucene}" + escapeQueryChars(fieldName) +
|
||||
":[" + escapeQueryChars(startDate) + " TO " + escapeQueryChars(endDate) + " } " );
|
||||
SolrQuery solrQuery =
|
||||
new SolrQuery("{!lucene}" + escapeQueryChars(fieldName) + ":[" + escapeQueryChars(startDate) + " TO " + escapeQueryChars(endDate) + " } " );
|
||||
|
||||
assertCountAndColocation(solrQuery, counts[i]);
|
||||
assertShardSequence(i, solrQuery, counts[i]);
|
||||
}
|
||||
|
||||
nodes.clear();
|
||||
nodeMetaDatas.clear();
|
||||
nodeMetaData.clear();
|
||||
|
||||
Transaction bigTxn1 = getTransaction(0, numNodes);
|
||||
|
||||
for (int i = 0; i < numNodes; i++) {
|
||||
for (int i = 0; i < numNodes; i++)
|
||||
{
|
||||
int aclIndex = i % numAcls;
|
||||
Node node = getNode(bigTxn1, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
|
||||
nodes.add(node);
|
||||
NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn1, bulkAcls.get(aclIndex), "mike", null, false);
|
||||
nodeMetaDatas.add(nodeMetaData);
|
||||
|
||||
NodeMetaData metadata = getNodeMetaData(node, bigTxn1, bulkAcls.get(aclIndex), "mike", null, false);
|
||||
nodeMetaData.add(metadata);
|
||||
}
|
||||
|
||||
indexTransaction(bigTxn1, nodes, nodeMetaDatas);
|
||||
indexTransaction(bigTxn1, nodes, nodeMetaData);
|
||||
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), numNodes*2, 100000);
|
||||
|
||||
//There are 5 shards. We should expect roughly 20% of the nodes on each shard
|
||||
assertNodesPerShardGreaterThan((int)((numNodes*2)*.17));
|
||||
}
|
||||
|
||||
protected static Properties getShardMethod()
|
||||
private static Properties getShardMethod()
|
||||
{
|
||||
Properties prop = new Properties();
|
||||
prop.put("shard.method", ShardMethodEnum.DATE.toString());
|
||||
|
||||
Reference in New Issue
Block a user