Project

General

Profile

Revision 8287f797

ID8287f797f13fb2970d01657f1ac5c47c7efd3820
Parent d494a61d
Child cb312388

Added by Cherian Mathew about 7 years ago

ClassInfoBridge : New class bridge to set class information in the index
AcceptedTaxonBridge : New class bridge to set accepted taxon information in the index

View differences:

.gitattributes
683 683
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/UUIDUserType.java -text
684 684
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/WSDLDefinitionUserType.java -text
685 685
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/AbstractClassBridge.java -text
686
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/AcceptedTaxonBridge.java -text
687
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/ClassInfoBridge.java -text
686 688
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/DateTimeBridge.java -text
687 689
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/DefinedTermBaseClassBridge.java -text
688 690
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/DescriptionBaseClassBridge.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/AcceptedTaxonBridge.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.hibernate.search;
10

  
11
import java.util.Set;
12

  
13
import org.apache.lucene.document.Document;
14
import org.apache.lucene.document.Field;
15
import org.hibernate.search.bridge.FieldBridge;
16
import org.hibernate.search.bridge.LuceneOptions;
17

  
18
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19
import eu.etaxonomy.cdm.model.taxon.Synonym;
20
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22

  
23
/**
24
 * Lucene index class bridge which sets the uuids of the accepted taxon for the 
25
 * TaxonBase object into the index.
26
 *
27
 * @author c.mathew
28
 * @version 1.0
29
 * @created 26 Jul 2013
30
 */
31
public class AcceptedTaxonBridge implements FieldBridge {
32

  
33
	public final static String ACCEPTED_TAXON_UUID_LIST_SEP = ",";
34
	private final static String DOC_KEY_SUFFIX = ".uuids";
35
	
36
	@Override
37
	public void set(String name, Object value, Document document,
38
			LuceneOptions luceneOptions) {
39
		String accTaxonUuids = "";
40
		
41
		// in the case of taxon this is just the uuid
42
		if(value instanceof Taxon) {
43
			accTaxonUuids = ((Taxon)value).getUuid().toString();
44
		}				
45
		// in the case of synonym this is the accepted taxon in the synonym
46
		// relationships
47
        if (value instanceof Synonym) {
48
        	StringBuilder sb = new StringBuilder(); 
49
            Synonym synonym = (Synonym) value;
50
            Set<SynonymRelationship> synRelationships = synonym.getSynonymRelations();
51
            for (SynonymRelationship sr : synRelationships) {
52
            	Taxon accTaxon = sr.getAcceptedTaxon();
53
            	sb.append(accTaxon.getUuid().toString());
54
            	sb.append(ACCEPTED_TAXON_UUID_LIST_SEP);
55
            }
56
            accTaxonUuids = sb.toString();
57
            if(accTaxonUuids.length() > 0) {
58
            	accTaxonUuids = accTaxonUuids.substring(0, accTaxonUuids.length()-1);
59
            }
60
        }
61

  
62
        Field canonicalNameField = new Field(name + DOC_KEY_SUFFIX,
63
        		accTaxonUuids,
64
        		luceneOptions.getStore(),
65
        		luceneOptions.getIndex(),
66
        		luceneOptions.getTermVector());
67
        canonicalNameField.setBoost(luceneOptions.getBoost());
68
        document.add(canonicalNameField);
69

  
70
	}
71
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/ClassInfoBridge.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.hibernate.search;
10

  
11
import org.apache.lucene.document.Document;
12
import org.apache.lucene.document.Field;
13
import org.hibernate.search.bridge.FieldBridge;
14
import org.hibernate.search.bridge.LuceneOptions;
15
/**
16
 * Lucene index class bridge which sets class information for the objects into the index
17
 *
18
 * @author c.mathew
19
 * @version 1.0
20
 * @created 26 Jul 2013
21
 */
22
public class ClassInfoBridge implements FieldBridge {
23

  
24
	@Override
25
	public void set(String name, Object value, Document document,
26
			LuceneOptions luceneOptions) {
27
		Field nameField = new Field(name + ".name",
28
				value.getClass().getName(),
29
				luceneOptions.getStore(),
30
				luceneOptions.getIndex(),
31
				luceneOptions.getTermVector());
32
		nameField.setBoost(luceneOptions.getBoost());
33
		document.add(nameField);
34
		
35
		Field canonicalNameField = new Field(name + ".canonicalName",
36
				value.getClass().getCanonicalName(),
37
				luceneOptions.getStore(),
38
				luceneOptions.getIndex(),
39
				luceneOptions.getTermVector());
40
		canonicalNameField.setBoost(luceneOptions.getBoost());
41
		document.add(canonicalNameField);
42

  
43
	}
44
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)