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

File ObjectPropertySolrMetadataExtractor.java

 

Coverage histogram

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

Code metrics

2
17
2
1
112
53
3
0.18
8.5
2
1.5

Classes

Class Line # Actions
ObjectPropertySolrMetadataExtractor 49 17 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.model.reference.ObjectPropertyReference;
33    import org.xwiki.search.solr.internal.api.FieldUtils;
34    import org.xwiki.search.solr.internal.reference.SolrReferenceResolver;
35   
36    import com.xpn.xwiki.doc.XWikiDocument;
37    import com.xpn.xwiki.objects.BaseObjectReference;
38    import com.xpn.xwiki.objects.BaseProperty;
39   
40    /**
41    * Extract the metadata to be indexed from object properties.
42    *
43    * @version $Id: ae91d6bb99970a6f70fe86261561c15926999ae2 $
44    * @since 4.3M2
45    */
46    @Component
47    @Named("object_property")
48    @Singleton
 
49    public class ObjectPropertySolrMetadataExtractor extends AbstractSolrMetadataExtractor
50    {
51    /**
52    * The Solr reference resolver.
53    */
54    @Inject
55    @Named("object_property")
56    private SolrReferenceResolver resolver;
57   
 
58  2401 toggle @Override
59    public boolean setFieldsInternal(LengthSolrInputDocument solrDocument, EntityReference entityReference)
60    throws Exception
61    {
62  2401 ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference(entityReference);
63   
64  2401 BaseObjectReference objectReference = new BaseObjectReference(objectPropertyReference.getParent());
65  2401 DocumentReference classReference = objectReference.getXClassReference();
66  2401 DocumentReference documentReference = new DocumentReference(objectReference.getParent());
67   
68  2401 XWikiDocument document = getDocument(documentReference);
69  2401 BaseProperty<ObjectPropertyReference> objectProperty = document.getXObjectProperty(objectPropertyReference);
70  2401 if (objectProperty == null) {
71  1 return false;
72    }
73   
74    // Object
75  2400 solrDocument.setField(FieldUtils.CLASS, localSerializer.serialize(classReference));
76  2400 solrDocument.setField(FieldUtils.NUMBER, objectReference.getObjectNumber());
77   
78    // Property
79  2400 solrDocument.setField(FieldUtils.PROPERTY_NAME, objectPropertyReference.getName());
80   
81  2400 setLocaleAndContentFields(documentReference, solrDocument, objectProperty);
82   
83  2400 return true;
84    }
85   
86    /**
87    * Set the locale to all the translations that the owning document has. This ensures that this entity is found for
88    * all the translations of a document, not just the original document.
89    * <p>
90    * Also, index the content with each locale so that the right analyzer is used.
91    *
92    * @param documentReference the original document's reference.
93    * @param solrDocument the Solr document where to add the fields.
94    * @param objectProperty the object property.
95    * @throws Exception if problems occur.
96    */
 
97  2400 toggle protected void setLocaleAndContentFields(DocumentReference documentReference, SolrInputDocument solrDocument,
98    BaseProperty<ObjectPropertyReference> objectProperty) throws Exception
99    {
100    // Do the work for each locale.
101  2400 for (Locale documentLocale : getLocales(documentReference, null)) {
102  4797 solrDocument.addField(FieldUtils.LOCALES, documentLocale);
103   
104  4797 solrDocument.setField(FieldUtils.getFieldName(FieldUtils.PROPERTY_VALUE, documentLocale),
105    objectProperty.getValue());
106    }
107   
108    // We can`t rely on the schema's copyField here because we would trigger it for each locale. Doing the copy to
109    // the text_general field manually.
110  2400 solrDocument.setField(FieldUtils.getFieldName(FieldUtils.PROPERTY_VALUE, null), objectProperty.getValue());
111    }
112    }