1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named("object") |
47 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
|
48 |
|
public class ObjectSolrMetadataExtractor extends AbstractSolrMetadataExtractor |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@Inject |
54 |
|
@Named("object") |
55 |
|
private SolrReferenceResolver resolver; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
57 |
678 |
@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 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@param |
90 |
|
@param |
91 |
|
@param |
92 |
|
@throws |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
94 |
676 |
protected void setLocaleAndContentFields(DocumentReference documentReference, SolrInputDocument solrDocument,... |
95 |
|
BaseObject object) throws Exception |
96 |
|
{ |
97 |
|
|
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 |
|
|
105 |
|
|
106 |
676 |
setObjectContent(solrDocument, object, null); |
107 |
|
} |
108 |
|
} |