public void Should_read_and_write_doc_values() { var version = LuceneVersion.LUCENE_48; var indexWriter = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(version, new StandardAnalyzer(version))); using (indexWriter) { for (byte i = 0; i < 255; i++) { var document = new Document(); document.AddBinaryDocValuesField("field", new BytesRef(new byte[] { i })); indexWriter.AddDocument(document); } indexWriter.Commit(); using (var reader = indexWriter.GetReader(true)) { var bytesRef = new BytesRef(1); for (byte i = 0; i < 255; i++) { reader.GetBinaryValue("field", i, bytesRef); Assert.Equal(i, bytesRef.Bytes[0]); } } } }
public Task IndexAsync(NamedId <Guid> schemaId, Immutable <IndexCommand[]> updates) { foreach (var command in updates.Value) { switch (command) { case DeleteIndexEntry delete: index.Writer.DeleteDocuments(new Term(MetaId, delete.DocId)); break; case UpdateIndexEntry update: try { var values = GetValue(update.ServeAll, update.ServePublished); index.Writer.UpdateBinaryDocValue(new Term(MetaId, update.DocId), MetaFor, values); } catch (ArgumentException) { } break; case UpsertIndexEntry upsert: { var document = new Document(); document.AddStringField(MetaId, upsert.DocId, Field.Store.YES); document.AddStringField(MetaContentId, upsert.ContentId.ToString(), Field.Store.YES); document.AddStringField(MetaSchemaId, schemaId.Id.ToString(), Field.Store.YES); document.AddStringField(MetaSchemaName, schemaId.Name, Field.Store.YES); document.AddBinaryDocValuesField(MetaFor, GetValue(upsert.ServeAll, upsert.ServePublished)); foreach (var(key, value) in upsert.Texts) { document.AddTextField(key, value, Field.Store.NO); } index.Writer.UpdateDocument(new Term(MetaId, upsert.DocId), document); break; } } } return(TryCommitAsync()); }
public static void SetBinaryDocValue(this Document document, string name, BytesRef value) { document.RemoveField(name); document.AddBinaryDocValuesField(name, value); }
public void Index(Document document, byte forDraft, byte forPublished) { document.RemoveField(MetaFor); document.AddBinaryDocValuesField(MetaFor, GetValue(forDraft, forPublished)); }