public override System.Collections.BitArray Bits(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            if (cache == null)
            {
                cache = new System.Collections.Hashtable();
            }

            lock (cache.SyncRoot)
            {
                // check cache
                System.Collections.BitArray cached = (System.Collections.BitArray)cache[reader];
                if (cached != null)
                {
                    return(cached);
                }
            }

            System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);

            new IndexSearcher(reader).Search(query, new AnonymousClassHitCollector(bits, this));

            lock (cache.SyncRoot)
            {
                // update cache
                cache[reader] = bits;
            }

            return(bits);
        }
Exemple #2
0
        public override System.Collections.BitArray Bits(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            if (cache == null)
            {
                cache = new System.Collections.Hashtable();
            }

            lock (cache.SyncRoot)
            {
                // check cache
                System.Collections.BitArray cached = (System.Collections.BitArray)cache[reader];
                if (cached != null)
                {
                    return(cached);
                }
            }

            System.Collections.BitArray bits = filter.Bits(reader);

            lock (cache.SyncRoot)
            {
                // update cache
                cache[reader] = bits;
            }

            return(bits);
        }
Exemple #3
0
            // return a scorer that overrides the enclosed query's score if
            // the given hit has been filtered out.
            public virtual Scorer Scorer(Monodoc.Lucene.Net.Index.IndexReader indexReader)
            {
                Scorer scorer = weight.Scorer(indexReader);

                System.Collections.BitArray bitset = Enclosing_Instance.filter.Bits(indexReader);
                return(new AnonymousClassScorer(scorer, bitset, this, Enclosing_Instance.query.GetSimilarity(searcher)));
            }
Exemple #4
0
        /// <summary>The pattern used to detect integer values in a Field </summary>
        /// <summary>removed for java 1.3 compatibility
        /// protected static final Pattern pIntegers = Pattern.compile ("[0-9\\-]+");
        ///
        /// </summary>

        /// <summary>The pattern used to detect float values in a Field </summary>
        /// <summary> removed for java 1.3 compatibility
        /// protected static final Object pFloats = Pattern.compile ("[0-9+\\-\\.eEfFdD]+");
        /// </summary>

        // inherit javadocs
        public virtual System.Object GetAuto(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
        {
            field = String.Intern(field);
            System.Object ret = Lookup(reader, field, SortField.AUTO);
            if (ret == null)
            {
                TermEnum enumerator = reader.Terms(new Term(field, ""));
                try
                {
                    Term term = enumerator.Term();
                    if (term == null)
                    {
                        throw new System.SystemException("no terms in Field " + field + " - cannot determine sort type");
                    }
                    if ((System.Object)term.Field() == (System.Object)field)
                    {
                        System.String termtext = term.Text().Trim();

                        /// <summary> Java 1.4 level code:
                        /// if (pIntegers.matcher(termtext).matches())
                        /// return IntegerSortedHitQueue.comparator (reader, enumerator, Field);
                        /// else if (pFloats.matcher(termtext).matches())
                        /// return FloatSortedHitQueue.comparator (reader, enumerator, Field);
                        /// </summary>

                        // Java 1.3 level code:
                        try
                        {
                            System.Int32.Parse(termtext);
                            ret = GetInts(reader, field);
                        }
                        catch (System.FormatException nfe1)
                        {
                            try
                            {
                                System.Single.Parse(termtext);
                                ret = GetFloats(reader, field);
                            }
                            catch (System.FormatException nfe2)
                            {
                                ret = GetStringIndex(reader, field);
                            }
                        }
                        if (ret != null)
                        {
                            Store(reader, field, SortField.AUTO, ret);
                        }
                    }
                    else
                    {
                        throw new System.SystemException("Field \"" + field + "\" does not appear to be indexed");
                    }
                }
                finally
                {
                    enumerator.Close();
                }
            }
            return(ret);
        }
Exemple #5
0
 /// <summary> Returns a comparator for sorting hits according to a Field containing strings.</summary>
 /// <param name="reader"> Index to use.
 /// </param>
 /// <param name="fieldname"> Field containg string values.
 /// </param>
 /// <returns>  Comparator for sorting hits.
 /// </returns>
 /// <throws>  IOException If an error occurs reading the index. </throws>
 internal static ScoreDocComparator ComparatorStringLocale(Monodoc.Lucene.Net.Index.IndexReader reader, System.String fieldname, System.Globalization.CultureInfo locale)
 {
     System.Globalization.CompareInfo collator = locale.CompareInfo;
     System.String   field = String.Intern(fieldname);
     System.String[] index = Monodoc.Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStrings(reader, field);
     return(new AnonymousClassScoreDocComparator3(collator, index));
 }
Exemple #6
0
            public virtual Scorer Scorer(Monodoc.Lucene.Net.Index.IndexReader reader)
            {
                if (Enclosing_Instance.terms.Count == 0)
                {
                    // optimize zero-term case
                    return(null);
                }

                TermPositions[] tps = new TermPositions[Enclosing_Instance.terms.Count];
                for (int i = 0; i < Enclosing_Instance.terms.Count; i++)
                {
                    TermPositions p = reader.TermPositions((Term)Enclosing_Instance.terms[i]);
                    if (p == null)
                    {
                        return(null);
                    }
                    tps[i] = p;
                }

                if (Enclosing_Instance.slop == 0)
                {
                    // optimize exact case
                    return(new ExactPhraseScorer(this, tps, Enclosing_Instance.GetPositions(), Enclosing_Instance.GetSimilarity(searcher), reader.Norms(Enclosing_Instance.field)));
                }
                else
                {
                    return(new SloppyPhraseScorer(this, tps, Enclosing_Instance.GetPositions(), Enclosing_Instance.GetSimilarity(searcher), Enclosing_Instance.slop, reader.Norms(Enclosing_Instance.field)));
                }
            }
Exemple #7
0
 /// <summary> Returns a comparator for sorting hits according to values in the given Field.
 /// The terms in the Field are looked at to determine whether they contain integers,
 /// floats or strings.  Once the type is determined, one of the other static methods
 /// in this class is called to get the comparator.
 /// </summary>
 /// <param name="reader"> Index to use.
 /// </param>
 /// <param name="fieldname"> Field containg values.
 /// </param>
 /// <returns>  Comparator for sorting hits.
 /// </returns>
 /// <throws>  IOException If an error occurs reading the index. </throws>
 internal static ScoreDocComparator ComparatorAuto(Monodoc.Lucene.Net.Index.IndexReader reader, System.String fieldname)
 {
     System.String field       = String.Intern(fieldname);
     System.Object lookupArray = Monodoc.Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetAuto(reader, field);
     if (lookupArray is Monodoc.Lucene.Net.Search.StringIndex)
     {
         return(ComparatorString(reader, field));
     }
     else if (lookupArray is int[])
     {
         return(ComparatorInt(reader, field));
     }
     else if (lookupArray is float[])
     {
         return(ComparatorFloat(reader, field));
     }
     else if (lookupArray is System.String[])
     {
         return(ComparatorString(reader, field));
     }
     else
     {
         throw new System.SystemException("unknown data type in Field '" + field + "'");
     }
 }
Exemple #8
0
        /// <summary> Returns a BitSet with true for documents which should be
        /// permitted in search results, and false for those that should
        /// not.
        /// </summary>
        public override System.Collections.BitArray Bits(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
            TermEnum enumerator = reader.Terms(new Term(field, start));
            TermDocs termDocs   = reader.TermDocs();

            if (enumerator.Term() == null)
            {
                return(bits);
            }

            try
            {
                Term stop = new Term(field, end);
                while (enumerator.Term().CompareTo(stop) <= 0)
                {
                    termDocs.Seek(enumerator.Term());
                    while (termDocs.Next())
                    {
                        bits.Set(termDocs.Doc(), true);
                    }
                    if (!enumerator.Next())
                    {
                        break;
                    }
                }
            }
            finally
            {
                enumerator.Close();
                termDocs.Close();
            }
            return(bits);
        }
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            BooleanQuery query      = new BooleanQuery();
            TermEnum     enumerator = reader.Terms(prefix);

            try
            {
                System.String prefixText  = prefix.Text();
                System.String prefixField = prefix.Field();
                do
                {
                    Term term = enumerator.Term();
                    if (term != null && term.Text().StartsWith(prefixText) && (System.Object)term.Field() == (System.Object)prefixField)
                    {
                        TermQuery tq = new TermQuery(term); // found a match
                        tq.SetBoost(GetBoost());            // set the boost
                        query.Add(tq, false, false);        // add to query
                        //System.out.println("added " + term);
                    }
                    else
                    {
                        break;
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
Exemple #10
0
 private void  InitBlock(Monodoc.Lucene.Net.Index.IndexReader reader, SpanNotQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
     includeSpans           = Enclosing_Instance.include.GetSpans(reader);
     excludeSpans           = Enclosing_Instance.exclude.GetSpans(reader);
 }
Exemple #11
0
        public override Spans GetSpans(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            if (clauses.Count == 1)
            {
                // optimize 1-clause case
                return(((SpanQuery)clauses[0]).GetSpans(reader));
            }

            return(new AnonymousClassSpans(reader, this));
        }
Exemple #12
0
            public virtual Scorer Scorer(Monodoc.Lucene.Net.Index.IndexReader reader)
            {
                TermDocs termDocs = reader.TermDocs(Enclosing_Instance.term);

                if (termDocs == null)
                {
                    return(null);
                }

                return(new TermScorer(this, termDocs, Enclosing_Instance.GetSimilarity(searcher), reader.Norms(Enclosing_Instance.term.Field())));
            }
        public override Spans GetSpans(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            if (clauses.Count == 0)
            // optimize 0-clause case
            return new SpanOrQuery(GetClauses()).GetSpans(reader);

            if (clauses.Count == 1)
            // optimize 1-clause case
            return ((SpanQuery) clauses[0]).GetSpans(reader);

            return new NearSpans(this, reader);
        }
Exemple #14
0
        /// <summary> FIXME: Describe <code>rewrite</code> method here.
        ///
        /// </summary>
        /// <param name="reader">an <code>Monodoc.Lucene.Net.Index.IndexReader</code> value
        /// </param>
        /// <returns> a <code>Query</code> value
        /// </returns>
        /// <exception cref=""> IOException if an error occurs
        /// </exception>
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            BooleanQuery query      = new BooleanQuery();
            TermEnum     enumerator = reader.Terms(lowerTerm);

            try
            {
                bool checkLower = false;
                if (!inclusive)
                {
                    // make adjustments to set to exclusive
                    checkLower = true;
                }

                System.String testField = GetField();

                do
                {
                    Term term = enumerator.Term();
                    if (term != null && (System.Object)term.Field() == (System.Object)testField)
                    {
                        if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
                        {
                            checkLower = false;
                            if (upperTerm != null)
                            {
                                int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());

                                /* if beyond the upper term, or is exclusive and
                                 * this is equal to the upper term, break out */
                                if ((compare < 0) || (!inclusive && compare == 0))
                                {
                                    break;
                                }
                            }
                            TermQuery tq = new TermQuery(term); // found a match
                            tq.SetBoost(GetBoost());            // set the boost
                            query.Add(tq, false, false);        // add to query
                        }
                    }
                    else
                    {
                        break;
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            if (clauses.Count == 1)
            {
                // optimize 1-clause queries
                BooleanClause c = (BooleanClause)clauses[0];
                if (!c.prohibited)
                {
                    // just return clause

                    Query query = c.query.Rewrite(reader); // rewrite first

                    if (GetBoost() != 1.0f)
                    {
                        // incorporate boost
                        if (query == c.query)
                        {
                            // if rewrite was no-op
                            query = (Query)query.Clone(); // then clone before boost
                        }
                        query.SetBoost(GetBoost() * query.GetBoost());
                    }

                    return(query);
                }
            }

            BooleanQuery clone = null; // recursively rewrite

            for (int i = 0; i < clauses.Count; i++)
            {
                BooleanClause c     = (BooleanClause)clauses[i];
                Query         query = c.query.Rewrite(reader);
                if (query != c.query)
                {
                    // clause rewrote: must clone
                    if (clone == null)
                    {
                        clone = (BooleanQuery)this.Clone();
                    }
                    clone.clauses[i] = new BooleanClause(query, c.required, c.prohibited);
                }
            }
            if (clone != null)
            {
                return(clone); // some clauses rewrote
            }
            else
            {
                return(this); // no clauses rewrote
            }
        }
Exemple #16
0
 private void  InitBlock(Monodoc.Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
     all   = new System.Collections.ArrayList(Enclosing_Instance.clauses.Count);
     queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
     System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
     while (i.MoveNext())
     {
         // initialize all
         all.Add(((SpanQuery)i.Current).GetSpans(reader));
     }
 }
Exemple #17
0
 /// <summary>Returns a comparator if it is in the cache. </summary>
 internal static ScoreDocComparator Lookup(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, int type, System.Object factory)
 {
     FieldCacheImpl.Entry entry = (factory != null) ? new FieldCacheImpl.Entry(field, factory) : new FieldCacheImpl.Entry(field, type);
     lock (Comparators.SyncRoot)
     {
         System.Collections.Hashtable readerCache = (System.Collections.Hashtable)Comparators[reader];
         if (readerCache == null)
         {
             return(null);
         }
         return((ScoreDocComparator)readerCache[entry]);
     }
 }
Exemple #18
0
 // inherit javadocs
 public virtual float[] GetFloats(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, SortField.FLOAT);
     if (ret == null)
     {
         float[] retArray = new float[reader.MaxDoc()];
         if (retArray.Length > 0)
         {
             TermDocs termDocs = reader.TermDocs();
             TermEnum termEnum = reader.Terms(new Term(field, ""));
             try
             {
                 if (termEnum.Term() == null)
                 {
                     throw new System.SystemException("no terms in Field " + field);
                 }
                 do
                 {
                     Term term = termEnum.Term();
                     if ((System.Object)term.Field() != (System.Object)field)
                     {
                         break;
                     }
                     float termval;
                     try
                     {
                         termval = SupportClass.Single.Parse(term.Text());
                     }
                     catch (Exception e)
                     {
                         termval = 0;
                     }
                     termDocs.Seek(termEnum);
                     while (termDocs.Next())
                     {
                         retArray[termDocs.Doc()] = termval;
                     }
                 }while (termEnum.Next());
             }
             finally
             {
                 termDocs.Close();
                 termEnum.Close();
             }
         }
         Store(reader, field, SortField.FLOAT, retArray);
         return(retArray);
     }
     return((float[])ret);
 }
        public NearSpans(SpanNearQuery query, Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            this.query   = query;
            this.slop    = query.GetSlop();
            this.inOrder = query.IsInOrder();

            SpanQuery[] clauses = query.GetClauses(); // initialize spans & list
            queue = new CellQueue(this, clauses.Length);
            for (int i = 0; i < clauses.Length; i++)
            {
                SpansCell cell = new SpansCell(this, clauses[i].GetSpans(reader), i);
                ordered.Add(cell); // add to ordered
            }
        }
Exemple #20
0
        internal static ScoreDocComparator GetCachedComparator(Monodoc.Lucene.Net.Index.IndexReader reader, System.String fieldname, int type, System.Globalization.CultureInfo locale, SortComparatorSource factory)
        {
            if (type == SortField.DOC)
            {
                return(Monodoc.Lucene.Net.Search.ScoreDocComparator_Fields.INDEXORDER);
            }
            if (type == SortField.SCORE)
            {
                return(Monodoc.Lucene.Net.Search.ScoreDocComparator_Fields.RELEVANCE);
            }
            ScoreDocComparator comparator = Lookup(reader, fieldname, type, factory);

            if (comparator == null)
            {
                switch (type)
                {
                case SortField.AUTO:
                    comparator = ComparatorAuto(reader, fieldname);
                    break;

                case SortField.INT:
                    comparator = ComparatorInt(reader, fieldname);
                    break;

                case SortField.FLOAT:
                    comparator = ComparatorFloat(reader, fieldname);
                    break;

                case SortField.STRING:
                    if (locale != null)
                    {
                        comparator = ComparatorStringLocale(reader, fieldname, locale);
                    }
                    else
                    {
                        comparator = ComparatorString(reader, fieldname);
                    }
                    break;

                case SortField.CUSTOM:
                    comparator = factory.NewComparator(reader, fieldname);
                    break;

                default:
                    throw new System.SystemException("unknown Field type: " + type);
                }
                Store(reader, fieldname, type, factory, comparator);
            }
            return(comparator);
        }
Exemple #21
0
        /// <summary> Creates a hit queue sorted by the given list of fields.</summary>
        /// <param name="reader"> Index to use.
        /// </param>
        /// <param name="fields">Field names, in priority order (highest priority first).  Cannot be <code>null</code> or empty.
        /// </param>
        /// <param name="size"> The number of hits to retain.  Must be greater than zero.
        /// </param>
        /// <throws>  IOException </throws>
        internal FieldSortedHitQueue(Monodoc.Lucene.Net.Index.IndexReader reader, SortField[] fields, int size)
        {
            int n = fields.Length;

            comparators = new ScoreDocComparator[n];
            this.fields = new SortField[n];
            for (int i = 0; i < n; ++i)
            {
                System.String fieldname = fields[i].GetField();
                comparators[i] = GetCachedComparator(reader, fieldname, fields[i].GetType(), fields[i].GetLocale(), fields[i].GetFactory());
                this.fields[i] = new SortField(fieldname, comparators[i].SortType(), fields[i].GetReverse());
            }
            Initialize(size);
        }
Exemple #22
0
        /// <summary>See if an object is in the cache. </summary>
        internal virtual System.Object Lookup(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, int type)
        {
            Entry entry = new Entry(field, type);

            lock (this)
            {
                System.Collections.Hashtable readerCache = (System.Collections.Hashtable)cache[reader];
                if (readerCache == null)
                {
                    return(null);
                }
                return(readerCache[entry]);
            }
        }
Exemple #23
0
        /// <summary>Rewrites the wrapped query. </summary>
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            Query rewritten = query.Rewrite(reader);

            if (rewritten != query)
            {
                FilteredQuery clone = (FilteredQuery)this.Clone();
                clone.query = rewritten;
                return(clone);
            }
            else
            {
                return(this);
            }
        }
Exemple #24
0
 /// <summary>Stores a comparator into the cache. </summary>
 internal static System.Object Store(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, int type, System.Object factory, System.Object value_Renamed)
 {
     FieldCacheImpl.Entry entry = (factory != null) ? new FieldCacheImpl.Entry(field, factory) : new FieldCacheImpl.Entry(field, type);
     lock (Comparators.SyncRoot)
     {
         System.Collections.Hashtable readerCache = (System.Collections.Hashtable)Comparators[reader];
         if (readerCache == null)
         {
             readerCache         = new System.Collections.Hashtable();
             Comparators[reader] = readerCache;
         }
         System.Object tempObject;
         tempObject         = readerCache[entry];
         readerCache[entry] = value_Renamed;
         return(tempObject);
     }
 }
Exemple #25
0
 /// <summary> Constructor for enumeration of all terms from specified <code>reader</code> which share a prefix of
 /// length <code>prefixLength</code> with <code>term</code> and which have a fuzzy similarity &gt;
 /// <code>minSimilarity</code>.
 ///
 /// </summary>
 /// <param name="reader">Delivers terms.
 /// </param>
 /// <param name="term">Pattern term.
 /// </param>
 /// <param name="minSimilarity">Minimum required similarity for terms from the reader. Default value is 0.5f.
 /// </param>
 /// <param name="prefixLength">Length of required common prefix. Default value is 0.
 /// </param>
 /// <throws>  IOException </throws>
 public FuzzyTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term, float minSimilarity, int prefixLength) : base()
 {
     InitBlock();
     minimumSimilarity = minSimilarity;
     scale_factor      = 1.0f / (1.0f - minimumSimilarity);
     searchTerm        = term;
     field             = searchTerm.Field();
     text    = searchTerm.Text();
     textlen = text.Length;
     if (prefixLength > 0 && prefixLength < textlen)
     {
         this.prefixLength = prefixLength;
         prefix            = text.Substring(0, (prefixLength) - (0));
         text    = text.Substring(prefixLength);
         textlen = text.Length;
     }
     SetEnum(reader.Terms(new Term(searchTerm.Field(), prefix)));
 }
Exemple #26
0
        /// <summary>Put a custom object into the cache. </summary>
        internal virtual System.Object Store(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, System.Object comparer, System.Object value_Renamed)
        {
            Entry entry = new Entry(field, comparer);

            lock (this)
            {
                System.Collections.Hashtable readerCache = (System.Collections.Hashtable)cache[reader];
                if (readerCache == null)
                {
                    readerCache   = new System.Collections.Hashtable();
                    cache[reader] = readerCache;
                }
                System.Object tempObject;
                tempObject         = readerCache[entry];
                readerCache[entry] = value_Renamed;
                return(tempObject);
            }
        }
Exemple #27
0
 // inherit javadocs
 public virtual System.IComparable[] GetCustom(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, SortComparator comparator)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, comparator);
     if (ret == null)
     {
         System.IComparable[] retArray = new System.IComparable[reader.MaxDoc()];
         if (retArray.Length > 0)
         {
             TermDocs termDocs = reader.TermDocs();
             TermEnum termEnum = reader.Terms(new Term(field, ""));
             try
             {
                 if (termEnum.Term() == null)
                 {
                     throw new System.SystemException("no terms in Field " + field);
                 }
                 do
                 {
                     Term term = termEnum.Term();
                     if ((System.Object)term.Field() != (System.Object)field)
                     {
                         break;
                     }
                     System.IComparable termval = comparator.GetComparable(term.Text());
                     termDocs.Seek(termEnum);
                     while (termDocs.Next())
                     {
                         retArray[termDocs.Doc()] = termval;
                     }
                 }while (termEnum.Next());
             }
             finally
             {
                 termDocs.Close();
                 termEnum.Close();
             }
         }
         Store(reader, field, SortField.CUSTOM, retArray);
         return(retArray);
     }
     return((System.IComparable[])ret);
 }
            public virtual Scorer Scorer(Monodoc.Lucene.Net.Index.IndexReader reader)
            {
                if (Enclosing_Instance.termArrays.Count == 0)
                {
                    // optimize zero-term case
                    return(null);
                }

                TermPositions[] tps = new TermPositions[Enclosing_Instance.termArrays.Count];
                for (int i = 0; i < tps.Length; i++)
                {
                    Term[] terms = (Term[])Enclosing_Instance.termArrays[i];

                    TermPositions p;
                    if (terms.Length > 1)
                    {
                        p = new MultipleTermPositions(reader, terms);
                    }
                    else
                    {
                        p = reader.TermPositions(terms[0]);
                    }

                    if (p == null)
                    {
                        return(null);
                    }

                    tps[i] = p;
                }

                if (Enclosing_Instance.slop == 0)
                {
                    return(new ExactPhraseScorer(this, tps, Enclosing_Instance.GetPositions(), Enclosing_Instance.GetSimilarity(searcher), reader.Norms(Enclosing_Instance.field)));
                }
                else
                {
                    return(new SloppyPhraseScorer(this, tps, Enclosing_Instance.GetPositions(), Enclosing_Instance.GetSimilarity(searcher), Enclosing_Instance.slop, reader.Norms(Enclosing_Instance.field)));
                }
            }
Exemple #29
0
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            FilteredTermEnum enumerator = GetEnum(reader);
            BooleanQuery     query      = new BooleanQuery();

            try
            {
                do
                {
                    Term t = enumerator.Term();
                    if (t != null)
                    {
                        TermQuery tq = new TermQuery(t);                   // found a match
                        tq.SetBoost(GetBoost() * enumerator.Difference()); // set the boost
                        query.Add(tq, false, false);                       // add to query
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
Exemple #30
0
        /// <summary> Creates a new <code>WildcardTermEnum</code>.  Passing in a
        /// {@link Monodoc.Lucene.Net.Index.Term Term} that does not contain a
        /// <code>WILDCARD_CHAR</code> will cause an exception to be thrown.
        /// </summary>
        public WildcardTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term) : base()
        {
            searchTerm = term;
            field      = searchTerm.Field();
            text       = searchTerm.Text();

            int sidx = text.IndexOf((System.Char)WILDCARD_STRING);
            int cidx = text.IndexOf((System.Char)WILDCARD_CHAR);
            int idx  = sidx;

            if (idx == -1)
            {
                idx = cidx;
            }
            else if (cidx >= 0)
            {
                idx = System.Math.Min(idx, cidx);
            }

            pre    = searchTerm.Text().Substring(0, (idx) - (0));
            preLen = pre.Length;
            text   = text.Substring(preLen);
            SetEnum(reader.Terms(new Term(searchTerm.Field(), pre)));
        }
		private IndexSearcher(Monodoc.Lucene.Net.Index.IndexReader r, bool closeReader)
		{
			reader = r;
			this.closeReader = closeReader;
		}