Пример #1
0
		public virtual void  TestMultiValueSource()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
			Document doc = new Document();
			Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
			doc.Add(f);
			
			for (int i = 0; i < 17; i++)
			{
				f.SetValue("" + i);
				w.AddDocument(doc);
				w.Commit();
			}
			
			IndexReader r = w.GetReader();
			w.Close();
			
			Assert.IsTrue(r.GetSequentialSubReaders().Length > 1);
			
			ValueSource s1 = new IntFieldSource("field");
			DocValues v1 = s1.GetValues(r);
			DocValues v2 = new MultiValueSource(s1).GetValues(r);
			
			for (int i = 0; i < r.MaxDoc(); i++)
			{
				Assert.AreEqual(v1.IntVal(i), i);
				Assert.AreEqual(v2.IntVal(i), i);
			}
			
			Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches();
			
			r.Close();
			dir.Close();
		}
Пример #2
0
            internal MultiDocValues(MultiValueSource enclosingInstance, IndexReader[] subReaders)
            {
                InitBlock(enclosingInstance);
                docValues = new DocValues[subReaders.Length];
                docStarts = new int[subReaders.Length];
                int base_Renamed = 0;

                for (int i = 0; i < subReaders.Length; i++)
                {
                    docValues[i]  = Enclosing_Instance.other.GetValues(subReaders[i]);
                    docStarts[i]  = base_Renamed;
                    base_Renamed += subReaders[i].MaxDoc();
                }
            }
Пример #3
0
        // Test that queries based on reverse/ordFieldScore scores correctly
        private void  DoTestRank(System.String field, bool inOrder)
        {
            IndexSearcher s = new IndexSearcher(dir);
            ValueSource   vs;

            if (inOrder)
            {
                vs = new MultiValueSource(new OrdFieldSource(field));
            }
            else
            {
                vs = new MultiValueSource(new ReverseOrdFieldSource(field));
            }

            Query q = new ValueSourceQuery(vs);

            Log("test: " + q);
            QueryUtils.Check(q, s);
            ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
            Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
            System.String prevID = inOrder?"IE":"IC";             // smaller than all ids of docs in this test ("ID0001", etc.)

            for (int i = 0; i < h.Length; i++)
            {
                System.String resID = s.Doc(h[i].doc).Get(ID_FIELD);
                Log(i + ".   score=" + h[i].score + "  -  " + resID);
                Log(s.Explain(q, h[i].doc));
                if (inOrder)
                {
                    Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
                }
                else
                {
                    Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
                }
                prevID = resID;
            }
        }
Пример #4
0
        public virtual void  TestMultiValueSource()
        {
            Directory   dir = new MockRAMDirectory();
            IndexWriter w   = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
            Document    doc = new Document();
            Field       f   = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);

            doc.Add(f);

            for (int i = 0; i < 17; i++)
            {
                f.SetValue("" + i);
                w.AddDocument(doc);
                w.Commit();
            }

            IndexReader r = w.GetReader();

            w.Close();

            Assert.IsTrue(r.GetSequentialSubReaders().Length > 1);

            ValueSource s1 = new IntFieldSource("field");
            DocValues   v1 = s1.GetValues(r);
            DocValues   v2 = new MultiValueSource(s1).GetValues(r);

            for (int i = 0; i < r.MaxDoc(); i++)
            {
                Assert.AreEqual(v1.IntVal(i), i);
                Assert.AreEqual(v2.IntVal(i), i);
            }

            Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches();

            r.Close();
            dir.Close();
        }
Пример #5
0
		// Test that queries based on reverse/ordFieldScore scores correctly
		private void  DoTestRank(System.String field, bool inOrder)
		{
			IndexSearcher s = new IndexSearcher(dir);
			ValueSource vs;
			if (inOrder)
			{
				vs = new MultiValueSource(new OrdFieldSource(field));
			}
			else
			{
				vs = new MultiValueSource(new ReverseOrdFieldSource(field));
			}
			
			Query q = new ValueSourceQuery(vs);
			Log("test: " + q);
			QueryUtils.Check(q, s);
			ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
			Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
			System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)
			
			for (int i = 0; i < h.Length; i++)
			{
				System.String resID = s.Doc(h[i].doc).Get(ID_FIELD);
				Log(i + ".   score=" + h[i].score + "  -  " + resID);
				Log(s.Explain(q, h[i].doc));
				if (inOrder)
				{
					Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
				}
				else
				{
					Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
				}
				prevID = resID;
			}
		}
 private void InitBlock(MultiValueSource enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
 internal MultiDocValues(MultiValueSource enclosingInstance, IndexReader[] subReaders)
 {
     InitBlock(enclosingInstance);
     docValues = new DocValues[subReaders.Length];
     docStarts = new int[subReaders.Length];
     int base_Renamed = 0;
     for (int i = 0; i < subReaders.Length; i++)
     {
         docValues[i] = Enclosing_Instance.other.GetValues(subReaders[i]);
         docStarts[i] = base_Renamed;
         base_Renamed += subReaders[i].MaxDoc();
     }
 }
Пример #8
0
 private void  InitBlock(MultiValueSource enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }