Project

General

Profile

Revision 525e5ef8

ID525e5ef8a1d8f0266c240bad08bb9438bbb26e43
Parent b476aa03
Child b5e2a640

Added by Andreas Müller about 2 years ago

ref #5974 fully remove multi value field logic from AcceptedTaxonBridge

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/AcceptedTaxonBridge.java
34 34
 */
35 35
public class AcceptedTaxonBridge implements FieldBridge { // TODO inherit from AbstractClassBridge since this base class provides presets for id fields?
36 36

  
37
    public final static String ACCEPTED_TAXON_UUID_LIST_SEP = ",";
38
    private final static String DOC_KEY_UUID_SUFFIX = ".uuids"; // TODO do not use the plural for the field name
39
    private static final String DOC_KEY_ID_SUFFIX = ".id";
37
    public final static String DOC_KEY_UUID_SUFFIX = ".uuid";
38
    public static final String DOC_KEY_ID_SUFFIX = ".id";
39
    public final static String DOC_KEY_PUBLISH_SUFFIX = ".publish";
40 40

  
41 41
    @Override
42 42
    public void set(String name, Object value, Document document,
43 43
            LuceneOptions luceneOptions) {
44
        String accTaxonUuids = "";
44
        String accTaxonUuid = "";
45

  
46
        Taxon accTaxon;
47
        if(value instanceof Taxon){
48
            accTaxon = (Taxon)value;
49
        }else if (value instanceof Synonym){
50
            accTaxon = ((Synonym)value).getAcceptedTaxon();
51
        }else{
52
            throw new RuntimeException("Unhandled taxon base class: " + value.getClass().getSimpleName());
53
        }
45 54

  
46 55
        // in the case of taxon this is just the uuid
47
        if(value instanceof Taxon) {
48
            accTaxonUuids = ((Taxon)value).getUuid().toString();
56
        if(accTaxon != null) {
57
            //id
49 58
            Field canonicalNameIdField = new StringField(name + DOC_KEY_ID_SUFFIX,
50
                    Integer.toString(((Taxon)value).getId()),
59
                    Integer.toString(accTaxon.getId()),
51 60
                    luceneOptions.getStore()
52 61
                    );
53 62
            document.add(canonicalNameIdField);
63
            //uuid
64
            accTaxonUuid = accTaxon.getUuid().toString();
65
            Field canonicalNameUuidField = new StringField(name + DOC_KEY_UUID_SUFFIX,
66
                    accTaxonUuid,
67
                    luceneOptions.getStore()
68
                    );
69
            //TODO  do we really need to set the boost for an id field?
70
            canonicalNameUuidField.setBoost(luceneOptions.getBoost());
71
            document.add(canonicalNameUuidField);
54 72
        }
55
        // in the case of synonym this is the accepted taxon in the synonym
56
        // relationships
57
        if (value instanceof Synonym) {
58
            StringBuilder sb = new StringBuilder();
59
            Synonym synonym = (Synonym) value;
60
            Taxon accTaxon = synonym.getAcceptedTaxon();
61
            if (accTaxon != null){
62
                sb.append(accTaxon.getUuid().toString());
63
                sb.append(ACCEPTED_TAXON_UUID_LIST_SEP);
64
                // adding the accTaxon id as multivalue field:
65
                Field canonicalNameIdField = new StringField(name + DOC_KEY_ID_SUFFIX,
66
                        Integer.toString(accTaxon.getId()),
67
                        luceneOptions.getStore()
68
                        );
69
                document.add(canonicalNameIdField);
70
            }
71

  
72
            accTaxonUuids = sb.toString();
73
            if(accTaxonUuids.length() > 0) {
74
                accTaxonUuids = accTaxonUuids.substring(0, accTaxonUuids.length()-1);
75
            }
76
        }
77

  
78
        // TODO can't we also add the uuid as multivalue field?
79

  
80
        // the id field is shorter and should be sufficient
81
        Field canonicalNameUuidField = new StringField(name + DOC_KEY_UUID_SUFFIX,
82
                accTaxonUuids,
83
                luceneOptions.getStore()
84
                );
85
        //TODO  do we really need to set the boost for an id field?
86
        canonicalNameUuidField.setBoost(luceneOptions.getBoost());
87
        document.add(canonicalNameUuidField);
88

  
89 73
    }
90 74
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/dto/NameCatalogueController.java
423 423
                            searchResult.getMaxScore(),
424 424
                            doc.getValues("uuid")[0].toString(),
425 425
                            doc.getValues("taxonBases.uuid"),
426
                            mergeSynAccTaxonUuids(doc.getValues("taxonBases.accTaxon.uuids")));
426
                            mergeSynAccTaxonUuids(doc.getValues("taxonBases.accTaxon"+AcceptedTaxonBridge.DOC_KEY_UUID_SUFFIX)));
427 427
                    }
428 428
                }
429 429
                nsList.add(ns);
......
597 597
                            searchResult.getMaxScore(),
598 598
                            doc.getValues("uuid")[0].toString(),
599 599
                            doc.getValues("taxonBases.uuid"),
600
                            mergeSynAccTaxonUuids(doc.getValues("taxonBases.accTaxon.uuids")));
600
                            mergeSynAccTaxonUuids(doc.getValues("taxonBases.accTaxon"+AcceptedTaxonBridge.DOC_KEY_UUID_SUFFIX)));
601 601
                    }
602 602
                }
603 603
                nsList.add(ns);
......
616 616
    private String[] mergeSynAccTaxonUuids(String[] accTaxonUuids) {
617 617
        List<String> accTaxonUuidList = new ArrayList<>();
618 618
        for(String accTaxonUuid : accTaxonUuids) {
619
            for(String uuidListAsString : accTaxonUuid.split(AcceptedTaxonBridge.ACCEPTED_TAXON_UUID_LIST_SEP)) {
620
                accTaxonUuidList.add(uuidListAsString);
621
            }
619
              accTaxonUuidList.add(accTaxonUuid);
622 620
        }
623 621
        return accTaxonUuidList.toArray(new String[0]);
624 622

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
64 64
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
65 65
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
66 66
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
67
import eu.etaxonomy.cdm.hibernate.search.AcceptedTaxonBridge;
67 68
import eu.etaxonomy.cdm.hibernate.search.DefinedTermBaseClassBridge;
68 69
import eu.etaxonomy.cdm.hibernate.search.GroupByTaxonClassBridge;
69 70
import eu.etaxonomy.cdm.hibernate.search.MultilanguageTextFieldBridge;
......
1752 1753
            if(addDistributionFilter && searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)){
1753 1754
                // add additional area filter for synonyms
1754 1755
                String fromField = "inDescription.taxon.id"; // in DescriptionElementBase index
1755
                String toField = "accTaxon.id"; // id in TaxonBase index (is multivalued)
1756
                String toField = "accTaxon" + AcceptedTaxonBridge.DOC_KEY_ID_SUFFIX; // id in TaxonBase index
1756 1757

  
1757 1758
                //TODO replace by createByDistributionJoinQuery
1758 1759
                BooleanQuery byDistributionQuery = createByDistributionQuery(namedAreaList, distributionStatusList, distributionFilterQueryFactory);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)