本文整理汇总了C#中Document.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Add方法的具体用法?C# Document.Add怎么用?C# Document.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Import
public override Document Import()
{
var toret = new Document();
Question q = null;
string line;
toret.Clear();
line = this.ReadLine();
while ( line != null ) {
line = line.Trim();
if ( line.Length > 0 ) {
if ( IsQuestion( ref line ) ) {
if ( q != null ) {
toret.Add( q );
}
q = new Question( line );
q.ClearAnswers();
}
else
if ( IsAnswer( ref line ) ) {
q.AddAnswer( line );
}
}
line = this.ReadLine();
}
if ( q != null ) {
toret.Add( q );
}
return toret;
}
示例2: SetUp
public override void SetUp()
{
base.SetUp();
Document doc;
Rd1 = NewDirectory();
IndexWriter iw1 = new IndexWriter(Rd1, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
doc = new Document();
doc.Add(NewTextField("field1", "the quick brown fox jumps", Field.Store.YES));
doc.Add(NewTextField("field2", "the quick brown fox jumps", Field.Store.YES));
iw1.AddDocument(doc);
iw1.Dispose();
Rd2 = NewDirectory();
IndexWriter iw2 = new IndexWriter(Rd2, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
doc = new Document();
doc.Add(NewTextField("field1", "the fox jumps over the lazy dog", Field.Store.YES));
doc.Add(NewTextField("field3", "the fox jumps over the lazy dog", Field.Store.YES));
iw2.AddDocument(doc);
iw2.Dispose();
this.Ir1 = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(Rd1));
this.Ir2 = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(Rd2));
}
示例3: SetUp
public override void SetUp()
{
base.SetUp();
INDEX_SIZE = AtLeast(2000);
Index = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Index);
RandomGen random = new RandomGen(this, Random());
for (int i = 0; i < INDEX_SIZE; ++i) // don't decrease; if to low the
{
// problem doesn't show up
Document doc = new Document();
if ((i % 5) != 0) // some documents must not have an entry in the first
{
// sort field
doc.Add(NewStringField("publicationDate_", random.LuceneDate, Field.Store.YES));
}
if ((i % 7) == 0) // some documents to match the query (see below)
{
doc.Add(NewTextField("content", "test", Field.Store.YES));
}
// every document has a defined 'mandant' field
doc.Add(NewStringField("mandant", Convert.ToString(i % 3), Field.Store.YES));
writer.AddDocument(doc);
}
Reader = writer.Reader;
writer.Dispose();
Query = new TermQuery(new Term("content", "test"));
}
示例4: UploadDocuments
public static void UploadDocuments(SearchIndexClient indexClient, string fileId, string fileName, string ocrText, KeyPhraseResult keyPhraseResult)
{
List<IndexAction> indexOperations = new List<IndexAction>();
var doc = new Document();
doc.Add("fileId", fileId);
doc.Add("fileName", fileName);
doc.Add("ocrText", ocrText);
doc.Add("keyPhrases", keyPhraseResult.KeyPhrases.ToList());
indexOperations.Add(IndexAction.Upload(doc));
try
{
indexClient.Documents.Index(new IndexBatch(indexOperations));
}
catch (IndexBatchException e)
{
// Sometimes when your Search service is under load, indexing will fail for some of the documents in
// the batch. Depending on your application, you can take compensating actions like delaying and
// retrying. For this simple demo, we just log the failed document keys and continue.
Console.WriteLine(
"Failed to index some of the documents: {0}",
String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
}
}
示例5: Form1
// From <ClickButt> -> PdfConnector PdfCreatora <- PdfCreator(naemBank,Bodytext)
// Form <Image> <- PdfConnector -- tworzyć pdf |
public Form1()
{
while (!fileBanksLists.EndOfStream)
{
InitializeComponent();
using (FileStream file = new FileStream(String.Format(path, nameBank), FileMode.Create))
{
Document document = new Document(PageSize.A7);
PdfWriter writer = PdfWriter.GetInstance(document, file);
/// Create metadate pdf file
document.AddAuthor(nameBank);
document.AddLanguage("pl");
document.AddSubject("Payment transaction");
document.AddTitle("Transaction");
document.AddKeywords("OutcomingNumber :" + OutcomingNumber);
document.AddKeywords("IncomingNumber :" + IncomingNumber);
/// Create text in pdf file
document.Open();
document.Add(new Paragraph(_przelew + "\n"));
document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n", nameBank)));
document.Add(new Paragraph(DateTime.Now.ToString()));
document.Close();
writer.Close();
file.Close();
}
}
}
示例6: buildPoiIndex
public bool buildPoiIndex(String sdbName,String indexPath)
{
soDataSource ds = axSuperWorkspace1.OpenDataSource(sdbName, "", seEngineType.sceSDBPlus, true);
if (ds.Datasets.Count == 0)
{
return false;
}
soDataset dataset = ds.Datasets[1];
if (dataset == null)
{
return false;
}
soDatasetVector objDtv = (soDatasetVector)dataset;
soRecordset objRd = objDtv.Query("", false, null, "");
if (objRd == null)
{
return false;
}
int count = objRd.RecordCount;
int i = 0;
IndexWriter writer = new IndexWriter(indexPath, objCA, true);
objRd.MoveFirst();
while (!objRd.IsEOF())
{
Document doc = new Document();
String name = objRd.GetFieldValueText("NAME_CHN");
doc.Add(new Field("Name", name, Field.Store.YES, Field.Index.TOKENIZED));
double x = (double)objRd.GetFieldValue("X_COORD");
double y = (double)objRd.GetFieldValue("Y_COORD");
List<Byte> locationByte = new List<Byte>();
locationByte.AddRange(BitConverter.GetBytes(x));
locationByte.AddRange(BitConverter.GetBytes(y));
doc.Add(new Field("Location", locationByte.ToArray(), Field.Store.YES));
writer.AddDocument(doc);
objRd.MoveNext();
i++;
this.backgroundWorker1.ReportProgress(i*100 / count);
//if (i== 100)
//{
// break;
//}
}
this.backgroundWorker1.ReportProgress(100);
writer.Close();
axSuperWorkspace1.Close();
return true;
}
示例7: CreateIndex
private void CreateIndex(IndexWriter writer, string a, string b)
{
Document doc = new Document();
doc.Add(new Field("title", a, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("content", b, Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
writer.Commit();
}
示例8: TestPayloadFieldBit
public virtual void TestPayloadFieldBit()
{
Directory ram = NewDirectory();
PayloadAnalyzer analyzer = new PayloadAnalyzer();
IndexWriter writer = new IndexWriter(ram, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document d = new Document();
// this field won't have any payloads
d.Add(NewTextField("f1", "this field has no payloads", Field.Store.NO));
// this field will have payloads in all docs, however not for all term positions,
// so this field is used to check if the DocumentWriter correctly enables the payloads bit
// even if only some term positions have payloads
d.Add(NewTextField("f2", "this field has payloads in all docs", Field.Store.NO));
d.Add(NewTextField("f2", "this field has payloads in all docs NO PAYLOAD", Field.Store.NO));
// this field is used to verify if the SegmentMerger enables payloads for a field if it has payloads
// enabled in only some documents
d.Add(NewTextField("f3", "this field has payloads in some docs", Field.Store.NO));
// only add payload data for field f2
analyzer.SetPayloadData("f2", "somedata".GetBytes(IOUtils.CHARSET_UTF_8), 0, 1);
writer.AddDocument(d);
// flush
writer.Dispose();
SegmentReader reader = GetOnlySegmentReader(DirectoryReader.Open(ram));
FieldInfos fi = reader.FieldInfos;
Assert.IsFalse(fi.FieldInfo("f1").HasPayloads(), "Payload field bit should not be set.");
Assert.IsTrue(fi.FieldInfo("f2").HasPayloads(), "Payload field bit should be set.");
Assert.IsFalse(fi.FieldInfo("f3").HasPayloads(), "Payload field bit should not be set.");
reader.Dispose();
// now we add another document which has payloads for field f3 and verify if the SegmentMerger
// enabled payloads for that field
analyzer = new PayloadAnalyzer(); // Clear payload state for each field
writer = new IndexWriter(ram, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(OpenMode_e.CREATE));
d = new Document();
d.Add(NewTextField("f1", "this field has no payloads", Field.Store.NO));
d.Add(NewTextField("f2", "this field has payloads in all docs", Field.Store.NO));
d.Add(NewTextField("f2", "this field has payloads in all docs", Field.Store.NO));
d.Add(NewTextField("f3", "this field has payloads in some docs", Field.Store.NO));
// add payload data for field f2 and f3
analyzer.SetPayloadData("f2", "somedata".GetBytes(IOUtils.CHARSET_UTF_8), 0, 1);
analyzer.SetPayloadData("f3", "somedata".GetBytes(IOUtils.CHARSET_UTF_8), 0, 3);
writer.AddDocument(d);
// force merge
writer.ForceMerge(1);
// flush
writer.Dispose();
reader = GetOnlySegmentReader(DirectoryReader.Open(ram));
fi = reader.FieldInfos;
Assert.IsFalse(fi.FieldInfo("f1").HasPayloads(), "Payload field bit should not be set.");
Assert.IsTrue(fi.FieldInfo("f2").HasPayloads(), "Payload field bit should be set.");
Assert.IsTrue(fi.FieldInfo("f3").HasPayloads(), "Payload field bit should be set.");
reader.Dispose();
ram.Dispose();
}
示例9: TestBefore
public virtual void TestBefore()
{
// create an index
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore);
long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
Document doc = new Document();
// add time that is in the past
doc.Add(NewStringField("datefield", DateTools.TimeToString(now - 1000, DateTools.Resolution.MILLISECOND), Field.Store.YES));
doc.Add(NewTextField("body", "Today is a very sunny day in New York City", Field.Store.YES));
writer.AddDocument(doc);
IndexReader reader = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(reader);
// filter that should preserve matches
// DateFilter df1 = DateFilter.Before("datefield", now);
TermRangeFilter df1 = TermRangeFilter.NewStringRange("datefield", DateTools.TimeToString(now - 2000, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now, DateTools.Resolution.MILLISECOND), false, true);
// filter that should discard matches
// DateFilter df2 = DateFilter.Before("datefield", now - 999999);
TermRangeFilter df2 = TermRangeFilter.NewStringRange("datefield", DateTools.TimeToString(0, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForthis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
ScoreDoc[] result;
// ensure that queries return expected results without DateFilter first
result = searcher.Search(query1, null, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, null, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
// run queries with DateFilter
result = searcher.Search(query1, df1, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query1, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, df1, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
result = searcher.Search(query2, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
reader.Dispose();
indexStore.Dispose();
}
示例10: btnFolder_Click
private void btnFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog dia = new FolderBrowserDialog();
DialogResult res = dia.ShowDialog();
if (res != System.Windows.Forms.DialogResult.OK)
{
return;
}
FSDirectory dir = FSDirectory.GetDirectory(Environment.CurrentDirectory + "\\LuceneIndex");
//Lucene.Net.Store.RAMDirectory dir = new RAMDirectory();
Lucene.Net.Analysis.Standard.StandardAnalyzer an = new Lucene.Net.Analysis.Standard.StandardAnalyzer();
IndexWriter wr = new IndexWriter(dir, an,true);
IStemmer stemmer = new EnglishStemmer();
DirectoryInfo diMain = new DirectoryInfo(dia.SelectedPath);
foreach(FileInfo fi in diMain.GetFiles()){
Document doc = new Document();
doc.Add(new Field("title", fi.Name,Field.Store.YES, Field.Index.NO));
//doc.Add(new Field("text", File.ReadAllText(fi.FullName),Field.Store.YES, Field.Index.TOKENIZED,Field.TermVector.YES));
doc.Add(new Field("text", PerformStemming(stemmer,NLPToolkit.Tokenizer.TokenizeNow(File.ReadAllText(fi.FullName)).ToArray()), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
wr.AddDocument(doc);
}
wr.Optimize();
wr.Flush();
wr.Close();
dir.Close();
IndexReader reader = IndexReader.Open(dir);
for (int i = 0; i < reader.MaxDoc(); i++)
{
if (reader.IsDeleted(i))
continue;
Document doc = reader.Document(i);
String docId = doc.Get("docId");
foreach (TermFreqVector vector in reader.GetTermFreqVectors(i))
{
foreach(string term in vector.GetTerms()){
Console.WriteLine(term);
}
}
// do something with docId here...
}
//IndexSearcher search = new IndexSearcher(wr.GetReader());
//MoreLikeThis mlt = new MoreLikeThis(wr.GetReader());
//FileInfo fitarget = new FileInfo(@"C:\Users\peacemaker\Desktop\TestNoBitcoin\test.txt");
//Query query = mlt.Like(fitarget);
//var hits = search.Search(query, int.MaxValue);
//foreach (ScoreDoc doc in hits.ScoreDocs)
//{
// textBox1.Text += doc.Score + Environment.NewLine;
//}
}
示例11: generarEncabezado
private static Document generarEncabezado(Document doc, string nombreSimulacion, string fecha, string hora)
{
string path = Application.StartupPath + "\\Resources\\logo.png";
Image logo = Image.GetInstance(new Uri(path));
logo.ScalePercent(30);
logo.Alignment = Image.TEXTWRAP | Image.ALIGN_LEFT;
string encabezadoStr = string.Format("Simulador FFCC\nNombre de Simulación: {0} Fecha: {1} Hora: {2}", nombreSimulacion, fecha, hora);
Paragraph encabezado = new Paragraph(encabezadoStr, FontFactory.GetFont("ARIAL", 10, iTextSharp.text.Font.BOLDITALIC));
doc.Add(logo);
doc.Add(encabezado);
return doc;
}
示例12: TestCalculateSizeOfComplexDoc
public void TestCalculateSizeOfComplexDoc()
{
var doc = new Document();
doc.Add("a", "a");
doc.Add("b", 1);
var sub = new Document().Add("c_1", 1).Add("c_2", DateTime.Now);
doc.Add("c", sub);
var ms = new MemoryStream();
var writer = new BsonWriter(ms, new BsonDocumentDescriptor());
Assert.AreEqual(51, writer.CalculateSizeObject(doc));
}
示例13: button1_Click
private void button1_Click(object sender, EventArgs e)
{
Document PdfDoc = new Document();
PdfWriter pdfwriter=PdfWriter.GetInstance(PdfDoc,new FileStream("sample.pdf",FileMode.Create));
PdfDoc.Open();
PdfDoc.Add(new Paragraph("anurag ambush"));
PdfDoc.NewPage();
PdfDoc.Add(new Paragraph("hello world again"));
PdfDoc.Close();
}
示例14: btnPrint_Click
private void btnPrint_Click(object sender, EventArgs e)
{
// Create a Document object
var document = new Document(PageSize.A4, 50, 50, 25, 25);
string file = "Choo.pdf";
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
//var writer = PdfWriter.GetInstance(document, output);
var writer = PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create));
// Open the Document for writing
document.Open();
var titleFont = FontFactory.GetFont("Arial", 18);
var subTitleFont = FontFactory.GetFont("Arial", 14);
var boldTableFont = FontFactory.GetFont("Arial", 12);
var endingMessageFont = FontFactory.GetFont("Arial", 10);
var bodyFont = FontFactory.GetFont("Arial", 12);
//document.Add(new Paragraph("Northwind Traders Receipt", titleFont);
Paragraph tit = new Paragraph();
Chunk c1 = new Chunk(" Ingresos Diarios \n", titleFont);
Chunk c2 = new Chunk("Ciclo Escolar 2012 - 2013 \n");
Chunk c3 = new Chunk("Dia consultado : 25/01/2013");
tit.Add(c1);
tit.Add(c2);
tit.Add(c3);
tit.IndentationLeft = 200f;
document.Add(tit);
PdfContentByte cb = writer.DirectContent;
cb.MoveTo(50, document.PageSize.Height / 2);
cb.LineTo(document.PageSize.Width - 50, document.PageSize.Height / 2);
cb.Stroke();
var orderInfoTable = new PdfPTable(2);
orderInfoTable.HorizontalAlignment = 0;
orderInfoTable.SpacingBefore = 10;
orderInfoTable.SpacingAfter = 10;
orderInfoTable.DefaultCell.Border = 0;
orderInfoTable.SetWidths(new int[] { 1, 4 });
orderInfoTable.AddCell(new Phrase("Order:", boldTableFont));
orderInfoTable.AddCell("textorder");
orderInfoTable.AddCell(new Phrase("Price:", boldTableFont));
orderInfoTable.AddCell(Convert.ToDecimal(444444).ToString("c"));
document.Add(orderInfoTable);
document.Close();
System.Diagnostics.Process.Start(file);
}
示例15: ApplyData
public static void ApplyData(string fileName)
{
List<IndexAction> indexOperations = new List<IndexAction>();
string line;
int rowCounter = 0;
int totalCounter = 0;
int n;
double d;
// Get unique rated movies
IEnumerable<int> ratedMovies = ImportRatedIDs();
// Read the file and display it line by line.
using (StreamReader file = new StreamReader(fileName))
{
file.ReadLine(); // Skip header
while ((line = file.ReadLine()) != null)
{
char[] delimiters = new char[] { '\t' };
string[] parts = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
// If it is a rated movie, add it
if (ratedMovies.Contains(Convert.ToInt32(parts[0])))
{
Document doc = new Document();
doc.Add("id", Convert.ToString(parts[0]));
doc.Add("title", Convert.ToString(parts[1]));
doc.Add("imdbID", Convert.ToInt32(parts[2]));
doc.Add("spanishTitle", Convert.ToString(parts[3]));
doc.Add("imdbPictureURL", Convert.ToString(parts[4]));
if (int.TryParse(parts[5], out n))
doc.Add("year", Convert.ToInt32(parts[5]));
doc.Add("rtID", Convert.ToString(parts[6]));
if (double.TryParse(parts[7], out d))
doc.Add("rtAllCriticsRating", Convert.ToDouble(parts[7]));
indexOperations.Add(new IndexAction(IndexActionType.Upload, doc));
rowCounter++;
totalCounter++;
if (rowCounter == 1000)
{
IndexClient.Documents.Index(new IndexBatch(indexOperations));
indexOperations.Clear();
Console.WriteLine("Uploaded {0} docs...", totalCounter);
rowCounter = 0;
}
}
}
if (rowCounter > 0)
{
Console.WriteLine("Uploading {0} docs...", rowCounter);
IndexClient.Documents.Index(new IndexBatch(indexOperations));
}
file.Close();
}
}