List of usage examples for org.apache.solr.handler.extraction ExtractingParams LITERALS_PREFIX
String LITERALS_PREFIX
To view the source code for org.apache.solr.handler.extraction ExtractingParams LITERALS_PREFIX.
Click Source Link
literal.myField=Foo
From source file:org.craftercms.search.service.impl.SolrDocumentBuilder.java
License:Open Source License
/** * Build the Solr document for partial update of the search engine's index data of a structured document. * * @param request Content Stream update request for document update * @param additionalFields Fields to add to solr document * @return the Solr document//from ww w.j av a 2 s .co m * */ public ContentStreamUpdateRequest buildPartialUpdateDocument(ContentStreamUpdateRequest request, Map<String, String> additionalFields) { for (Map.Entry<String, String> additionalField : additionalFields.entrySet()) { String fieldName = additionalField.getKey(); String fieldValue = additionalField.getValue(); // If fieldName ends with HTML prefix, strip all HTML markup from the field value. if (fieldName.endsWith(htmlFieldSuffix)) { if (logger.isDebugEnabled()) { logger.debug("Stripping HTML from field '" + fieldName + "'"); } fieldValue = stripHtml(fieldName, fieldValue); } // If fieldName ends with datetime prefix, convert the field value to an ISO datetime string. if (fieldName.endsWith(dateTimeFieldSuffix)) { if (logger.isDebugEnabled()) { logger.debug("Converting '" + fieldValue + "' to ISO datetime"); } fieldValue = convertToISODateTimeString(fieldValue); } if (logger.isDebugEnabled()) { logger.debug("Adding field '" + fieldName + "' to the Solr doc"); } if (fieldName.endsWith(htmlFieldSuffix) || fieldName.endsWith(dateTimeFieldSuffix)) { request.setParam(ExtractingParams.LITERALS_PREFIX + fieldName, fieldValue); } else { String[] fieldValues = fieldValue.split(multivalueSeparator); if (fieldValues.length > 1) { ModifiableSolrParams params = request.getParams(); params.add(ExtractingParams.LITERALS_PREFIX + fieldName, fieldValues); } else { request.setParam(ExtractingParams.LITERALS_PREFIX + fieldName, fieldValue); } } } return request; }
From source file:org.craftercms.search.service.impl.SolrSearchService.java
License:Open Source License
@Override public void updateContent(String indexId, String site, String id, File file, Map<String, List<String>> additionalFields) throws SearchException { if (StringUtils.isEmpty(indexId)) { indexId = defaultIndexId;//from w ww . j av a2s . c o m } String finalId = site + ":" + id; String fileName = FilenameUtils.getName(id); String contentType = mimeTypesMap.getContentType(fileName); ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(SOLR_CONTENT_STREAM_UPDATE_URL); NamedList<Object> response; try { ModifiableSolrParams params = solrDocumentBuilder.buildParams(site, id, ExtractingParams.LITERALS_PREFIX, null, additionalFields); params.set(ExtractingParams.LITERALS_PREFIX + fileNameFieldName, fileName); request.setParams(params); request.addFile(file, contentType); request.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); response = solrClient.request(request, indexId); } catch (SolrServerException e) { logger.warn("{}Unable to update file through content stream request: {}. Attempting to perform just " + "the metadata update", getIndexPrefix(indexId), e.getMessage()); try { SolrInputDocument inputDocument = solrDocumentBuilder.build(site, id, additionalFields); inputDocument.setField(fileNameFieldName, fileName); response = solrClient.add(indexId, inputDocument).getResponse(); } catch (IOException e1) { throw new SearchException(indexId, "I/O error while executing update file for " + finalId, e1); } catch (SolrServerException e1) { throw new SearchException(indexId, e1.getMessage(), e1); } } catch (IOException e) { throw new SearchException(indexId, "I/O error while executing update file for " + finalId, e); } if (logger.isDebugEnabled()) { logger.debug(getSuccessfulMessage(indexId, finalId, "Update file", response)); } }
From source file:org.dspace.discovery.SolrServiceImpl.java
License:BSD License
/** * Write the document to the index under the appropriate handle. * * @param doc the solr document to be written to the server * @param streams/*from ww w. j a v a2 s .c om*/ * @throws IOException IO exception */ protected void writeDocument(SolrInputDocument doc, List<BitstreamContentStream> streams) throws IOException { try { if (getSolr() != null) { if (CollectionUtils.isNotEmpty(streams)) { ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); for (BitstreamContentStream bce : streams) { req.addContentStream(bce); } ModifiableSolrParams params = new ModifiableSolrParams(); //req.setParam(ExtractingParams.EXTRACT_ONLY, "true"); for (String name : doc.getFieldNames()) { for (Object val : doc.getFieldValues(name)) { params.add(ExtractingParams.LITERALS_PREFIX + name, val.toString()); } } req.setParams(params); req.setParam(ExtractingParams.UNKNOWN_FIELD_PREFIX, "attr_"); req.setParam(ExtractingParams.MAP_PREFIX + "content", "fulltext"); req.setParam(ExtractingParams.EXTRACT_FORMAT, "text"); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); req.process(getSolr()); } else { getSolr().add(doc); } } } catch (SolrServerException e) { log.error(e.getMessage(), e); } }