示例#1
0
        /// <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();
            }
        }
示例#2
0
文件: DocHelper.cs 项目: yonder/mono
        /// <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);
            }
        }
示例#3
0
文件: DocTest.cs 项目: runefs/Marvin
		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();
		}
示例#4
0
文件: TestDoc.cs 项目: yonder/mono
        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();
        }
示例#5
0
文件: DocTest.cs 项目: raj581/Marvin
        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();
        }
示例#6
0
		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)
			{
				
			}
		}
示例#7
0
        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)
            {
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
		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);
			}
		}
示例#10
0
		/// <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);
			}
		}
示例#11
0
		/// <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();
			}
		}
示例#12
0
文件: TestDoc.cs 项目: runefs/Marvin
		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();
		}
示例#13
0
		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);
		}