protected Field.Store getFieldStore(SchemaField field, String internalVal) { return field.stored() ? Field.Store.YES : Field.Store.NO; } protected Field.Index getFieldIndex(SchemaField field,
/** Add the xpathFields to the indexConfig using information about the field drawn from the schema. */ private void addXPathFields() { for (Entry<String,String> f : xpathFieldConfig) { SchemaField field = schema.getField(f.getKey()); FieldType fieldType = field.getType(); if (fieldType == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "Field " + f.getKey() + " declared in lux config, but not defined in schema"); } XPathField xpathField = new XPathField(f.getKey(), f.getValue(), fieldType.getAnalyzer(), field.stored() ? Store.YES : Store.NO, field); indexConfig.addField(xpathField); } }
/** * Returns a collection of the names of all stored fields which can be * highlighted the index reader knows about. */ public Collection<String> getStoredHighlightFieldNames() { if (storedHighlightFieldNames == null) { storedHighlightFieldNames = new LinkedList<String>(); for (String fieldName : fieldNames) { try { SchemaField field = schema.getField(fieldName); if (field.stored() && ((field.getType() instanceof org.apache.solr.schema.TextField) || (field.getType() instanceof org.apache.solr.schema.StrField))) { storedHighlightFieldNames.add(fieldName); } } catch (RuntimeException e) { // getField() throws a SolrException, but it arrives as a RuntimeException log.warn("Field \"" + fieldName + "\" found in index, but not defined in schema."); } } } return storedHighlightFieldNames; } //
public Field createField(SchemaField field, Object val, float boost) { if (val == null) return null; if (!field.stored()) { log.trace("Ignoring unstored binary field: " + field); return null; } byte[] buf = null; int offset = 0, len = 0; if (val instanceof byte[]) { buf = (byte[]) val; len = buf.length; } else if (val instanceof ByteBuffer && ((ByteBuffer)val).hasArray()) { ByteBuffer byteBuf = (ByteBuffer) val; buf = byteBuf.array(); offset = byteBuf.position(); len = byteBuf.limit() - byteBuf.position(); } else { String strVal = val.toString(); //the string has to be a base64 encoded string buf = Base64.base64ToByteArray(strVal); offset = 0; len = buf.length; } Field f = new Field(field.getName(), buf, offset, len, getFieldStore(field, null)); f.setBoost(boost); return f; } }
@Override public IndexableField createField(SchemaField field, Object val /*, float boost*/) { if (val == null) return null; if (!field.stored()) { return null; } byte[] buf = null; int offset = 0, len = 0; if (val instanceof byte[]) { buf = (byte[]) val; len = buf.length; } else if (val instanceof ByteBuffer && ((ByteBuffer)val).hasArray()) { ByteBuffer byteBuf = (ByteBuffer) val; buf = byteBuf.array(); offset = byteBuf.position(); len = byteBuf.limit() - byteBuf.position(); } else { String strVal = val.toString(); //the string has to be a base64 encoded string buf = Base64.base64ToByteArray(strVal); offset = 0; len = buf.length; } Field f = new org.apache.lucene.document.BinaryDocValuesField(field.getName(), new BytesRef(buf, offset, len)); // Field f = new org.apache.lucene.document.StoredField(field.getName(), buf, offset, len); //f.setBoost(boost); return f; } }
private void append(SolrDocumentList results, ScoreDoc[] more, Set<Integer> alreadyFound, Map<String,SchemaField> fields, Map<String,Object> extraFields, float scoreCutoff, IndexReader reader, boolean includeScore) throws IOException { for (ScoreDoc hit : more) { if (alreadyFound.contains(hit.doc)) { continue; } Document doc = reader.document(hit.doc); SolrDocument sdoc = new SolrDocument(); for (String fieldname : fields.keySet()) { SchemaField sf = fields.get(fieldname); if (sf.stored()) { sdoc.addField(fieldname, doc.get(fieldname)); } } for (String extraField : extraFields.keySet()) { sdoc.addField(extraField, extraFields.get(extraField)); } if (includeScore) { sdoc.addField("score", hit.score); } results.add(sdoc); alreadyFound.add(hit.doc); } } public class PairComparable implements Comparator<Pair> {
private void append(SolrDocumentList results, ScoreDoc[] more, Set<Integer> alreadyFound, Map<String,SchemaField> fields, Map<String,Object> extraFields, float scoreCutoff, IndexReader reader, boolean includeScore) throws IOException { for (ScoreDoc hit : more) { if (alreadyFound.contains(hit.doc)) { continue; } Document doc = reader.document(hit.doc); SolrDocument sdoc = new SolrDocument(); for (String fieldname : fields.keySet()) { SchemaField sf = fields.get(fieldname); if (sf.stored()) { sdoc.addField(fieldname, doc.get(fieldname)); } } for (String extraField : extraFields.keySet()) { sdoc.addField(extraField, extraFields.get(extraField)); } if (includeScore) { sdoc.addField("score", hit.score); } results.add(sdoc); alreadyFound.add(hit.doc); } } public class PairComparable implements Comparator<Pair> {
/** * @return a string representing a SchemaField's flags. */ private static String getFieldFlags( SchemaField f ) { FieldType t = (f==null) ? null : f.getType(); // see: http://www.nabble.com/schema-field-properties-tf3437753.html#a9585549 boolean lazy = false; // "lazy" is purely a property of reading fields boolean binary = false; // Currently not possible StringBuilder flags = new StringBuilder(); flags.append( (f != null && f.indexed()) ? FieldFlag.INDEXED.getAbbreviation() : '-' ); flags.append( (t != null && t.isTokenized()) ? FieldFlag.TOKENIZED.getAbbreviation() : '-' ); flags.append( (f != null && f.stored()) ? FieldFlag.STORED.getAbbreviation() : '-' ); flags.append( (f != null && f.multiValued()) ? FieldFlag.MULTI_VALUED.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermVector() ) ? FieldFlag.TERM_VECTOR_STORED.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermOffsets() ) ? FieldFlag.TERM_VECTOR_OFFSET.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermPositions() ) ? FieldFlag.TERM_VECTOR_POSITION.getAbbreviation() : '-' ); flags.append( (f != null && f.omitNorms()) ? FieldFlag.OMIT_NORMS.getAbbreviation() : '-' ); flags.append( (f != null && f.omitTf()) ? FieldFlag.OMIT_TF.getAbbreviation() : '-' ); flags.append( (lazy) ? FieldFlag.LAZY.getAbbreviation() : '-' ); flags.append( (binary) ? FieldFlag.BINARY.getAbbreviation() : '-' ); flags.append( (f != null && f.isCompressed()) ? FieldFlag.COMPRESSED.getAbbreviation() : '-' ); flags.append( (f != null && f.sortMissingFirst() ) ? FieldFlag.SORT_MISSING_FIRST.getAbbreviation() : '-' ); flags.append( (f != null && f.sortMissingLast() ) ? FieldFlag.SORT_MISSING_LAST.getAbbreviation() : '-' ); return flags.toString(); }
.toString(schemaField.indexed())); fieldBuilder.allAttributes.put("stored", Boolean .toString(schemaField.stored())); fieldBuilder.allAttributes.put("defaultValue", schemaField .getDefaultValue());
@Override public Field createField(SchemaField field, String externalVal, float boost) { boolean indexed = field.indexed(); boolean stored = field.stored(); if (!indexed && !stored) { if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field); return null; } int ps = precisionStep; byte[] arr=null; TokenStream ts=null; long time = super.parseMath(null, externalVal).getTime(); if (stored) arr = TrieField.toArr(time); if (indexed) ts = new NumericTokenStream(ps).setLongValue(time); Field f; if (stored) { f = new Field(field.getName(), arr, Field.Store.YES); if (indexed) f.setTokenStream(ts); } else { f = new Field(field.getName(), ts); } // term vectors aren't supported f.setOmitNorms(field.omitNorms()); f.setOmitTermFreqAndPositions(field.omitTf()); f.setBoost(boost); return f; }
if (field.stored()) { f = new Field(field.getName(), storableValue, type); } else {
if (returnOnlyStored && sf != null && !sf.stored()) { continue;
if (!field.indexed() && !field.stored()) { if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field);
@Override public Field createField(SchemaField field, String externalVal, float boost) { boolean indexed = field.indexed(); boolean stored = field.stored();