Filter to remove duplicate values from search results. WARNING: for this to work correctly, you may have to wrap your reader as it cannot current deduplicate across different index segments.
Inheritance: Lucene.Net.Search.Filter
示例#1
0
        public void TestKeepsLastFilter()
        {
            DuplicateFilter df = new DuplicateFilter(KEY_FIELD);

            df.KeepMode = (KeepMode.KM_USE_LAST_OCCURRENCE);
            ScoreDoc[] hits = searcher.Search(tq, df, 1000).ScoreDocs;
            assertTrue("Filtered searching should have found some matches", hits.Length > 0);
            foreach (ScoreDoc hit in hits)
            {
                Document d   = searcher.Doc(hit.Doc);
                string   url = d.Get(KEY_FIELD);
                DocsEnum td  = TestUtil.Docs(Random(), reader,
                                             KEY_FIELD,
                                             new BytesRef(url),
                                             MultiFields.GetLiveDocs(reader),
                                             null,
                                             0);

                int lastDoc = 0;
                while (td.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                {
                    lastDoc = td.DocID;
                }
                assertEquals("Duplicate urls should return last doc", lastDoc, hit.Doc);
            }
        }
示例#2
0
        public void TestDefaultFilter()
        {
            DuplicateFilter  df      = new DuplicateFilter(KEY_FIELD);
            HashSet <string> results = new HashSet <string>();

            ScoreDoc[] hits = searcher.Search(tq, df, 1000).ScoreDocs;

            foreach (ScoreDoc hit in hits)
            {
                Document d   = searcher.Doc(hit.Doc);
                string   url = d.Get(KEY_FIELD);
                assertFalse("No duplicate urls should be returned", results.contains(url));
                results.add(url);
            }
        }
示例#3
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if ((obj == null) || (obj.GetType() != this.GetType()))
            {
                return(false);
            }

            DuplicateFilter other = (DuplicateFilter)obj;

            return(keepMode == other.keepMode &&
                   processingMode == other.processingMode &&
                   fieldName != null && fieldName.Equals(other.fieldName, StringComparison.Ordinal));
        }
示例#4
0
        public void TestFastFilter()
        {
            DuplicateFilter df = new DuplicateFilter(KEY_FIELD);

            df.ProcessingMode = (ProcessingMode.PM_FAST_INVALIDATION);
            HashSet <string> results = new HashSet <string>();

            ScoreDoc[] hits = searcher.Search(tq, df, 1000).ScoreDocs;
            assertTrue("Filtered searching should have found some matches", hits.Length > 0);

            foreach (ScoreDoc hit in hits)
            {
                Document d   = searcher.Doc(hit.Doc);
                string   url = d.Get(KEY_FIELD);
                assertFalse("No duplicate urls should be returned", results.contains(url));
                results.add(url);
            }
            assertEquals("Two urls found", 2, results.size());
        }