Project

General

Profile

Revision ece6cbb6

IDece6cbb698eabc4a9e0dcf860f400d3bf1bee0c6
Parent 3fd8f26b
Child 6635b6cf

Added by Cherian Mathew about 7 years ago

ICdmMassIndexer : added methods to clear and add classes to the list of indexed classes
CdmMassIndexer : implemented the new methods in ICdmMassIndexer
TaxonServiceSearchTest : updated test to initialise the list of indexed classes

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/CdmMassIndexer.java
12 12
import java.io.IOException;
13 13
import java.lang.reflect.Field;
14 14
import java.util.ArrayList;
15
import java.util.HashSet;
15 16
import java.util.Iterator;
16 17
import java.util.List;
18
import java.util.Set;
17 19

  
18 20
import org.apache.log4j.Logger;
19 21
import org.apache.lucene.index.IndexReader;
......
61 63
@Transactional
62 64
public class CdmMassIndexer implements ICdmMassIndexer {
63 65

  
66
	private Set<Class<? extends CdmBase>> indexedClasses = new HashSet<Class<? extends CdmBase>>();
64 67
    public static final Logger logger = Logger.getLogger(CdmMassIndexer.class);
65 68

  
66 69
    /*
......
257 260
        }
258 261

  
259 262
        monitor.setTaskName("CdmMassIndexer");
260
        int steps = indexedClasses().length + 1; // +1 for optimize
261
        monitor.beginTask("Reindexing " + indexedClasses().length + " classes", steps);
263
        int steps = indexedClasses().size() + 1; // +1 for optimize
264
        monitor.beginTask("Reindexing " + indexedClasses().size() + " classes", steps);
262 265

  
263 266
        for(Class<? extends CdmBase> type : indexedClasses()){
264 267
            reindex(type, monitor);
265 268
        }
266 269

  
267
        optimize();
268
        monitor.worked(1);
269

  
270
        monitor.subTask("Optimizing Index");
271
        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
272
        subMonitor.beginTask("Optimizing Index",1);
273
        optimize();        
274
        subMonitor.worked(1);
275
        logger.info("end index optimization");
276
        subMonitor.done();
277
        
278
        //monitor.worked(1);
270 279
        monitor.done();
271 280
    }
272 281

  
......
317 326
        }
318 327

  
319 328
        monitor.setTaskName("CdmMassIndexer");
320
        int steps = indexedClasses().length + 1; // +1 for optimize
321
        monitor.beginTask("Purging " + indexedClasses().length + " classes", steps);
329
        int steps = indexedClasses().size() + 1; // +1 for optimize
330
        monitor.beginTask("Purging " + indexedClasses().size() + " classes", steps);
322 331

  
323 332
        for(Class<? extends CdmBase> type : indexedClasses()){
324 333
            purge(type, monitor);
......
364 373
     */
365 374
    @SuppressWarnings("unchecked")
366 375
    @Override
367
    public Class<? extends CdmBase>[] indexedClasses() {
368
        return new Class[] {
369
                TaxonBase.class,
370
                DescriptionElementBase.class,
371
                Classification.class,
372
                TaxonNameBase.class,
373
                SpecimenOrObservationBase.class
374
                };
376
    public Set<Class<? extends CdmBase>> indexedClasses() {
377
//    	indexedClasses.clear();
378
//    	indexedClasses.add(DescriptionElementBase.class);
379
//    	indexedClasses.add(TaxonBase.class);
380
//    	indexedClasses.add(DescriptionElementBase.class);
381
//    	indexedClasses.add(Classification.class);
382
//    	indexedClasses.add(TaxonNameBase.class);
383
//    	indexedClasses.add(SpecimenOrObservationBase.class);
384
        return indexedClasses;
375 385
    }
376 386

  
377 387
    /**
......
384 394
                };
385 395
    }
386 396

  
397
	@Override
398
	public void addToIndexedClasses(Class<? extends CdmBase> cdmBaseClass) {
399
		indexedClasses.add(cdmBaseClass);
400
		
401
	}
402

  
403
	@Override
404
	public void clearIndexedClasses() {
405
		indexedClasses.clear();		
406
	}
407

  
387 408

  
388 409
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/ICdmMassIndexer.java
1 1
package eu.etaxonomy.cdm.api.service.search;
2 2

  
3
import java.util.Set;
4

  
3 5
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
6
import eu.etaxonomy.cdm.model.common.CdmBase;
4 7

  
5 8
/**
6 9
 * @author andreas
......
22 25
     */
23 26
    public abstract void purge(IProgressMonitor monitor);
24 27

  
25
    public Class[] indexedClasses();
28
    /**
29
     * Returns a list of (sub-classes of CdmBase) classes to be indexed.
30
     *
31
     * @return a List of {@link CdmBase} sub classes
32
     */
33
    public Set<Class<? extends CdmBase>> indexedClasses();
34
    
35
    /**
36
     * Adds to the current list of (sub-classes of CdmBase) classes to be indexed.
37
     *
38
     * @param cdmBaseClass sub-class of CdmBase class to add
39
     */
40
    public void addToIndexedClasses(Class<? extends CdmBase> cdmBaseClass);
26 41
    
27 42
    /**
43
     * Clears the current list of (sub-classes of CdmBase) classes to be indexed.     
44
     */
45
    public void clearIndexedClasses();
46
    /**
28 47
     * Create (spell-checking) dictionary listed in {@link ICdmMassIndexer#dictionaryClasses()}.
29 48
     * This action will not purge the dictionary.
30 49
     * @param monitor TODO
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.java
27 27
import org.apache.lucene.index.CorruptIndexException;
28 28
import org.apache.lucene.queryParser.ParseException;
29 29
import org.junit.Assert;
30
import org.junit.Before;
30 31
import org.junit.Ignore;
31 32
import org.junit.Test;
32 33
import org.unitils.dbunit.annotation.DataSet;
......
106 107

  
107 108
    private static final int BENCHMARK_ROUNDS = 300;
108 109

  
110
	/**
111
	 * @throws java.lang.Exception
112
	 */
113
	@Before
114
	public void setUp() throws Exception {
115
		indexer.clearIndexedClasses();
116
    	indexer.addToIndexedClasses(DescriptionElementBase.class);
117
		indexer.addToIndexedClasses(TaxonBase.class);
118
	}
109 119
    @Test
110 120
    public void testDbUnitUsageTest() throws Exception {
111 121
        assertNotNull("taxonService should exist", taxonService);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)