1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal.metadata

File ObjectSolrMetadataExtractor.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
18
2
1
108
52
3
0.17
9
2
1.5

Classes

Class Line # Actions
ObjectSolrMetadataExtractor 48 18 0% 3 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.search.solr.internal.metadata;
21   
22    import java.util.Locale;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.apache.solr.common.SolrInputDocument;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.search.solr.internal.api.FieldUtils;
33    import org.xwiki.search.solr.internal.reference.SolrReferenceResolver;
34   
35    import com.xpn.xwiki.doc.XWikiDocument;
36    import com.xpn.xwiki.objects.BaseObject;
37    import com.xpn.xwiki.objects.BaseObjectReference;
38   
39    /**
40    * Extract the metadata to be indexed from attachments.
41    *
42    * @version $Id: 51f65d043b7146831fc8077db27f85444f6ac32f $
43    * @since 4.3M2
44    */
45    @Component
46    @Named("object")
47    @Singleton
 
48    public class ObjectSolrMetadataExtractor extends AbstractSolrMetadataExtractor
49    {
50    /**
51    * The Solr reference resolver.
52    */
53    @Inject
54    @Named("object")
55    private SolrReferenceResolver resolver;
56   
 
57  678 toggle @Override
58    public boolean setFieldsInternal(LengthSolrInputDocument solrDocument, EntityReference entityReference)
59    throws Exception
60    {
61  678 BaseObjectReference objectReference = new BaseObjectReference(entityReference);
62   
63  678 DocumentReference classReference = objectReference.getXClassReference();
64  678 DocumentReference documentReference = new DocumentReference(objectReference.getParent());
65   
66  678 XWikiDocument document = getDocument(documentReference);
67  678 BaseObject object = document.getXObject(objectReference);
68  678 if (object == null) {
69  2 return false;
70    }
71   
72  676 solrDocument.setField(FieldUtils.ID, resolver.getId(object.getReference()));
73  676 setDocumentFields(documentReference, solrDocument);
74  676 solrDocument.setField(FieldUtils.TYPE, objectReference.getType().name());
75  676 solrDocument.setField(FieldUtils.CLASS, localSerializer.serialize(classReference));
76  676 solrDocument.setField(FieldUtils.NUMBER, objectReference.getObjectNumber());
77   
78  676 setLocaleAndContentFields(documentReference, solrDocument, object);
79   
80  676 return true;
81    }
82   
83    /**
84    * Set the locale to all the translations that the owning document has. This ensures that this entity is found for
85    * all the translations of a document, not just the original document.
86    * <p>
87    * Also, index the content with each locale so that the right analyzer is used.
88    *
89    * @param documentReference the original document's reference.
90    * @param solrDocument the Solr document where to add the fields.
91    * @param object the object.
92    * @throws Exception if problems occur.
93    */
 
94  676 toggle protected void setLocaleAndContentFields(DocumentReference documentReference, SolrInputDocument solrDocument,
95    BaseObject object) throws Exception
96    {
97    // Do the work for each locale.
98  676 for (Locale documentLocale : getLocales(documentReference, null)) {
99  1374 solrDocument.addField(FieldUtils.LOCALES, documentLocale);
100   
101  1374 setObjectContent(solrDocument, object, documentLocale);
102    }
103   
104    // We can`t rely on the schema's copyField here because we would trigger it for each locale. Doing the copy to
105    // the text_general field manually.
106  676 setObjectContent(solrDocument, object, null);
107    }
108    }