/// <summary> Adds a document to this index, using the provided analyzer instead of the /// value of {@link #GetAnalyzer()}. If the document contains more than /// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are /// discarded. /// </summary> public virtual void AddDocument(Document doc, Analyzer analyzer) { DocumentWriter dw = new DocumentWriter(ramDirectory, analyzer, this); dw.SetInfoStream(infoStream); System.String segmentName = NewSegmentName(); dw.AddDocument(segmentName, doc); lock (this) { segmentInfos.Add(new SegmentInfo(segmentName, 1, ramDirectory)); MaybeMergeSegments(); } }
/// <summary> Writes the document to the directory segment using the analyzer and the similarity score</summary> /// <param name="">dir /// </param> /// <param name="">analyzer /// </param> /// <param name="">similarity /// </param> /// <param name="">segment /// </param> /// <param name="">doc /// </param> public static void WriteDoc(Directory dir, Analyzer analyzer, Similarity similarity, System.String segment, Document doc) { DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50); try { writer.AddDocument(segment, doc); } catch (System.IO.IOException e) { System.Console.Error.WriteLine(e.StackTrace); } }
public static void IndexDoc(System.String segment, System.String fileName) { Directory directory = FSDirectory.GetDirectory("test", false); Analyzer analyzer = new SimpleAnalyzer(); DocumentWriter writer = new DocumentWriter(directory, analyzer, Similarity.GetDefault(), 1000); System.IO.FileInfo file = new System.IO.FileInfo(fileName); Document doc = Lucene.Net.Demo.FileDocument.Document(file); writer.AddDocument(segment, doc); directory.Close(); }
private void IndexDoc(System.String segment, System.String fileName) { Directory directory = FSDirectory.GetDirectory(indexDir, false); Analyzer analyzer = new SimpleAnalyzer(); DocumentWriter writer = new DocumentWriter(directory, analyzer, Similarity.GetDefault(), 1000); System.IO.FileInfo file = new System.IO.FileInfo(workDir.FullName + "\\" + fileName); Document doc = FileDocument.Document(file); writer.AddDocument(segment, doc); directory.Close(); }
protected virtual void SetUp() { fieldInfos = new FieldInfos(); DocHelper.SetupDoc(testDoc); fieldInfos.Add(testDoc); DocumentWriter writer = new DocumentWriter(dir, new WhitespaceAnalyzer(), Similarity.GetDefault(), 50); Assert.IsTrue(writer != null); try { writer.AddDocument("test", testDoc); } catch (System.IO.IOException e) { } }
public virtual void TestAddDocument() { Analyzer analyzer = new WhitespaceAnalyzer(); Similarity similarity = Similarity.GetDefault(); DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50); Assert.IsTrue(writer != null); try { writer.AddDocument("test", testDoc); //After adding the document, we should be able to read it back in SegmentReader reader = new SegmentReader(new SegmentInfo("test", 1, dir)); Assert.IsTrue(reader != null); Document doc = reader.Document(0); Assert.IsTrue(doc != null); //System.out.println("Document: " + doc); Field[] fields = doc.GetFields("textField2"); Assert.IsTrue(fields != null && fields.Length == 1); Assert.IsTrue(fields[0].StringValue().Equals(DocHelper.FIELD_2_TEXT)); Assert.IsTrue(fields[0].IsTermVectorStored() == true); fields = doc.GetFields("textField1"); Assert.IsTrue(fields != null && fields.Length == 1); Assert.IsTrue(fields[0].StringValue().Equals(DocHelper.FIELD_1_TEXT)); Assert.IsTrue(fields[0].IsTermVectorStored() == false); fields = doc.GetFields("keyField"); Assert.IsTrue(fields != null && fields.Length == 1); Assert.IsTrue(fields[0].StringValue().Equals(DocHelper.KEYWORD_TEXT)); } catch (System.IO.IOException e) { System.Console.Error.WriteLine(e.StackTrace); Assert.IsTrue(false); } }
/// <summary> Adds a document to this index, using the provided analyzer instead of the /// value of {@link #GetAnalyzer()}. If the document contains more than /// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are /// discarded. /// </summary> public virtual void AddDocument(Document doc, Analyzer analyzer) { DocumentWriter dw = new DocumentWriter(ramDirectory, analyzer, this); dw.SetInfoStream(infoStream); System.String segmentName = NewSegmentName(); dw.AddDocument(segmentName, doc); lock (this) { segmentInfos.Add(new SegmentInfo(segmentName, 1, ramDirectory)); singleDocSegmentsCount++; MaybeMergeSegments(); } }
internal virtual SegmentInfo BuildSingleDocSegment(Document doc, Analyzer analyzer) { DocumentWriter dw = new DocumentWriter(ramDirectory, analyzer, this); dw.SetInfoStream(infoStream); System.String segmentName = NewRamSegmentName(); dw.AddDocument(segmentName, doc); return new SegmentInfo(segmentName, 1, ramDirectory, false, false); }