List of usage examples for org.apache.solr.schema IndexSchema hasExplicitField
public boolean hasExplicitField(String fieldName)
From source file:io.yucca.solr.processor.FieldBoost.java
License:Apache License
/** * Set Field value//from w w w .j a va 2s .c o m * * @param values * String[] values to set * @param document * SolrInputDocument to set field in * @param schema * IndexSchema * @param overwrite * boolean if true existing values are overwritten */ public void set(String[] values, SolrInputDocument document, IndexSchema schema, boolean overwrite) { boolean multivalued = false; if (schema != null && schema.hasExplicitField(field)) { multivalued = schema.getField(field).multiValued(); } if (overwrite || document.containsKey(field) == false) { document.setField(field, values, boost); } else if (multivalued && overwrite == false) { document.addField(field, values, boost); } }
From source file:org.opencms.search.solr.CmsSolrDocument.java
License:Open Source License
/** * @see org.opencms.search.I_CmsSearchDocument#addSearchField(org.opencms.search.fields.CmsSearchField, java.lang.String) *///from w w w.j a v a2 s . com public void addSearchField(CmsSearchField sfield, String value) { CmsSolrField field = (CmsSolrField) sfield; List<String> fieldsToAdd = new ArrayList<String>(Collections.singletonList(field.getName())); if ((field.getCopyFields() != null) && !field.getCopyFields().isEmpty()) { fieldsToAdd.addAll(field.getCopyFields()); } IndexSchema schema = OpenCms.getSearchManager().getSolrServerConfiguration().getSolrSchema(); for (String fieldName : fieldsToAdd) { try { List<String> splitedValues = new ArrayList<String>(); boolean multi = false; try { SchemaField f = schema.getField(fieldName); if ((f != null) && (!field.getName().startsWith(CmsSearchField.FIELD_CONTENT))) { multi = f.multiValued(); } } catch (@SuppressWarnings("unused") SolrException e) { LOG.warn(Messages.get().getBundle().key(Messages.LOG_SOLR_FIELD_NOT_FOUND_1, field.toString())); } if (multi) { splitedValues = CmsStringUtil.splitAsList(value.toString(), "\n"); } else { splitedValues.add(value); } for (String val : splitedValues) { if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(val)) { try { FieldType type = schema.getFieldType(fieldName); if (type instanceof TrieDateField) { val = DF.format(new Date(new Long(val).longValue())); } } catch (SolrException e) { LOG.debug(e.getMessage(), e); throw new RuntimeException(e); } if (fieldName.endsWith(CmsSearchField.FIELD_EXCERPT)) { // TODO: make the length and the area configurable val = CmsStringUtil.trimToSize(val, 1000, 50, ""); } if (schema.hasExplicitField(fieldName) || (schema.getDynamicPattern(fieldName) != null)) { m_doc.addField(fieldName, val); } else { m_doc.addField(fieldName, val, field.getBoost()); } } } } catch (SolrException e) { LOG.error(e.getMessage(), e); } catch (@SuppressWarnings("unused") RuntimeException e) { // noop } } }
From source file:org.opencms.search.solr.CmsSolrField.java
License:Open Source License
/** * Public constructor.<p>//from w ww . ja v a 2 s .c o m * * @param luceneField */ public CmsSolrField(CmsLuceneField luceneField) { super(); String name = luceneField.getName(); IndexSchema schema = OpenCms.getSearchManager().getSolrServerConfiguration().getSolrSchema(); if (schema.hasExplicitField(name)) { // take the lucene field name for Solr } else if ((luceneField.getType() != null) && schema.isDynamicField(luceneField.getName() + "_" + luceneField.getType())) { // try to use the specified type attribute as dynamic field suffix name = luceneField.getName() + "_" + luceneField.getType(); } else { // fallback create a general_text field name = luceneField.getName() + "_txt"; } setName(name); setBoost(luceneField.getBoost()); setDefaultValue(luceneField.getDefaultValue()); for (I_CmsSearchFieldMapping mapping : luceneField.getMappings()) { addMapping(mapping); } }