static protected void AddPropertyToDocument (Property prop, Document doc) { if (prop == null || String.IsNullOrEmpty (prop.Value)) return; // Don't actually put properties in the UnindexedNamespace // in the document. A horrible (and yet lovely!) hack. if (prop.Key.StartsWith (StringFu.UnindexedNamespace)) return; Field f; if (prop.IsSearched) { string wildcard_field = TypeToWildcardField (prop.Type); f = new Field (wildcard_field, prop.Value, Field.Store.NO, TypeToIndexInstruction (prop.Type)); // We don't want to include norms for non-text // fields, even if we do tokenize them. if (prop.Type == PropertyType.Keyword || prop.Type == PropertyType.Date) f.SetOmitNorms (true); doc.Add (f); if (prop.Type == PropertyType.Date) AddDateFields (wildcard_field, prop, doc); } string coded_value; coded_value = String.Format ("{0}{1}:{2}", prop.IsSearched ? 's' : '_', prop.IsPersistent ? 'p' : '_', prop.Value); string field_name = PropertyToFieldName (prop.Type, prop.Key); f = new Field (field_name, coded_value, prop.IsStored ? Field.Store.YES : Field.Store.NO, Field.Index.TOKENIZED); doc.Add (f); if (prop.Type == PropertyType.Date) AddDateFields (field_name, prop, doc); }
private void AddField(Document doc, FieldInfo fi, bool binary, bool compressed, bool tokenize) { //we have a binary stored field, and it may be compressed if (binary) { int toRead = fieldsStream.ReadVInt(); byte[] b = new byte[toRead]; fieldsStream.ReadBytes(b, 0, b.Length); if (compressed) doc.Add(new Field(fi.name, Uncompress(b), Field.Store.COMPRESS)); else doc.Add(new Field(fi.name, b, Field.Store.YES)); } else { Field.Store store = Field.Store.YES; Field.Index index = GetIndexType(fi, tokenize); Field.TermVector termVector = GetTermVectorType(fi); AbstractField f; if (compressed) { store = Field.Store.COMPRESS; int toRead = fieldsStream.ReadVInt(); byte[] b = new byte[toRead]; fieldsStream.ReadBytes(b, 0, b.Length); f = new Field(fi.name, false, System.Text.Encoding.GetEncoding("UTF-8").GetString(Uncompress(b)), store, index, termVector); f.SetOmitTermFreqAndPositions(fi.omitTermFreqAndPositions); f.SetOmitNorms(fi.omitNorms); } else { f = new Field(fi.name, false, fieldsStream.ReadString(), store, index, termVector); f.SetOmitTermFreqAndPositions(fi.omitTermFreqAndPositions); f.SetOmitNorms(fi.omitNorms); } doc.Add(f); } }