当前位置: 首页>>代码示例>>C#>>正文


C# Lucene.Net.Index.IndexWriter.SetSimilarity方法代码示例

本文整理汇总了C#中Lucene.Net.Index.IndexWriter.SetSimilarity方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.SetSimilarity方法的具体用法?C# Lucene.Net.Index.IndexWriter.SetSimilarity怎么用?C# Lucene.Net.Index.IndexWriter.SetSimilarity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Index.IndexWriter的用法示例。


在下文中一共展示了Lucene.Net.Index.IndexWriter.SetSimilarity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUp

		public override void  SetUp()
		{
			base.SetUp();
			RAMDirectory directory = new RAMDirectory();
			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
			IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
			writer.SetSimilarity(similarity);
			//writer.infoStream = System.out;
			for (int i = 0; i < 1000; i++)
			{
				Document doc = new Document();
				Field noPayloadField = new Field(PayloadHelper.NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED);
				//noPayloadField.setBoost(0);
				doc.Add(noPayloadField);
				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
				doc.Add(new Field("multiField", English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
				writer.AddDocument(doc);
			}
			writer.Optimize();
			writer.Close();
			
			searcher = new IndexSearcher(directory);
			searcher.SetSimilarity(similarity);
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:24,代码来源:TestBoostingTermQuery.cs

示例2: TestSimilarity_

		public virtual void  TestSimilarity_()
		{
			RAMDirectory store = new RAMDirectory();
			IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
			writer.SetSimilarity(new SimpleSimilarity());
			
			Document d1 = new Document();
			d1.Add(Field.Text("Field", "a c"));
			
			Document d2 = new Document();
			d2.Add(Field.Text("Field", "a b c"));
			
			writer.AddDocument(d1);
			writer.AddDocument(d2);
			writer.Optimize();
			writer.Close();
			
			float[] scores = new float[4];
			
			Searcher searcher = new IndexSearcher(store);
			searcher.SetSimilarity(new SimpleSimilarity());
			
			Term a = new Term("Field", "a");
			Term b = new Term("Field", "b");
			Term c = new Term("Field", "c");
			
			searcher.Search(new TermQuery(b), new AnonymousClassHitCollector(this));
			
			BooleanQuery bq = new BooleanQuery();
			bq.Add(new TermQuery(a), false, false);
			bq.Add(new TermQuery(b), false, false);
			//System.out.println(bq.toString("Field"));
			searcher.Search(bq, new AnonymousClassHitCollector1(this));
			
			PhraseQuery pq = new PhraseQuery();
			pq.Add(a);
			pq.Add(c);
			//System.out.println(pq.toString("Field"));
			searcher.Search(pq, new AnonymousClassHitCollector2(this));
			
			pq.SetSlop(2);
			//System.out.println(pq.toString("Field"));
			searcher.Search(pq, new AnonymousClassHitCollector3(this));
		}
开发者ID:emtees,项目名称:old-code,代码行数:44,代码来源:TestSimilarity.cs

示例3: SetUp

		public override void SetUp()
		{
			
			base.SetUp();
			
			index = new RAMDirectory();
			IndexWriter writer = new IndexWriter(index, new WhitespaceAnalyzer(), true);
			writer.SetSimilarity(sim);
			
			// hed is the most important field, dek is secondary
			
			// d1 is an "ok" match for:  albino elephant
			{
				Lucene.Net.Documents.Document d1 = new Lucene.Net.Documents.Document();
				d1.Add(new Field("id", "d1", Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("id", "d1"));
				d1.Add(new Field("hed", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "elephant"));
				d1.Add(new Field("dek", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("dek", "elephant"));
				writer.AddDocument(d1);
			}
			
			// d2 is a "good" match for:  albino elephant
			{
				Lucene.Net.Documents.Document d2 = new Lucene.Net.Documents.Document();
				d2.Add(new Field("id", "d2", Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("id", "d2"));
				d2.Add(new Field("hed", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "elephant"));
				d2.Add(new Field("dek", "albino", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("dek", "albino"));
				d2.Add(new Field("dek", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("dek", "elephant"));
				writer.AddDocument(d2);
			}
			
			// d3 is a "better" match for:  albino elephant
			{
				Lucene.Net.Documents.Document d3 = new Lucene.Net.Documents.Document();
				d3.Add(new Field("id", "d3", Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("id", "d3"));
				d3.Add(new Field("hed", "albino", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "albino"));
				d3.Add(new Field("hed", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "elephant"));
				writer.AddDocument(d3);
			}
			
			// d4 is the "best" match for:  albino elephant
			{
				Lucene.Net.Documents.Document d4 = new Lucene.Net.Documents.Document();
				d4.Add(new Field("id", "d4", Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("id", "d4"));
				d4.Add(new Field("hed", "albino", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "albino"));
				d4.Add(new Field("hed", "elephant", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("hed", "elephant"));
				d4.Add(new Field("dek", "albino", Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("dek", "albino"));
				writer.AddDocument(d4);
			}
			
			writer.Close();
			
			r = IndexReader.Open(index);
			s = new IndexSearcher(r);
			s.SetSimilarity(sim);
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:55,代码来源:TestDisjunctionMaxQuery.cs

示例4: TestPayloadSpanUtil

		public virtual void  TestPayloadSpanUtil()
		{
			RAMDirectory directory = new RAMDirectory();
			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
			IndexWriter writer = new IndexWriter(directory, analyzer, true);
			writer.SetSimilarity(similarity);
			Document doc = new Document();
			doc.Add(new Field(PayloadHelper.FIELD, "xx rr yy mm  pp", Field.Store.YES, Field.Index.ANALYZED));
			writer.AddDocument(doc);
			
			writer.Close();
			
			IndexSearcher searcher = new IndexSearcher(directory);
			
			IndexReader reader = searcher.GetIndexReader();
			PayloadSpanUtil psu = new PayloadSpanUtil(reader);
			
			System.Collections.Generic.ICollection<byte[]> payloads = psu.GetPayloadsForQuery(new TermQuery(new Term(PayloadHelper.FIELD, "rr")));
			if (DEBUG)
				System.Console.Out.WriteLine("Num payloads:" + payloads.Count);
			System.Collections.IEnumerator it = payloads.GetEnumerator();
			while (it.MoveNext())
			{
				byte[] bytes = (byte[]) it.Current;
				if (DEBUG)
					System.Console.Out.WriteLine(new System.String(System.Text.UTF8Encoding.UTF8.GetChars(bytes)));
			}
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:28,代码来源:TestPayloadSpans.cs

示例5: GetSearcher

		private IndexSearcher GetSearcher()
		{
			RAMDirectory directory = new RAMDirectory();
			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
			System.String[] docs = new System.String[]{"xx rr yy mm  pp", "xx yy mm rr pp", "nopayload qq ss pp np", "one two three four five six seven eight nine ten eleven", "nine one two three four five six seven eight eleven ten"};
			IndexWriter writer = new IndexWriter(directory, analyzer, true);
			
			writer.SetSimilarity(similarity);
			
			Document doc = null;
			for (int i = 0; i < docs.Length; i++)
			{
				doc = new Document();
				System.String docText = docs[i];
				doc.Add(new Field(PayloadHelper.FIELD, docText, Field.Store.YES, Field.Index.ANALYZED));
				writer.AddDocument(doc);
			}
			
			writer.Close();
			
			IndexSearcher searcher = new IndexSearcher(directory);
			return searcher;
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:23,代码来源:TestPayloadSpans.cs

示例6: GetSpanNotSearcher

		public virtual IndexSearcher GetSpanNotSearcher()
		{
			RAMDirectory directory = new RAMDirectory();
			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
			IndexWriter writer = new IndexWriter(directory, analyzer, true);
			writer.SetSimilarity(similarity);
			
			Document doc = new Document();
			doc.Add(new Field(PayloadHelper.FIELD, "one two three one four three", Field.Store.YES, Field.Index.ANALYZED));
			writer.AddDocument(doc);
			
			writer.Close();
			
			IndexSearcher searcher = new IndexSearcher(directory);
			searcher.SetSimilarity(similarity);
			return searcher;
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:17,代码来源:TestPayloadSpans.cs

示例7: SetUp

 public override void  SetUp()
 {
     base.SetUp();
     RAMDirectory directory = new RAMDirectory();
     PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
     IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
     writer.SetSimilarity(similarity);
     //writer.infoStream = System.out;
     for (int i = 0; i < 1000; i++)
     {
         Document doc = new Document();
         doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
         System.String txt = English.IntToEnglish(i) + ' ' + English.IntToEnglish(i + 1);
         doc.Add(new Field("field2", txt, Field.Store.YES, Field.Index.ANALYZED));
         writer.AddDocument(doc);
     }
     writer.Optimize();
     writer.Close();
     
     searcher = new IndexSearcher(directory, true);
     searcher.Similarity = similarity;
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:22,代码来源:TestPayloadNearQuery.cs

示例8: TestSimilarity_Renamed

 public virtual void  TestSimilarity_Renamed()
 {
     RAMDirectory store = new RAMDirectory();
     IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.SetSimilarity(new SimpleSimilarity());
     
     Document d1 = new Document();
     d1.Add(new Field("field", "a c", Field.Store.YES, Field.Index.ANALYZED));
     
     Document d2 = new Document();
     d2.Add(new Field("field", "a b c", Field.Store.YES, Field.Index.ANALYZED));
     
     writer.AddDocument(d1);
     writer.AddDocument(d2);
     writer.Optimize();
     writer.Close();
     
     Searcher searcher = new IndexSearcher(store, true);
     searcher.Similarity = new SimpleSimilarity();
     
     Term a = new Term("field", "a");
     Term b = new Term("field", "b");
     Term c = new Term("field", "c");
     
     searcher.Search(new TermQuery(b), new AnonymousClassCollector(this));
     
     BooleanQuery bq = new BooleanQuery();
     bq.Add(new TermQuery(a), Occur.SHOULD);
     bq.Add(new TermQuery(b), Occur.SHOULD);
     //System.out.println(bq.toString("field"));
     searcher.Search(bq, new AnonymousClassCollector1(this));
     
     PhraseQuery pq = new PhraseQuery();
     pq.Add(a);
     pq.Add(c);
     //System.out.println(pq.toString("field"));
     searcher.Search(pq, new AnonymousClassCollector2(this));
     
     pq.Slop = 2;
     //System.out.println(pq.toString("field"));
     searcher.Search(pq, new AnonymousClassCollector3(this));
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:42,代码来源:TestSimilarity.cs

示例9: SetUp

		/// <summary> Sets up a RAMDirectory, and adds documents (using English.intToEnglish()) with two fields: field and multiField
		/// and analyzes them using the PayloadAnalyzer
		/// </summary>
		/// <param name="similarity">The Similarity class to use in the Searcher
		/// </param>
		/// <param name="numDocs">The num docs to add
		/// </param>
		/// <returns> An IndexSearcher
		/// </returns>
		/// <throws>  IOException </throws>
		public virtual IndexSearcher SetUp(Similarity similarity, int numDocs)
		{
			RAMDirectory directory = new RAMDirectory();
			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
			IndexWriter writer = new IndexWriter(directory, analyzer, true);
			writer.SetSimilarity(similarity);
			//writer.infoStream = System.out;
			for (int i = 0; i < numDocs; i++)
			{
				Document doc = new Document();
				doc.Add(new Field(FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
				doc.Add(new Field(MULTI_FIELD, English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
				doc.Add(new Field(NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
				writer.AddDocument(doc);
			}
			//writer.optimize();
			writer.Close();
			
			IndexSearcher searcher = new IndexSearcher(directory);
			searcher.SetSimilarity(similarity);
			return searcher;
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:32,代码来源:PayloadHelper.cs

示例10: TestSimilarity_Renamed_Method

		public virtual void  TestSimilarity_Renamed_Method()
		{
			RAMDirectory store = new RAMDirectory();
			IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
			writer.SetSimilarity(new SimpleSimilarity());
			
			Lucene.Net.Documents.Document d1 = new Lucene.Net.Documents.Document();
			d1.Add(new Field("field", "a c", Field.Store.YES, Field.Index.TOKENIZED));
			
			Lucene.Net.Documents.Document d2 = new Lucene.Net.Documents.Document();
			d2.Add(new Field("field", "a b c", Field.Store.YES, Field.Index.TOKENIZED));
			
			writer.AddDocument(d1);
			writer.AddDocument(d2);
			writer.Optimize();
			writer.Close();
			
			Searcher searcher = new IndexSearcher(store);
			searcher.SetSimilarity(new SimpleSimilarity());
			
			Term a = new Term("field", "a");
			Term b = new Term("field", "b");
			Term c = new Term("field", "c");
			
			searcher.Search(new TermQuery(b), new AnonymousClassHitCollector(this));
			
			BooleanQuery bq = new BooleanQuery();
			bq.Add(new TermQuery(a), BooleanClause.Occur.SHOULD);
			bq.Add(new TermQuery(b), BooleanClause.Occur.SHOULD);
			//System.out.println(bq.toString("field"));
			searcher.Search(bq, new AnonymousClassHitCollector1(this));
			
			PhraseQuery pq = new PhraseQuery();
			pq.Add(a);
			pq.Add(c);
			//System.out.println(pq.toString("field"));
			searcher.Search(pq, new AnonymousClassHitCollector2(this));
			
			pq.SetSlop(2);
			//System.out.println(pq.toString("field"));
			searcher.Search(pq, new AnonymousClassHitCollector3(this));
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:42,代码来源:TestSimilarity.cs


注:本文中的Lucene.Net.Index.IndexWriter.SetSimilarity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。