Skip to content

Commit

Permalink
Merge pull request #1 from aborroy/feature/preview-search-details
Browse files Browse the repository at this point in the history
Feature/preview search details
  • Loading branch information
aborroy authored Apr 17, 2023
2 parents 4b3098c + a14b836 commit 49cd579
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.orderofthebee.addons.support.tools.repo.search;

/**
* SOLR Admin HTTP Client for native SOLR services.
* This interface describes operations not covered by the <a href="https://docs.alfresco.com/search-services/latest/admin/restapi/">Alfresco REST API for SOLR</a>
*
* @author Angel Borroy
*/
public interface SolrAdminNativeClient {

/**
* Get count of documents that require path indexing in SOLR.
* @param coreName name of the core: alfresco, archive
* @return Number of documents that require path indexing
*/
long getCascadeTrackerPendingCount(String coreName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.orderofthebee.addons.support.tools.repo.search.solr6;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.orderofthebee.addons.support.tools.repo.search.SolrAdminNativeClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

/**
* SOLR Admin HTTP Client for native SOLR services.
* This class provides access to requests not covered by the <a href="https://docs.alfresco.com/search-services/latest/admin/restapi/">Alfresco REST API for SOLR</a>
*
* @author Angel Borroy
*/
public class SolrAdminNativeClientImpl implements SolrAdminNativeClient {

private static final Logger LOGGER = LoggerFactory.getLogger(SolrAdminNativeClientImpl.class);

private HttpClient httpClient;

private String baseUrl;

/**
* {@inheritDoc}
*/
@Override
public long getCascadeTrackerPendingCount(String coreName) {
try {
GetMethod getMethod = new GetMethod(
httpClient.getHostConfiguration().getHostURL() + baseUrl + "/" + coreName + "/select"
+ "?fl=" + URLEncoder.encode("*,[cached]", StandardCharsets.UTF_8.toString())
+ "&q=" + URLEncoder.encode("{!term f=int@s_@cascade}1", StandardCharsets.UTF_8.toString())
+ "&wt=json");
httpClient.executeMethod(getMethod);
JSONObject json = (JSONObject) new JSONParser().parse(getMethod.getResponseBodyAsString());
JSONObject response = (JSONObject) json.get("response");
return (long) response.get("numFound");
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return -1;
}
}

public void setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="solrAdminNativeClient.proxy" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
<property name="sourceApplicationContextFactory">
<ref bean="solrAdminNativeClient.subsystem.search" />
</property>
<property name="sourceBeanName">
<value>solrAdminNativeClient</value>
</property>
<property name="interfaces">
<list>
<value>org.orderofthebee.addons.support.tools.repo.search.SolrAdminNativeClient</value>
</list>
</property>
</bean>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="solrAdminNativeClient" class="org.orderofthebee.addons.support.tools.repo.search.solr6.SolrAdminNativeClientImpl">
<property name="httpClient">
<bean factory-bean="solrHttpClientFactory" factory-method="getHttpClient" />
</property>
<property name="baseUrl" value="${solr.baseUrl}" />
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,27 @@ Copyright (C) 2005 - 2020 Alfresco Software Limited.

</div>

<div class="column-full">
<@section label=msg("solr-tracking.section.detail.title") />
<div class="column-left">
<@field value="${trackingSummary[coreName]['MetadataTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.metadata.title") description=msg("solr-tracking.section.detail.metadata.description")/>
<@field value="${trackingSummary[coreName]['ContentTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.content.title") description=msg("solr-tracking.section.detail.content.description")/>
<@field value="${trackingSummary[coreName]['AclTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.acl.title") description=msg("solr-tracking.section.detail.acl.description")/>
<@field value="${(cascadeTracker[coreName]['numFound'] > 0)?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.cascade.title") description=msg("solr-tracking.section.detail.cascade.description")/>
</div>
<div class="column-right">
<@field value="${trackingSummary[coreName]['Approx transactions remaining']?c}" label=msg("solr-tracking.section.detail.metadata.count.title") description=msg("solr-tracking.section.detail.metadata.count.description") />
<#if trackingSummary[coreName]['FTS']['Node count whose content needs to be updated']?has_content>
<@field value="${trackingSummary[coreName]['FTS']['Node count whose content needs to be updated']?c}" label=msg("solr-tracking.section.detail.content.count.title") description=msg("solr-tracking.section.detail.content.count.description")/>
<#else>
<@field value="${(trackingSummary[coreName]['FTS']['Node count with FTSStatus New'] + trackingSummary[coreName]['FTS']['Node count with FTSStatus Dirty'])?c}" label=msg("solr-tracking.section.detail.content.count.title") description=msg("solr-tracking.section.detail.content.count.description")/>
</#if>
<@field value="${trackingSummary[coreName]['Approx change sets remaining']?c}" label=msg("solr-tracking.section.detail.acl.count.title") description=msg("solr-tracking.section.detail.acl.count.description") />
<@field value="${cascadeTracker[coreName]['numFound']?c}" label=msg("solr-tracking.section.detail.cascade.count.title") description=msg("solr-tracking.section.detail.cascade.count.description") />
<div class="column-full">

<@section label=msg("solr-tracking.section.detail.title") />
<div class="column-left">
<@field value="${trackingSummary[coreName]['MetadataTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.metadata.title") description=msg("solr-tracking.section.detail.metadata.description")/>
<@field value="${trackingSummary[coreName]['ContentTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.content.title") description=msg("solr-tracking.section.detail.content.description")/>
<@field value="${trackingSummary[coreName]['AclTracker Active']?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.acl.title") description=msg("solr-tracking.section.detail.acl.description")/>
<@field value="${(cascadeTracker[coreName] > 0)?string(msg('solr-tracking.true'), msg('solr-tracking.false'))}" label=msg("solr-tracking.section.detail.cascade.title") description=msg("solr-tracking.section.detail.cascade.description")/>
</div>
<div class="column-right">
<@field value="${trackingSummary[coreName]['Approx transactions remaining']?c}" label=msg("solr-tracking.section.detail.metadata.count.title") description=msg("solr-tracking.section.detail.metadata.count.description") />
<#if trackingSummary[coreName]['FTS']['Node count whose content needs to be updated']?has_content>
<@field value="${trackingSummary[coreName]['FTS']['Node count whose content needs to be updated']?c}" label=msg("solr-tracking.section.detail.content.count.title") description=msg("solr-tracking.section.detail.content.count.description")/>
<#else>
<@field value="${(trackingSummary[coreName]['FTS']['Node count with FTSStatus New'] + trackingSummary[coreName]['FTS']['Node count with FTSStatus Dirty'])?c}" label=msg("solr-tracking.section.detail.content.count.title") description=msg("solr-tracking.section.detail.content.count.description")/>
</#if>
<@field value="${trackingSummary[coreName]['Approx change sets remaining']?c}" label=msg("solr-tracking.section.detail.acl.count.title") description=msg("solr-tracking.section.detail.acl.count.description") />
<@field value="${cascadeTracker[coreName]?c}" label=msg("solr-tracking.section.detail.cascade.count.title") description=msg("solr-tracking.section.detail.cascade.count.description") />
</div>

</div>
</div>

</#list>
</@page>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function buildPropertyGetter(ctxt)
/* exported loadSolrSummaryAndStatus */
function loadSolrSummaryAndStatus()
{
var ctxt, propertyGetter, indexSubsystem, solrContextFactory, solrContext, solrAdminClient, args, trackingSummaryResponse, trackingSummary, trackingStatusResponse, trackingStatus, coreNames;
var ctxt, propertyGetter, indexSubsystem, solrContextFactory, solrContext, solrAdminClient, solrAdminNativeClient, args, trackingSummaryResponse, trackingSummary, trackingStatusResponse, trackingStatus, coreNames;

ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
propertyGetter = buildPropertyGetter(ctxt);
Expand Down Expand Up @@ -93,25 +93,16 @@ function loadSolrSummaryAndStatus()
});
model.coreNames = coreNames;

if (/^solr([6])?$/.test(indexSubsystem)) {

model.cascadeTracker = [];

if (/^solr([6])?$/.test(indexSubsystem))
{
solrAdminNativeClient = solrContext
.getBean('solrAdminNativeClient', Packages.org.orderofthebee.addons.support.tools.repo.search.SolrAdminNativeClient);
model.cascadeTracker = [];
for (var i in coreNames) {
if (i) {
var solrHttpClientFactory = solrContext.getBean('solrHttpClientFactory', Packages.org.alfresco.httpclient.HttpClientFactory);
var getMethod =
new Packages.org.apache.commons.httpclient.methods.GetMethod(
solrHttpClientFactory.getHttpClient().getHostConfiguration().getHostURL() +
'/solr/' + coreNames[i] + '/select?' +
'?fl=' + encodeURIComponent('*,[cached]') +
'&q=' + encodeURIComponent('{!term f=int@s_@cascade}1') +
'&wt=json');
solrHttpClientFactory.getHttpClient().executeMethod(getMethod);
model.cascadeTracker[coreNames[i]] = JSON.parse(getMethod.getResponseBodyAsString()).response;
model.cascadeTracker[coreNames[i]] = solrAdminNativeClient.getCascadeTrackerPendingCount(coreNames[i]);
}
}

}

}
Expand Down

0 comments on commit 49cd579

Please sign in to comment.