| 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.io.InputStream; |
| 23 |
|
import java.util.Arrays; |
| 24 |
|
import java.util.Collection; |
| 25 |
|
import java.util.HashSet; |
| 26 |
|
import java.util.List; |
| 27 |
|
import java.util.Locale; |
| 28 |
|
import java.util.Map; |
| 29 |
|
import java.util.Set; |
| 30 |
|
|
| 31 |
|
import javax.inject.Inject; |
| 32 |
|
import javax.inject.Named; |
| 33 |
|
import javax.inject.Provider; |
| 34 |
|
|
| 35 |
|
import org.apache.solr.common.SolrInputDocument; |
| 36 |
|
import org.apache.tika.Tika; |
| 37 |
|
import org.apache.tika.metadata.Metadata; |
| 38 |
|
import org.apache.tika.metadata.TikaMetadataKeys; |
| 39 |
|
import org.slf4j.Logger; |
| 40 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 41 |
|
import org.xwiki.component.manager.ComponentManager; |
| 42 |
|
import org.xwiki.context.Execution; |
| 43 |
|
import org.xwiki.model.EntityType; |
| 44 |
|
import org.xwiki.model.reference.DocumentReference; |
| 45 |
|
import org.xwiki.model.reference.EntityReference; |
| 46 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 47 |
|
import org.xwiki.search.solr.internal.api.FieldUtils; |
| 48 |
|
import org.xwiki.search.solr.internal.api.SolrIndexerException; |
| 49 |
|
import org.xwiki.search.solr.internal.reference.SolrReferenceResolver; |
| 50 |
|
|
| 51 |
|
import com.xpn.xwiki.XWikiContext; |
| 52 |
|
import com.xpn.xwiki.XWikiException; |
| 53 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
| 54 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 55 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 56 |
|
import com.xpn.xwiki.objects.BaseProperty; |
| 57 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 58 |
|
import com.xpn.xwiki.objects.classes.BooleanClass; |
| 59 |
|
import com.xpn.xwiki.objects.classes.ListItem; |
| 60 |
|
import com.xpn.xwiki.objects.classes.PasswordClass; |
| 61 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
| 62 |
|
import com.xpn.xwiki.objects.classes.StaticListClass; |
| 63 |
|
import com.xpn.xwiki.objects.classes.TextAreaClass; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@version |
| 69 |
|
@since |
| 70 |
|
|
| |
|
| 94.7% |
Uncovered Elements: 10 (189) |
Complexity: 58 |
Complexity Density: 0.47 |
|
| 71 |
|
public abstract class AbstractSolrMetadataExtractor implements SolrMetadataExtractor |
| 72 |
|
{ |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
private static final String OBJCONTENT_FORMAT = "%s : %s"; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
protected static final int SHORT_TEXT_LIMIT = 255; |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
@Inject |
| 89 |
|
protected Logger logger; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@Inject |
| 95 |
|
protected Execution execution; |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
@Inject |
| 102 |
|
@Named("local") |
| 103 |
|
protected EntityReferenceSerializer<String> localSerializer; |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
@link |
| 107 |
|
|
| 108 |
|
@Inject |
| 109 |
|
protected Provider<XWikiContext> xcontextProvider; |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
@Inject |
| 115 |
|
protected ComponentManager componentManager; |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 117 |
4049 |
@Override... |
| 118 |
|
public LengthSolrInputDocument getSolrDocument(EntityReference entityReference) |
| 119 |
|
throws SolrIndexerException, IllegalArgumentException |
| 120 |
|
{ |
| 121 |
4049 |
try { |
| 122 |
4049 |
LengthSolrInputDocument solrDocument = new LengthSolrInputDocument(); |
| 123 |
|
|
| 124 |
4049 |
solrDocument.setField(FieldUtils.ID, getResolver(entityReference).getId(entityReference)); |
| 125 |
|
|
| 126 |
4048 |
if (!setDocumentFields(new DocumentReference(entityReference.extractReference(EntityType.DOCUMENT)), |
| 127 |
|
solrDocument)) { |
| 128 |
1 |
return null; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
4047 |
solrDocument.setField(FieldUtils.TYPE, entityReference.getType().name()); |
| 132 |
|
|
| 133 |
4047 |
if (!setFieldsInternal(solrDocument, entityReference)) { |
| 134 |
4 |
return null; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
4043 |
return solrDocument; |
| 138 |
|
} catch (Exception e) { |
| 139 |
1 |
String message = String.format("Failed to get input Solr document for entity '%s'", entityReference); |
| 140 |
1 |
throw new SolrIndexerException(message, e); |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
@param@link |
| 146 |
|
@param |
| 147 |
|
@return |
| 148 |
|
@throws |
| 149 |
|
|
| 150 |
|
protected abstract boolean setFieldsInternal(LengthSolrInputDocument solrDocument, EntityReference entityReference) |
| 151 |
|
throws Exception; |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
@param |
| 155 |
|
@return |
| 156 |
|
@throws |
| 157 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 158 |
4049 |
protected SolrReferenceResolver getResolver(EntityReference entityReference) throws SolrIndexerException... |
| 159 |
|
{ |
| 160 |
4049 |
try { |
| 161 |
4049 |
return this.componentManager.getInstance(SolrReferenceResolver.class, |
| 162 |
|
entityReference.getType().getLowerCase()); |
| 163 |
|
} catch (ComponentLookupException e) { |
| 164 |
0 |
throw new SolrIndexerException( |
| 165 |
|
"Faile to find solr reference resolver for type reference [" + entityReference + "]"); |
| 166 |
|
} |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
@param |
| 173 |
|
@return@link |
| 174 |
|
@throws |
| 175 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 176 |
9648 |
protected XWikiDocument getDocument(DocumentReference documentReference) throws XWikiException... |
| 177 |
|
{ |
| 178 |
9648 |
XWikiContext xcontext = this.xcontextProvider.get(); |
| 179 |
|
|
| 180 |
9648 |
XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); |
| 181 |
|
|
| 182 |
9647 |
return document; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
@param |
| 189 |
|
@return |
| 190 |
|
@throws |
| 191 |
|
|
| |
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 192 |
876 |
protected XWikiDocument getTranslatedDocument(DocumentReference documentReference) throws SolrIndexerException... |
| 193 |
|
{ |
| 194 |
876 |
try { |
| 195 |
876 |
XWikiDocument document = getDocument(documentReference); |
| 196 |
876 |
Locale locale = documentReference.getLocale(); |
| 197 |
|
|
| 198 |
876 |
if (locale == null || locale.equals(Locale.ROOT)) { |
| 199 |
759 |
return document; |
| 200 |
|
} |
| 201 |
|
|
| 202 |
117 |
XWikiDocument translatedDocument = document.getTranslatedDocument(locale, this.xcontextProvider.get()); |
| 203 |
|
|
| 204 |
|
|
| 205 |
117 |
if (translatedDocument.getRealLocale().equals(locale)) { |
| 206 |
117 |
return translatedDocument; |
| 207 |
|
} |
| 208 |
|
} catch (Exception e) { |
| 209 |
0 |
throw new SolrIndexerException( |
| 210 |
|
String.format("Failed to get translated document for '%s'", documentReference), e); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
0 |
return null; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
@param |
| 222 |
|
@param |
| 223 |
|
@return |
| 224 |
|
@throws |
| 225 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 226 |
4725 |
protected boolean setDocumentFields(DocumentReference documentReference, SolrInputDocument solrDocument)... |
| 227 |
|
throws Exception |
| 228 |
|
{ |
| 229 |
4725 |
XWikiDocument document = getDocument(documentReference); |
| 230 |
4724 |
if (document.isNew()) { |
| 231 |
1 |
return false; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
4723 |
solrDocument.setField(FieldUtils.HIDDEN, document.isHidden()); |
| 235 |
|
|
| 236 |
4723 |
solrDocument.setField(FieldUtils.WIKI, documentReference.getWikiReference().getName()); |
| 237 |
4723 |
solrDocument.setField(FieldUtils.NAME, documentReference.getName()); |
| 238 |
|
|
| 239 |
|
|
| 240 |
4723 |
setHierarchyFields(solrDocument, documentReference.getParent()); |
| 241 |
|
|
| 242 |
4723 |
Locale locale = getLocale(documentReference); |
| 243 |
4723 |
solrDocument.setField(FieldUtils.LOCALE, locale.toString()); |
| 244 |
4723 |
solrDocument.setField(FieldUtils.LANGUAGE, locale.getLanguage()); |
| 245 |
|
|
| 246 |
4723 |
return true; |
| 247 |
|
} |
| 248 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 249 |
3076 |
protected Set<Locale> getLocales(DocumentReference documentReference, Locale entityLocale)... |
| 250 |
|
throws XWikiException, SolrIndexerException |
| 251 |
|
{ |
| 252 |
3076 |
XWikiContext xcontext = this.xcontextProvider.get(); |
| 253 |
|
|
| 254 |
3076 |
return getLocales(xcontext.getWiki().getDocument(documentReference, xcontext), entityLocale); |
| 255 |
|
} |
| 256 |
|
|
| |
|
| 96.2% |
Uncovered Elements: 1 (26) |
Complexity: 7 |
Complexity Density: 0.44 |
|
| 257 |
4043 |
protected Set<Locale> getLocales(XWikiDocument xdocument, Locale entityLocale)... |
| 258 |
|
throws XWikiException, SolrIndexerException |
| 259 |
|
{ |
| 260 |
4043 |
Set<Locale> locales = new HashSet<Locale>(); |
| 261 |
|
|
| 262 |
4043 |
String entityLocaleString = entityLocale != null ? entityLocale.toString() : null; |
| 263 |
|
|
| 264 |
|
|
| 265 |
4043 |
if (entityLocale != null) { |
| 266 |
876 |
locales.add(entityLocale); |
| 267 |
|
} |
| 268 |
|
|
| 269 |
4043 |
XWikiContext xcontext = this.xcontextProvider.get(); |
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
4043 |
List<Locale> documentLocales = xdocument.getTranslationLocales(this.xcontextProvider.get()); |
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| 277 |
4043 |
if (entityLocale == null) { |
| 278 |
3167 |
for (Locale locale : documentLocales) { |
| 279 |
116 |
locales.add(locale); |
| 280 |
|
} |
| 281 |
|
} |
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| 285 |
4043 |
List<Locale> availableLocales = xcontext.getWiki().getAvailableLocales(xcontext); |
| 286 |
|
|
| 287 |
4043 |
for (Locale locale : availableLocales) { |
| 288 |
|
|
| 289 |
4031 |
if (!documentLocales.contains(locale)) { |
| 290 |
4031 |
if (entityLocale == null || locale.toString().startsWith(entityLocaleString)) { |
| 291 |
3914 |
locales.add(locale); |
| 292 |
|
} |
| 293 |
|
} |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
4043 |
locales.add(getLocale(xdocument.getDocumentReference())); |
| 298 |
|
|
| 299 |
4043 |
return locales; |
| 300 |
|
} |
| 301 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 302 |
876 |
protected void addLocales(XWikiDocument xdocument, Locale entityLocale, SolrInputDocument solrDocument)... |
| 303 |
|
throws SolrIndexerException, XWikiException |
| 304 |
|
{ |
| 305 |
876 |
Set<Locale> locales = getLocales(xdocument, entityLocale); |
| 306 |
876 |
for (Locale childLocale : locales) { |
| 307 |
1752 |
solrDocument.addField(FieldUtils.LOCALES, childLocale.toString()); |
| 308 |
|
} |
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
|
| 312 |
|
@param |
| 313 |
|
@return |
| 314 |
|
@throws |
| 315 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 316 |
9642 |
protected Locale getLocale(DocumentReference documentReference) throws SolrIndexerException... |
| 317 |
|
{ |
| 318 |
9642 |
Locale locale = null; |
| 319 |
|
|
| 320 |
9642 |
try { |
| 321 |
9642 |
if (documentReference.getLocale() != null && !documentReference.getLocale().equals(Locale.ROOT)) { |
| 322 |
234 |
locale = documentReference.getLocale(); |
| 323 |
|
} else { |
| 324 |
9408 |
XWikiContext xcontext = this.xcontextProvider.get(); |
| 325 |
9408 |
locale = xcontext.getWiki().getDocument(documentReference, xcontext).getRealLocale(); |
| 326 |
|
} |
| 327 |
|
} catch (Exception e) { |
| 328 |
0 |
throw new SolrIndexerException( |
| 329 |
|
String.format("Exception while fetching the locale of the document '%s'", documentReference), e); |
| 330 |
|
} |
| 331 |
|
|
| 332 |
9642 |
return locale; |
| 333 |
|
} |
| 334 |
|
|
| 335 |
|
|
| 336 |
|
|
| 337 |
|
|
| 338 |
|
@param |
| 339 |
|
@param |
| 340 |
|
@param |
| 341 |
|
|
| 342 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 343 |
2928 |
protected void setObjectContent(SolrInputDocument solrDocument, BaseObject object, Locale locale)... |
| 344 |
|
{ |
| 345 |
2928 |
if (object == null) { |
| 346 |
|
|
| 347 |
23 |
return; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
2905 |
BaseClass xClass = object.getXClass(this.xcontextProvider.get()); |
| 351 |
2905 |
for (Object field : object.getFieldList()) { |
| 352 |
11425 |
@SuppressWarnings("unchecked") |
| 353 |
|
BaseProperty<EntityReference> property = (BaseProperty<EntityReference>) field; |
| 354 |
|
|
| 355 |
11425 |
if (property.getValue() != null) { |
| 356 |
11401 |
PropertyClass propertyClass = (PropertyClass) xClass.get(property.getName()); |
| 357 |
11401 |
setPropertyValue(solrDocument, property, propertyClass, locale); |
| 358 |
|
} |
| 359 |
|
} |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
|
| 363 |
|
|
| 364 |
|
|
| 365 |
|
@param |
| 366 |
|
@param |
| 367 |
|
@param |
| 368 |
|
@param |
| 369 |
|
|
| |
|
| 96.7% |
Uncovered Elements: 1 (30) |
Complexity: 14 |
Complexity Density: 0.88 |
|
| 370 |
11401 |
private void setPropertyValue(SolrInputDocument solrDocument, BaseProperty<EntityReference> property,... |
| 371 |
|
PropertyClass propertyClass, Locale locale) |
| 372 |
|
{ |
| 373 |
11401 |
Object propertyValue = property.getValue(); |
| 374 |
11401 |
if (propertyClass instanceof StaticListClass) { |
| 375 |
2376 |
setStaticListPropertyValue(solrDocument, property, (StaticListClass) propertyClass, locale); |
| 376 |
9025 |
} else if (propertyClass instanceof TextAreaClass |
| 377 |
|
|| (propertyClass != null && "String".equals(propertyClass.getClassType())) |
| 378 |
|
|| (propertyValue instanceof CharSequence && String.valueOf(propertyValue).length() > SHORT_TEXT_LIMIT)) { |
| 379 |
|
|
| 380 |
|
|
| 381 |
|
|
| 382 |
|
|
| 383 |
|
|
| 384 |
|
|
| 385 |
|
|
| 386 |
|
|
| 387 |
|
|
| 388 |
|
|
| 389 |
|
|
| 390 |
6287 |
setPropertyValue(solrDocument, property, new TypedValue(String.valueOf(propertyValue), TypedValue.TEXT), |
| 391 |
|
locale); |
| 392 |
|
|
| 393 |
6287 |
if (!(propertyClass instanceof TextAreaClass) |
| 394 |
|
&& String.valueOf(propertyValue).length() <= SHORT_TEXT_LIMIT) { |
| 395 |
|
|
| 396 |
|
|
| 397 |
4318 |
setPropertyValue(solrDocument, property, new TypedValue(propertyValue), locale); |
| 398 |
|
} |
| 399 |
2738 |
} else if (propertyValue instanceof Collection) { |
| 400 |
|
|
| 401 |
|
|
| 402 |
|
|
| 403 |
73 |
for (Object value : (Collection<?>) propertyValue) { |
| 404 |
18 |
if (value != null) { |
| 405 |
|
|
| 406 |
18 |
setPropertyValue(solrDocument, property, new TypedValue(value), locale); |
| 407 |
|
} |
| 408 |
|
} |
| 409 |
2665 |
} else if (propertyValue instanceof Integer && propertyClass instanceof BooleanClass) { |
| 410 |
|
|
| 411 |
1534 |
Boolean booleanValue = ((Integer) propertyValue) != 0; |
| 412 |
1534 |
setPropertyValue(solrDocument, property, new TypedValue(booleanValue), locale); |
| 413 |
1131 |
} else if (!(propertyClass instanceof PasswordClass)) { |
| 414 |
|
|
| 415 |
1124 |
setPropertyValue(solrDocument, property, new TypedValue(propertyValue), locale); |
| 416 |
|
} |
| 417 |
|
} |
| 418 |
|
|
| 419 |
|
|
| 420 |
|
|
| 421 |
|
|
| 422 |
|
|
| 423 |
|
@param |
| 424 |
|
@param |
| 425 |
|
@param |
| 426 |
|
@param |
| 427 |
|
@see |
| 428 |
|
|
| |
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
| 429 |
2376 |
private void setStaticListPropertyValue(SolrInputDocument solrDocument, BaseProperty<EntityReference> property,... |
| 430 |
|
StaticListClass propertyClass, Locale locale) |
| 431 |
|
{ |
| 432 |
|
|
| 433 |
2376 |
Map<String, ListItem> knownValues = propertyClass.getMap(this.xcontextProvider.get()); |
| 434 |
2376 |
Object propertyValue = property.getValue(); |
| 435 |
|
|
| 436 |
2376 |
List<?> rawValues = propertyValue instanceof List ? (List<?>) propertyValue : Arrays.asList(propertyValue); |
| 437 |
2376 |
for (Object rawValue : rawValues) { |
| 438 |
|
|
| 439 |
1736 |
if (rawValue != null) { |
| 440 |
|
|
| 441 |
|
|
| 442 |
1736 |
setPropertyValue(solrDocument, property, new TypedValue(rawValue), locale); |
| 443 |
1736 |
ListItem valueInfo = knownValues.get(rawValue); |
| 444 |
1736 |
if (valueInfo != null && valueInfo.getValue() != null && !valueInfo.getValue().equals(rawValue)) { |
| 445 |
|
|
| 446 |
|
|
| 447 |
|
|
| 448 |
45 |
setPropertyValue(solrDocument, property, new TypedValue(valueInfo.getValue(), TypedValue.TEXT), |
| 449 |
|
locale); |
| 450 |
|
} |
| 451 |
|
} |
| 452 |
|
} |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
|
| 456 |
|
|
| 457 |
|
|
| 458 |
|
@param |
| 459 |
|
@param |
| 460 |
|
|
| 461 |
|
@param |
| 462 |
|
@param |
| 463 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 464 |
15062 |
protected void setPropertyValue(SolrInputDocument solrDocument, BaseProperty<EntityReference> property,... |
| 465 |
|
TypedValue typedValue, Locale locale) |
| 466 |
|
{ |
| 467 |
|
|
| 468 |
15062 |
String fieldName = FieldUtils.getFieldName(FieldUtils.OBJECT_CONTENT, locale); |
| 469 |
15062 |
String fieldValue = String.format(OBJCONTENT_FORMAT, property.getName(), typedValue.getValue()); |
| 470 |
|
|
| 471 |
|
|
| 472 |
|
|
| 473 |
15062 |
addFieldValueOnce(solrDocument, fieldName, fieldValue); |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
|
| 477 |
|
|
| 478 |
|
|
| 479 |
|
@param |
| 480 |
|
@param |
| 481 |
|
@param |
| 482 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 483 |
19419 |
protected void addFieldValueOnce(SolrInputDocument solrDocument, String fieldName, Object fieldValue)... |
| 484 |
|
{ |
| 485 |
19419 |
Collection<Object> fieldValues = solrDocument.getFieldValues(fieldName); |
| 486 |
19419 |
if (fieldValues == null || !fieldValues.contains(fieldValue)) { |
| 487 |
12999 |
solrDocument.addField(fieldName, fieldValue); |
| 488 |
|
} |
| 489 |
|
} |
| 490 |
|
|
| 491 |
|
|
| 492 |
|
|
| 493 |
|
|
| 494 |
|
@param |
| 495 |
|
@return |
| 496 |
|
@throws |
| 497 |
|
|
| |
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 498 |
286 |
protected String getContentAsText(XWikiAttachment attachment)... |
| 499 |
|
{ |
| 500 |
286 |
try { |
| 501 |
286 |
Tika tika = new Tika(); |
| 502 |
|
|
| 503 |
286 |
Metadata metadata = new Metadata(); |
| 504 |
286 |
metadata.set(TikaMetadataKeys.RESOURCE_NAME_KEY, attachment.getFilename()); |
| 505 |
|
|
| 506 |
286 |
InputStream in = attachment.getContentInputStream(this.xcontextProvider.get()); |
| 507 |
|
|
| 508 |
286 |
try { |
| 509 |
286 |
return tika.parseToString(in, metadata); |
| 510 |
|
} finally { |
| 511 |
286 |
in.close(); |
| 512 |
|
} |
| 513 |
|
} catch (Exception e) { |
| 514 |
0 |
this.logger.error("Failed to retrieve the content of attachment [{}]", attachment.getReference(), e); |
| 515 |
0 |
return null; |
| 516 |
|
} |
| 517 |
|
} |
| 518 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 519 |
4723 |
private void setHierarchyFields(SolrInputDocument solrDocument, EntityReference path)... |
| 520 |
|
{ |
| 521 |
4723 |
solrDocument.setField(FieldUtils.SPACE_EXACT, this.localSerializer.serialize(path)); |
| 522 |
4723 |
List<EntityReference> ancestors = path.getReversedReferenceChain(); |
| 523 |
|
|
| 524 |
10002 |
for (int i = 1; i < ancestors.size(); i++) { |
| 525 |
5279 |
solrDocument.addField(FieldUtils.SPACES, ancestors.get(i).getName()); |
| 526 |
5279 |
String localAncestorReference = this.localSerializer.serialize(ancestors.get(i)); |
| 527 |
5279 |
solrDocument.addField(FieldUtils.SPACE_PREFIX, localAncestorReference); |
| 528 |
|
|
| 529 |
|
|
| 530 |
|
|
| 531 |
5279 |
solrDocument.addField(FieldUtils.SPACE_FACET, (i - 1) + "/" + localAncestorReference + "."); |
| 532 |
|
} |
| 533 |
|
} |
| 534 |
|
} |