View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.solr.classification;
20  
21  import org.apache.solr.common.SolrInputDocument;
22  import org.mycore.datamodel.classifications2.MCRCategLinkReference;
23  import org.mycore.datamodel.classifications2.MCRCategoryID;
24  
25  /**
26   * Simple helper class to handle a classification link in solr.
27   * 
28   * @author Matthias Eichner
29   */
30  public class MCRSolrCategoryLink {
31  
32      private MCRCategoryID categoryId;
33  
34      private MCRCategLinkReference linkReference;
35  
36      /**
37       * Creates a new link object.
38       * 
39       * @param categoryId category of the link 
40       * @param linkReference the link reference
41       */
42      public MCRSolrCategoryLink(MCRCategoryID categoryId, MCRCategLinkReference linkReference) {
43          this.categoryId = categoryId;
44          this.linkReference = linkReference;
45      }
46  
47      /**
48       * Transform this link object to a solr document.
49       * <ul>
50       * <li>id - combination of the object id and the category separated by a dollar sign </li>
51       * <li>object - object id</li>
52       * <li>category - category id</li>
53       * <li>type - fix string "link"</li>
54       * <li>linkType - type of the link</li>
55       * </ul>
56       * 
57       * @return a new solr document
58       */
59      public SolrInputDocument toSolrDocument() {
60          SolrInputDocument doc = new SolrInputDocument();
61          String objectId = linkReference.getObjectID();
62          String catId = categoryId.toString();
63          doc.setField("id", objectId + "$" + catId);
64          doc.setField("object", objectId);
65          doc.setField("category", catId);
66          doc.setField("type", "link");
67          doc.setField("linkType", linkReference.getType());
68          return doc;
69      }
70  
71  }