예제 #1
0
 internal AnonymousClassPrefixGenerator(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance, Lucene.Net.Index.Term Param1) : base(Param1)
 {
     InitBlock(bitSet, enclosingInstance);
 }
예제 #2
0
        public virtual void TestPrefixFilter_Mem()
        {
            Directory directory = NewDirectory();

            string[]          categories = new string[] { "/Computers/Linux", "/Computers/Mac/One", "/Computers/Mac/Two", "/Computers/Windows" };
            RandomIndexWriter writer     = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, directory);

            for (int i = 0; i < categories.Length; i++)
            {
                Document doc = new Document();
                doc.Add(NewStringField("category", categories[i], Field.Store.YES));
                writer.AddDocument(doc);
            }
            IndexReader reader = writer.GetReader();

            // PrefixFilter combined with ConstantScoreQuery
            PrefixFilter  filter   = new PrefixFilter(new Term("category", "/Computers"));
            Query         query    = new ConstantScoreQuery(filter);
            IndexSearcher searcher = NewSearcher(reader);

            ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test middle of values
            filter = new PrefixFilter(new Term("category", "/Computers/Mac"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(2, hits.Length);

            // test start of values
            filter = new PrefixFilter(new Term("category", "/Computers/Linux"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test end of values
            filter = new PrefixFilter(new Term("category", "/Computers/Windows"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test non-existant
            filter = new PrefixFilter(new Term("category", "/Computers/ObsoleteOS"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, before values
            filter = new PrefixFilter(new Term("category", "/Computers/AAA"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, after values
            filter = new PrefixFilter(new Term("category", "/Computers/ZZZ"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test zero length prefix
            filter = new PrefixFilter(new Term("category", ""));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test non existent field
            filter = new PrefixFilter(new Term("nonexistantfield", "/Computers"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            writer.Dispose();
            reader.Dispose();
            directory.Dispose();
        }
예제 #3
0
			internal AnonymousClassPrefixGenerator(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance, Lucene.Net.Index.Term Param1):base(Param1)
			{
				InitBlock(bitSet, enclosingInstance);
			}
예제 #4
0
 private void  InitBlock(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance)
 {
     this.bitSet            = bitSet;
     this.enclosingInstance = enclosingInstance;
 }
예제 #5
0
		public virtual void  TestPrefixFilter_Renamed_Method()
		{
			RAMDirectory directory = new RAMDirectory();
			
			System.String[] categories = new System.String[]{"/Computers/Linux", "/Computers/Mac/One", "/Computers/Mac/Two", "/Computers/Windows"};
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
			for (int i = 0; i < categories.Length; i++)
			{
				Document doc = new Document();
				doc.Add(new Field("category", categories[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
				writer.AddDocument(doc);
			}
			writer.Close();
			
			// PrefixFilter combined with ConstantScoreQuery
			PrefixFilter filter = new PrefixFilter(new Term("category", "/Computers"));
			Query query = new ConstantScoreQuery(filter);
			IndexSearcher searcher = new IndexSearcher(directory);
			Hits hits = searcher.Search(query);
			Assert.AreEqual(4, hits.Length());
			
			// test middle of values
			filter = new PrefixFilter(new Term("category", "/Computers/Mac"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(2, hits.Length());
			
			// test start of values
			filter = new PrefixFilter(new Term("category", "/Computers/Linux"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(1, hits.Length());
			
			// test end of values
			filter = new PrefixFilter(new Term("category", "/Computers/Windows"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(1, hits.Length());
			
			// test non-existant
			filter = new PrefixFilter(new Term("category", "/Computers/ObsoleteOS"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(0, hits.Length());
			
			// test non-existant, before values
			filter = new PrefixFilter(new Term("category", "/Computers/AAA"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(0, hits.Length());
			
			// test non-existant, after values
			filter = new PrefixFilter(new Term("category", "/Computers/ZZZ"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(0, hits.Length());
			
			// test zero length prefix
			filter = new PrefixFilter(new Term("category", ""));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(4, hits.Length());
			
			// test non existent field
			filter = new PrefixFilter(new Term("nonexistantfield", "/Computers"));
			query = new ConstantScoreQuery(filter);
			hits = searcher.Search(query);
			Assert.AreEqual(0, hits.Length());
		}
예제 #6
0
			private void  InitBlock(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance)
			{
				this.bitSet = bitSet;
				this.enclosingInstance = enclosingInstance;
			}
 /// <summary>
 /// Creates the query.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static Filter CreateQuery(string field, CategoryFilterValue value)
 {
     var query = new BooleanFilter();
     if (!string.IsNullOrEmpty(value.Outline))
     {
         // workaround since there is no wildcard filter in current lucene version
         var outline = value.Outline.TrimEnd('*');
         var nodeQuery = new PrefixFilter(new Term(field, outline.ToLower()));
         query.Add(new FilterClause(nodeQuery, Occur.MUST));
     }
     return query;
 }
예제 #8
0
        public virtual void TestPrefixFilter_Mem()
        {
            Directory directory = NewDirectory();

            string[] categories = new string[] { "/Computers/Linux", "/Computers/Mac/One", "/Computers/Mac/Two", "/Computers/Windows" };
            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, Similarity, TimeZone);
            for (int i = 0; i < categories.Length; i++)
            {
                Document doc = new Document();
                doc.Add(NewStringField("category", categories[i], Field.Store.YES));
                writer.AddDocument(doc);
            }
            IndexReader reader = writer.Reader;

            // PrefixFilter combined with ConstantScoreQuery
            PrefixFilter filter = new PrefixFilter(new Term("category", "/Computers"));
            Query query = new ConstantScoreQuery(filter);
            IndexSearcher searcher = NewSearcher(reader);
            ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test middle of values
            filter = new PrefixFilter(new Term("category", "/Computers/Mac"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(2, hits.Length);

            // test start of values
            filter = new PrefixFilter(new Term("category", "/Computers/Linux"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test end of values
            filter = new PrefixFilter(new Term("category", "/Computers/Windows"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test non-existant
            filter = new PrefixFilter(new Term("category", "/Computers/ObsoleteOS"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, before values
            filter = new PrefixFilter(new Term("category", "/Computers/AAA"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, after values
            filter = new PrefixFilter(new Term("category", "/Computers/ZZZ"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test zero length prefix
            filter = new PrefixFilter(new Term("category", ""));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test non existent field
            filter = new PrefixFilter(new Term("nonexistantfield", "/Computers"));
            query = new ConstantScoreQuery(filter);
            hits = searcher.Search(query, null, 1000).ScoreDocs;
            Assert.AreEqual(0, hits.Length);

            writer.Dispose();
            reader.Dispose();
            directory.Dispose();
        }
예제 #9
0
        //private static Query CreateFilteredByTypeQuery(string reviewableType, string criteria)
        //{
        //    criteria = criteria.Trim();
        //    reviewableType = reviewableType.Trim().ToLower();
        //    //BooleanQuery bq = new BooleanQuery();
        //    //bq.Add(new TermQuery(new Lucene.Net.Index.Term("reviewableType", reviewableType)), Occur.MUST);
        //    //bq.Add(criteria, Occur.MUST);
        //    //return bq;
        //    BooleanQuery mainQuery = new BooleanQuery();
        //    TermQuery contentFilter = new TermQuery(new Term("reviewabletype", reviewableType.Trim()));
        //    mainQuery.Add(contentFilter, Occur.MUST);
        //    WildcardQuery criteriaQ = new WildcardQuery(new Term("content", criteria + "*"));
        //    mainQuery.Add(criteriaQ, Occur.MUST);
        //    //BooleanQuery moduleFilter = new BooleanQuery();
        //    //moduleFilter.MinimumNumberShouldMatch = 1;
        //    //moduleFilter.Add(new TermQuery(new Term("text", criteria)), Occur.SHOULD);
        //    //moduleFilter.Add(new TermQuery(new Term("description1", criteria)), Occur.SHOULD);
        //    //moduleFilter.Add(new TermQuery(new Term("description2", criteria)), Occur.SHOULD);
        //    //mainQuery.Add(moduleFilter, Occur.MUST);
        //    return mainQuery;
        //}
        public static Hashtable searchReviewablesByReviewablesType(string searchText, string reviewableType)
        {
            if (!searchText.Contains(" "))
            {
                searchText = searchText + "*";
            }

            query = multiParser.Parse(searchText);

            Filter f = new PrefixFilter(new Term("reviewabletype",reviewableType));

            FilteredQuery fq = new FilteredQuery(query,f);
            Hashtable results = new Hashtable();
            lock (my_lock)
            {

                //Lucene.Net.Search.TopDocs hits = null;
                Lucene.Net.Search.TopDocs hits = null;
                try
                {
                    if (searcher == null)
                    {
                        Lucene.Net.Store.FSDirectory d = Lucene.Net.Store.FSDirectory.Open(_indexPath);
                        searcher = new Lucene.Net.Search.IndexSearcher(d);
                    }

                    hits = searcher.Search(fq, 200);

                }
                catch (Exception e)
                {

                }

                for (int i = 0; i <= hits.ScoreDocs.Count() - 1; i++)
                {
                    Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                    string id = doc.GetField("reviewableid").StringValue;

                    //double score = hits[i]
                    if (!results.Contains(id))
                        results.Add(id, hits.ScoreDocs[i].Score);

                    float x = hits.MaxScore;

                }
            }
            return results;
        }
예제 #10
0
 public virtual void TestEmpty3()
 {
     Filter expected = new PrefixFilter(new Term("bogusField", "bogusVal"));
     Filter actual = new CachingWrapperFilter(expected);
     AssertFilterEquals(expected, actual);
 }
예제 #11
0
        public virtual void  TestPrefixFilter_Renamed()
        {
            RAMDirectory directory = new RAMDirectory();

            System.String[] categories = new System.String[] { "/Computers/Linux", "/Computers/Mac/One", "/Computers/Mac/Two", "/Computers/Windows" };
            IndexWriter     writer     = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            for (int i = 0; i < categories.Length; i++)
            {
                Document doc = new Document();
                doc.Add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
                writer.AddDocument(doc);
            }
            writer.Close();

            // PrefixFilter combined with ConstantScoreQuery
            PrefixFilter  filter   = new PrefixFilter(new Term("category", "/Computers"));
            Query         query    = new ConstantScoreQuery(filter);
            IndexSearcher searcher = new IndexSearcher(directory);

            ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test middle of values
            filter = new PrefixFilter(new Term("category", "/Computers/Mac"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(2, hits.Length);

            // test start of values
            filter = new PrefixFilter(new Term("category", "/Computers/Linux"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test end of values
            filter = new PrefixFilter(new Term("category", "/Computers/Windows"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(1, hits.Length);

            // test non-existant
            filter = new PrefixFilter(new Term("category", "/Computers/ObsoleteOS"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, before values
            filter = new PrefixFilter(new Term("category", "/Computers/AAA"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test non-existant, after values
            filter = new PrefixFilter(new Term("category", "/Computers/ZZZ"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(0, hits.Length);

            // test zero length prefix
            filter = new PrefixFilter(new Term("category", ""));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(4, hits.Length);

            // test non existent field
            filter = new PrefixFilter(new Term("nonexistantfield", "/Computers"));
            query  = new ConstantScoreQuery(filter);
            hits   = searcher.Search(query, null, 1000).scoreDocs;
            Assert.AreEqual(0, hits.Length);
        }
예제 #12
0
 private void InitBlock(OpenBitSet bitSet, PrefixFilter enclosingInstance)
 {
     this.bitSet = bitSet;
     this.enclosingInstance = enclosingInstance;
 }
예제 #13
0
 internal AnonymousClassPrefixGenerator2(OpenBitSet bitSet, PrefixFilter enclosingInstance, Lucene.Net.Index.Term Param1)
     : base(Param1)
 {
     InitBlock(bitSet, enclosingInstance);
 }
예제 #14
0
 internal AnonymousClassPrefixGenerator2(OpenBitSet bitSet, PrefixFilter enclosingInstance, Lucene.Net.Index.Term Param1)
     : base(Param1)
 {
     InitBlock(bitSet, enclosingInstance);
 }
예제 #15
0
 private void InitBlock(OpenBitSet bitSet, PrefixFilter enclosingInstance)
 {
     this.bitSet            = bitSet;
     this.enclosingInstance = enclosingInstance;
 }