Exemple #1
0
        private void  AddDoc(System.String text, IndexWriter iw, float boost)
        {
            Document doc = new Document();
            Field    f   = new Field("key", text, Field.Store.YES, Field.Index.ANALYZED);

            f.SetBoost(boost);
            doc.Add(f);
            iw.AddDocument(doc);
        }
        // create the next document
        private Document NewDoc()
        {
            Document d     = new Document();
            float    boost = NextNorm();

            for (int i = 0; i < 10; i++)
            {
                Field f = new Field("f" + i, "v" + i, Field.Store.NO, Field.Index.NOT_ANALYZED);
                f.SetBoost(boost);
                d.Add(f);
            }
            return(d);
        }
Exemple #3
0
        public virtual void  TestDocBoost_()
        {
            RAMDirectory store  = new RAMDirectory();
            IndexWriter  writer = new IndexWriter(store, new SimpleAnalyzer(), true);

            Field f1 = Field.Text("Field", "word");
            Field f2 = Field.Text("Field", "word");

            f2.SetBoost(2.0f);

            Document d1 = new Document();
            Document d2 = new Document();
            Document d3 = new Document();
            Document d4 = new Document();

            d3.SetBoost(3.0f);
            d4.SetBoost(2.0f);

            d1.Add(f1);             // boost = 1
            d2.Add(f2);             // boost = 2
            d3.Add(f1);             // boost = 3
            d4.Add(f2);             // boost = 4

            writer.AddDocument(d1);
            writer.AddDocument(d2);
            writer.AddDocument(d3);
            writer.AddDocument(d4);
            writer.Optimize();
            writer.Close();

            float[] scores = new float[4];

            new IndexSearcher(store).Search(new TermQuery(new Term("Field", "word")), new AnonymousClassHitCollector(scores, this));

            float lastScore = 0.0f;

            for (int i = 0; i < 4; i++)
            {
                Assert.IsTrue(scores[i] > lastScore);
                lastScore = scores[i];
            }
        }
		// create the next document
		private Document NewDoc()
		{
			Document d = new Document();
			float boost = NextNorm();
			for (int i = 0; i < 10; i++)
			{
				Field f = new Field("f" + i, "v" + i, Field.Store.NO, Field.Index.NOT_ANALYZED);
				f.SetBoost(boost);
				d.Add(f);
			}
			return d;
		}
		private void  AddDoc(System.String text, IndexWriter iw, float boost)
		{
			Document doc = new Document();
			Field f = new Field("key", text, Field.Store.YES, Field.Index.ANALYZED);
			f.SetBoost(boost);
			doc.Add(f);
			iw.AddDocument(doc);
		}
		public override void  SetUp()
		{
			base.SetUp();
			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 < 1000; i++)
			{
				Document doc = new Document();
				Field noPayloadField = new Field("noPayLoad", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED);
				noPayloadField.SetBoost(0);
				doc.Add(noPayloadField);
				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
				doc.Add(new Field("multiField", English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
				writer.AddDocument(doc);
			}
			writer.Optimize();
			writer.Close();
			
			searcher = new IndexSearcher(directory);
			searcher.SetSimilarity(similarity);
		}
		// create the next document
		private Lucene.Net.Documents.Document NewDoc()
		{
			Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
			float boost = NextNorm();
			for (int i = 0; i < 10; i++)
			{
				Field f = new Field("f" + i, "v" + i, Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.UN_TOKENIZED);
				f.SetBoost(boost);
				d.Add(f);
			}
			return d;
		}