Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
add options to reindex page
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Apr 20, 2012
1 parent 0adc6cf commit 5647f58
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 9 deletions.
@@ -1,5 +1,7 @@
package org.zanata.action;

import java.util.Collection;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -17,6 +19,11 @@ public class ReindexActionBean
@In
ReindexAsyncBean reindexAsync;

public Collection<ReindexClassOptions> getClasses()
{
return reindexAsync.getReindexOptions();
}

public boolean isReindexing()
{
return reindexAsync.isReindexing();
Expand Down
@@ -1,5 +1,7 @@
package org.zanata.action;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -45,6 +47,7 @@ public class ReindexAsyncBean
private FullTextSession session;

private Set<Class<?>> indexables = new HashSet<Class<?>>();
private HashMap<Class<?>, ReindexClassOptions> indexingOptions = new HashMap<Class<?>, ReindexClassOptions>();

private boolean reindexing;

Expand All @@ -69,6 +72,16 @@ public void create()
indexables.add(HTextFlowTarget.class);
indexables.add(HGlossaryTerm.class);
indexables.add(HGlossaryEntry.class);

for (Class<?> clazz : indexables)
{
indexingOptions.put(clazz, new ReindexClassOptions(clazz));
}
}

public Collection<ReindexClassOptions> getReindexOptions()
{
return indexingOptions.values();
}

/**
Expand All @@ -92,7 +105,10 @@ public void prepareReindex()
objectCount = 0;
for (Class<?> clazz : indexables)
{
objectCount += (Integer) session.createCriteria(clazz).setProjection(Projections.rowCount()).list().get(0);
if (indexingOptions.get(clazz).isReindex())
{
objectCount += (Integer) session.createCriteria(clazz).setProjection(Projections.rowCount()).list().get(0);
}
}
objectProgress = 0;
}
Expand All @@ -109,10 +125,31 @@ public void startReindex()
throw new RuntimeException("startReindex() must not be called before prepareReindex()");
}

// reindex all @Indexed entities
for (Class<?> clazz : indexables)
{
reindex(clazz);
if (indexingOptions.get(clazz).isPurge())
{
log.info("purging index for {0}", clazz);
session.purgeAll(clazz);
}
}

for (Class<?> clazz : indexables)
{
if (indexingOptions.get(clazz).isReindex())
{
log.info("reindexing {0}", clazz);
reindex(clazz);
}
}

for (Class<?> clazz : indexables)
{
if (indexingOptions.get(clazz).isOptimize())
{
log.info("optimizing {0}", clazz);
session.getSearchFactory().optimize(clazz);
}
}

if (objectCount != objectProgress)
Expand All @@ -135,11 +172,9 @@ private void reindex(Class<?> clazz)
ScrollableResults results = null;
try
{
session.purgeAll(clazz);

// TODO try this, see how it affects reindexing time:
//session.flushToIndexes();
//session.getSearchFactory().optimize(clazz);
// session.getSearchFactory().optimize(clazz);

session.setFlushMode(FlushMode.MANUAL);
session.setCacheMode(CacheMode.IGNORE);
Expand All @@ -159,8 +194,6 @@ private void reindex(Class<?> clazz)
}
}
session.flushToIndexes(); // apply changes to indexes
// TODO try this too, see how it affects reindexing time:
//session.getSearchFactory().optimize(clazz);
session.clear(); // clear since the queue is processed
}
catch (Exception e)
Expand Down
@@ -0,0 +1,57 @@
package org.zanata.action;

/**
* Stores options for the lucene indexing
*
* @author David Mason, damason@redhat.com
*/
public class ReindexClassOptions
{
private Class<?> clazz;
private boolean purge = false;
private boolean reindex = false;
private boolean optimize = false;

public ReindexClassOptions(Class<?> indexableClass)
{
clazz = indexableClass;
}

public String getClassName()
{
return clazz.getSimpleName();
}

public boolean isPurge()
{
return purge;
}

public void setPurge(boolean shouldPurge)
{
this.purge = shouldPurge;
}

public boolean isReindex()
{
return reindex;
}

public void setReindex(boolean shouldReindex)
{
this.reindex = shouldReindex;
}

public boolean isOptimize()
{
return optimize;
}

public void setOptimize(boolean optimize)
{
this.optimize = optimize;
}



}
23 changes: 22 additions & 1 deletion server/zanata-war/src/main/webapp/admin/search.xhtml
Expand Up @@ -13,7 +13,7 @@
<ui:define name="center_content">
<rich:jQuery selector="#tab_admin" query="addClass('ui-tabs-selected')" />
<rich:panel>
<h1>#{messages['jsf.Search']}</h1>
<h1>#{messages['jsf.Search']}</h1>

<!-- TODO reformat indentation, change button label id to match progress message id -->
<a4j:form>
Expand All @@ -26,6 +26,27 @@
<h:outputText rendered="#{reindexAction.reindexError}" escape="false">
<p>#{messages['jsf.search.reindex.PleaseReindex']}</p>
</h:outputText>

<rich:dataTable id="classList" rows="#{reindexAction.classes.size}"
value="#{reindexAction.classes.toArray()}" var="clazz">
<rich:column width="270px" sortBy="#{clazz.className}">
<f:facet name="header">Class</f:facet>
<h:outputText value="#{clazz.className}" />
</rich:column>
<rich:column width="auto" styleClass="centered">
<f:facet name="header">Purge index</f:facet>
<h:selectBooleanCheckbox value="#{clazz.purge}" />
</rich:column>
<rich:column width="auto" styleClass="centered">
<f:facet name="header">Reindex</f:facet>
<h:selectBooleanCheckbox value="#{clazz.reindex}" />
</rich:column>
<rich:column width="auto" styleClass="centered">
<f:facet name="header">Optimize</f:facet>
<h:selectBooleanCheckbox value="#{clazz.optimize}" />
</rich:column>
</rich:dataTable>

<a4j:commandButton id="reindex"
value="#{messages['jsf.ReindexFullTextSearchDatabase']}"
action="#{reindexAction.reindexDatabase}"
Expand Down

0 comments on commit 5647f58

Please sign in to comment.