Пример #1
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);
        }
 /// <summary>Increments the enumeration to the next element.  True if one exists. </summary>
 public override bool Next()
 {
     if (actualEnum == null)
     {
         return(false); // the actual enumerator is not initialized!
     }
     currentTerm = null;
     while (currentTerm == null)
     {
         if (EndEnum())
         {
             return(false);
         }
         if (actualEnum.Next())
         {
             Term term = actualEnum.Term();
             if (TermCompare(term))
             {
                 currentTerm = term;
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     currentTerm = null;
     return(false);
 }
Пример #3
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);
        }
Пример #5
0
 public override void  Close()
 {
     base.Close();
     searchTerm = null;
     field      = null;
     text       = null;
 }
Пример #6
0
		/// <summary>Compares two terms, returning an integer which is less than zero iff this
		/// term belongs after the argument, equal zero iff this term is equal to the
		/// argument, and greater than zero iff this term belongs after the argument.
		/// The ordering of terms is first by Field, then by text.
		/// </summary>
		public int CompareTo(Term other)
		{
			if ((System.Object) field == (System.Object) other.field)
			// fields are interned
				return String.CompareOrdinal(text, other.text);
			else
				return String.CompareOrdinal(field, other.field);
		}
        /// <summary>Add multiple terms at the next position in the phrase.  Any of the terms
        /// may match.
        /// 
        /// </summary>
        /// <seealso cref="PhraseQuery#Add(Term)">
        /// </seealso>
		public virtual void  Add(Term[] terms)
		{
			int position = 0;
			if (positions.Count > 0)
				position = ((System.Int32) positions[positions.Count - 1]) + 1;
			
			Add(terms, position);
		}
Пример #8
0
		// Term Vector support
		
		/// <summary>Skips terms to the first beyond the current whose value is
		/// greater or equal to <i>target</i>. <p>Returns true iff there is such
		/// an entry.  <p>Behaves as if written: <pre>
		/// public boolean skipTo(Term target) {
		/// do {
		/// if (!next())
		/// return false;
		/// } while (target > term());
		/// return true;
		/// }
		/// </pre>
		/// Some implementations are considerably more efficient than that.
		/// </summary>
		public virtual bool SkipTo(Term target)
		{
			do 
			{
				if (!Next())
					return false;
			}
			while (target.CompareTo(Term()) > 0);
			return true;
		}
Пример #9
0
		protected internal virtual void  SetEnum(TermEnum actualEnum)
		{
			this.actualEnum = actualEnum;
			// Find the first term that matches
			Term term = actualEnum.Term();
			if (term != null && TermCompare(term))
				currentTerm = term;
			else
				Next();
		}
Пример #10
0
        /// <summary> Adds a term to the end of the query phrase.
        /// The relative position of the term is the one immediately after the last term added.
        /// </summary>
        public virtual void  Add(Term term)
        {
            int position = 0;

            if (positions.Count > 0)
            {
                position = ((System.Int32)positions[positions.Count - 1]) + 1;
            }

            Add(term, position);
        }
Пример #11
0
        /// <summary> Adds a term to the end of the query phrase.
        /// The relative position of the term within the phrase is specified explicitly.
        /// This allows e.g. phrases with more than one term at the same position
        /// or phrases with gaps (e.g. in connection with stopwords).
        /// 
        /// </summary>
        /// <param name="">term
        /// </param>
        /// <param name="">position
        /// </param>
        public virtual void  Add(Term term, int position)
        {
            if (terms.Count == 0)
                field = term.Field();
            else if ((System.Object) term.Field() != (System.Object) field)
            {
                throw new System.ArgumentException("All phrase terms must be in the same field: " + term);
            }
			
            terms.Add(term);
            positions.Add((System.Int32) position);
        }
Пример #12
0
 protected internal override Weight CreateWeight(Searcher searcher)
 {
     if (terms.Count == 1)
     {
         // optimize one-term case
         Term  term      = (Term)terms[0];
         Query termQuery = new TermQuery(term);
         termQuery.SetBoost(GetBoost());
         return(termQuery.CreateWeight(searcher));
     }
     return(new PhraseWeight(this, searcher));
 }
Пример #13
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);
        }
		protected internal override bool TermCompare(Term term)
		{
			if ((System.Object) field == (System.Object) term.Field())
			{
				System.String searchText = term.Text();
				if (searchText.StartsWith(pre))
				{
					return WildcardEquals(text, 0, searchText, preLen);
				}
			}
			endEnum = true;
			return false;
		}
Пример #15
0
		internal bool Next()
		{
			if (termEnum.Next())
			{
				term = termEnum.Term();
				return true;
			}
			else
			{
				term = null;
				return false;
			}
		}
Пример #16
0
 protected internal override bool TermCompare(Term term)
 {
     if ((System.Object)field == (System.Object)term.Field())
     {
         System.String searchText = term.Text();
         if (searchText.StartsWith(pre))
         {
             return(WildcardEquals(text, 0, searchText, preLen));
         }
     }
     endEnum = true;
     return(false);
 }
Пример #17
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);
 }
Пример #18
0
 /// <summary>The termCompare method in FuzzyTermEnum uses Levenshtein distance to
 /// calculate the distance between the given term and the comparing term.
 /// </summary>
 protected internal override bool TermCompare(Term term)
 {
     System.String termText = term.Text();
     if ((System.Object)field == (System.Object)term.Field() && termText.StartsWith(prefix))
     {
         System.String target    = termText.Substring(prefixLength);
         int           targetlen = target.Length;
         int           dist      = EditDistance(text, target, textlen, targetlen);
         distance = 1 - ((double)dist / (double)System.Math.Min(textlen, targetlen));
         return(distance > minimumSimilarity);
     }
     endEnum = true;
     return(false);
 }
Пример #19
0
        /// <summary> Adds a term to the end of the query phrase.
        /// The relative position of the term within the phrase is specified explicitly.
        /// This allows e.g. phrases with more than one term at the same position
        /// or phrases with gaps (e.g. in connection with stopwords).
        ///
        /// </summary>
        /// <param name="">term
        /// </param>
        /// <param name="">position
        /// </param>
        public virtual void  Add(Term term, int position)
        {
            if (terms.Count == 0)
            {
                field = term.Field();
            }
            else if ((System.Object)term.Field() != (System.Object)field)
            {
                throw new System.ArgumentException("All phrase terms must be in the same field: " + term);
            }

            terms.Add(term);
            positions.Add((System.Int32)position);
        }
        protected internal virtual void  SetEnum(TermEnum actualEnum)
        {
            this.actualEnum = actualEnum;
            // Find the first term that matches
            Term term = actualEnum.Term();

            if (term != null && TermCompare(term))
            {
                currentTerm = term;
            }
            else
            {
                Next();
            }
        }
Пример #21
0
        /// <summary> Create a new FuzzyQuery that will match terms with a similarity 
        /// of at least <code>minimumSimilarity</code> to <code>term</code>.
        /// If a <code>prefixLength</code> &gt; 0 is specified, a common prefix
        /// of that length is also required.
        /// 
        /// </summary>
        /// <param name="term">the term to search for
        /// </param>
        /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity
        /// between the query term and the matching terms. For example, for a
        /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length
        /// as the query term is considered similar to the query term if the edit distance
        /// between both terms is less than <code>length(term)*0.5</code>
        /// </param>
        /// <param name="prefixLength">length of common (non-fuzzy) prefix
        /// </param>
        /// <throws>  IllegalArgumentException if minimumSimilarity is &gt; 1 or &lt; 0 </throws>
        /// <summary> or if prefixLength &lt; 0 or &gt; <code>term.text().length()</code>.
        /// </summary>
        public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength):base(term)
        {
			
            if (minimumSimilarity > 1.0f)
                throw new System.ArgumentException("minimumSimilarity > 1");
            else if (minimumSimilarity < 0.0f)
                throw new System.ArgumentException("minimumSimilarity < 0");
            this.minimumSimilarity = minimumSimilarity;
			
            if (prefixLength < 0)
                throw new System.ArgumentException("prefixLength < 0");
            else if (prefixLength >= term.Text().Length)
                throw new System.ArgumentException("prefixLength >= term.text().length()");
            this.prefixLength = prefixLength;
        }
Пример #22
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)));
 }
Пример #23
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);
 }
Пример #24
0
        /// <summary> Create a new FuzzyQuery that will match terms with a similarity
        /// of at least <code>minimumSimilarity</code> to <code>term</code>.
        /// If a <code>prefixLength</code> &gt; 0 is specified, a common prefix
        /// of that length is also required.
        ///
        /// </summary>
        /// <param name="term">the term to search for
        /// </param>
        /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity
        /// between the query term and the matching terms. For example, for a
        /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length
        /// as the query term is considered similar to the query term if the edit distance
        /// between both terms is less than <code>length(term)*0.5</code>
        /// </param>
        /// <param name="prefixLength">length of common (non-fuzzy) prefix
        /// </param>
        /// <throws>  IllegalArgumentException if minimumSimilarity is &gt; 1 or &lt; 0 </throws>
        /// <summary> or if prefixLength &lt; 0 or &gt; <code>term.text().length()</code>.
        /// </summary>
        public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) : base(term)
        {
            if (minimumSimilarity > 1.0f)
            {
                throw new System.ArgumentException("minimumSimilarity > 1");
            }
            else if (minimumSimilarity < 0.0f)
            {
                throw new System.ArgumentException("minimumSimilarity < 0");
            }
            this.minimumSimilarity = minimumSimilarity;

            if (prefixLength < 0)
            {
                throw new System.ArgumentException("prefixLength < 0");
            }
            else if (prefixLength >= term.Text().Length)
            {
                throw new System.ArgumentException("prefixLength >= term.text().length()");
            }
            this.prefixLength = prefixLength;
        }
Пример #25
0
		internal int[] docMap = null; // maps around deleted docs
		
		internal SegmentMergeInfo(int b, TermEnum te, Monodoc.Lucene.Net.Index.IndexReader r)
		{
			base_Renamed = b;
			reader = r;
			termEnum = te;
			term = te.Term();
			postings = reader.TermPositions();
			
			// build array which maps document numbers around deletions 
			if (reader.HasDeletions())
			{
				int maxDoc = reader.MaxDoc();
				docMap = new int[maxDoc];
				int j = 0;
				for (int i = 0; i < maxDoc; i++)
				{
					if (reader.IsDeleted(i))
						docMap[i] = - 1;
					else
						docMap[i] = j++;
				}
			}
		}
		/// <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)));
		}
Пример #27
0
        /// <summary>Constructs a query selecting all terms greater than
        /// <code>lowerTerm</code> but less than <code>upperTerm</code>.
        /// There must be at least one term and either term may be null,
        /// in which case there is no bound on that side, but if there are
        /// two terms, both terms <b>must</b> be for the same Field.
        /// </summary>
        public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive)
        {
            if (lowerTerm == null && upperTerm == null)
            {
                throw new System.ArgumentException("At least one term must be non-null");
            }
            if (lowerTerm != null && upperTerm != null && (System.Object)lowerTerm.Field() != (System.Object)upperTerm.Field())
            {
                throw new System.ArgumentException("Both terms must be for the same Field");
            }

            // if we have a lowerTerm, start there. otherwise, start at beginning
            if (lowerTerm != null)
            {
                this.lowerTerm = lowerTerm;
            }
            else
            {
                this.lowerTerm = new Term(upperTerm.Field(), "");
            }

            this.upperTerm = upperTerm;
            this.inclusive = inclusive;
        }
Пример #28
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)));
        }
Пример #29
0
		/// <summary>Increments the enumeration to the next element.  True if one exists. </summary>
		public override bool Next()
		{
			if (actualEnum == null)
				return false; // the actual enumerator is not initialized!
			currentTerm = null;
			while (currentTerm == null)
			{
				if (EndEnum())
					return false;
				if (actualEnum.Next())
				{
					Term term = actualEnum.Term();
					if (TermCompare(term))
					{
						currentTerm = term;
						return true;
					}
				}
				else
					return false;
			}
			currentTerm = null;
			return false;
		}
Пример #30
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);
        }
Пример #31
0
		/// <summary>Constructs a query selecting all terms greater than
		/// <code>lowerTerm</code> but less than <code>upperTerm</code>.
		/// There must be at least one term and either term may be null,
		/// in which case there is no bound on that side, but if there are
		/// two terms, both terms <b>must</b> be for the same Field.
		/// </summary>
		public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive)
		{
			if (lowerTerm == null && upperTerm == null)
			{
				throw new System.ArgumentException("At least one term must be non-null");
			}
			if (lowerTerm != null && upperTerm != null && (System.Object) lowerTerm.Field() != (System.Object) upperTerm.Field())
			{
				throw new System.ArgumentException("Both terms must be for the same Field");
			}
			
			// if we have a lowerTerm, start there. otherwise, start at beginning
			if (lowerTerm != null)
			{
				this.lowerTerm = lowerTerm;
			}
			else
			{
				this.lowerTerm = new Term(upperTerm.Field(), "");
			}
			
			this.upperTerm = upperTerm;
			this.inclusive = inclusive;
		}
Пример #32
0
		/// <summary>Closes the enumeration to further activity, freeing resources.  </summary>
		public override void  Close()
		{
			actualEnum.Close();
			currentTerm = null;
			actualEnum = null;
		}
Пример #33
0
 /// <summary>Constructs a query for the term <code>t</code>. </summary>
 public TermQuery(Term t)
 {
     term = t;
 }
		public override int DocFreq(Term t)
		{
			TermInfo ti = tis.Get(t);
			if (ti != null)
				return ti.docFreq;
			else
				return 0;
		}
Пример #35
0
 /// <summary> Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.</summary>
 public FuzzyQuery(Term term, float minimumSimilarity):this(term, minimumSimilarity, 0)
 {
 }
Пример #36
0
		/// <summary>Returns an enumeration of all the documents which contain
		/// <code>term</code>. For each document, the document number, the frequency of
		/// the term in that document is also provided, for use in search scoring.
		/// Thus, this method implements the mapping:
		/// <p><ul>
		/// Term &nbsp;&nbsp; =&gt; &nbsp;&nbsp; &lt;docNum, freq&gt;<sup>*</sup>
		/// </ul>
		/// <p>The enumeration is ordered by document number.  Each document number
		/// is greater than all that precede it in the enumeration.
		/// </summary>
		public virtual TermDocs TermDocs(Term term)
		{
			TermDocs termDocs = TermDocs();
			termDocs.Seek(term);
			return termDocs;
		}
Пример #37
0
		/// <summary>Deletes all documents containing <code>term</code>.
		/// This is useful if one uses a document Field to hold a unique ID string for
		/// the document.  Then to delete such a document, one merely constructs a
		/// term with the appropriate Field and the unique ID string as its text and
		/// passes it to this method.  Returns the number of documents deleted.
		/// </summary>
		public int Delete(Term term)
		{
			TermDocs docs = TermDocs(term);
			if (docs == null)
				return 0;
			int n = 0;
			try
			{
				while (docs.Next())
				{
					Delete(docs.Doc());
					n++;
				}
			}
			finally
			{
				docs.Close();
			}
			return n;
		}
Пример #38
0
        // inherit javadocs
        public virtual StringIndex GetStringIndex(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
        {
            field = String.Intern(field);
            System.Object ret = Lookup(reader, field, Monodoc.Lucene.Net.Search.FieldCache_Fields.STRING_INDEX);
            if (ret == null)
            {
                int[]           retArray = new int[reader.MaxDoc()];
                System.String[] mterms   = new System.String[reader.MaxDoc() + 1];
                if (retArray.Length > 0)
                {
                    TermDocs termDocs = reader.TermDocs();
                    TermEnum termEnum = reader.Terms(new Term(field, ""));
                    int      t        = 0;         // current term number

                    // an entry for documents that have no terms in this Field
                    // should a document with no terms be at top or bottom?
                    // this puts them at the top - if it is changed, FieldDocSortedHitQueue
                    // needs to change as well.
                    mterms[t++] = null;

                    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;
                            }

                            // store term text
                            // we expect that there is at most one term per document
                            if (t >= mterms.Length)
                            {
                                throw new System.SystemException("there are more terms than documents in Field \"" + field + "\"");
                            }
                            mterms[t] = term.Text();

                            termDocs.Seek(termEnum);
                            while (termDocs.Next())
                            {
                                retArray[termDocs.Doc()] = t;
                            }

                            t++;
                        }while (termEnum.Next());
                    }
                    finally
                    {
                        termDocs.Close();
                        termEnum.Close();
                    }

                    if (t == 0)
                    {
                        // if there are no terms, make the term array
                        // have a single null entry
                        mterms = new System.String[1];
                    }
                    else if (t < mterms.Length)
                    {
                        // if there are less terms than documents,
                        // trim off the dead array space
                        System.String[] terms = new System.String[t];
                        Array.Copy(mterms, 0, terms, 0, t);
                        mterms = terms;
                    }
                }
                StringIndex value_Renamed = new StringIndex(retArray, mterms);
                Store(reader, field, Monodoc.Lucene.Net.Search.FieldCache_Fields.STRING_INDEX, value_Renamed);
                return(value_Renamed);
            }
            return((StringIndex)ret);
        }
Пример #39
0
 /// <summary>Construct a SpanTermQuery matching the named term's spans. </summary>
 public SpanTermQuery(Term term)
 {
     this.term = term;
 }
Пример #40
0
 /// <summary> Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.</summary>
 public FuzzyQuery(Term term) : this(term, defaultMinSimilarity, 0)
 {
 }
Пример #41
0
 /// <summary> Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.</summary>
 public FuzzyQuery(Term term, float minimumSimilarity) : this(term, minimumSimilarity, 0)
 {
 }
Пример #42
0
 /// <summary>Computes a score factor for a simple term.
 ///
 /// <p>The default implementation is:<pre>
 /// return idf(searcher.docFreq(term), searcher.maxDoc());
 /// </pre>
 ///
 /// Note that {@link Searcher#MaxDoc()} is used instead of
 /// {@link Monodoc.Lucene.Net.Index.IndexReader#NumDocs()} because it is proportional to
 /// {@link Searcher#DocFreq(Term)} , i.e., when one is inaccurate,
 /// so is the other, and in the same direction.
 ///
 /// </summary>
 /// <param name="term">the term in question
 /// </param>
 /// <param name="searcher">the document collection being searched
 /// </param>
 /// <returns> a score factor for the term
 /// </returns>
 public virtual float Idf(Term term, Searcher searcher)
 {
     return(Idf(searcher.DocFreq(term), searcher.MaxDoc()));
 }
 /// <summary>Closes the enumeration to further activity, freeing resources.  </summary>
 public override void  Close()
 {
     actualEnum.Close();
     currentTerm = null;
     actualEnum  = null;
 }
 /// <summary>Equality compare on the term </summary>
 protected internal abstract bool TermCompare(Term term);
Пример #45
0
		/// <summary>Returns an enumeration of all the documents which contain
		/// <code>term</code>.  For each document, in addition to the document number
		/// and frequency of the term in that document, a list of all of the ordinal
		/// positions of the term in the document is available.  Thus, this method
		/// implements the mapping:
		/// <p><ul>
		/// Term &nbsp;&nbsp; =&gt; &nbsp;&nbsp; &lt;docNum, freq,
		/// &lt;pos<sub>1</sub>, pos<sub>2</sub>, ...
		/// pos<sub>freq-1</sub>&gt;
		/// &gt;<sup>*</sup>
		/// </ul>
		/// <p> This positional information faciliates phrase and proximity searching.
		/// <p>The enumeration is ordered by document number.  Each document number is
		/// greater than all that precede it in the enumeration.
		/// </summary>
		public virtual TermPositions TermPositions(Term term)
		{
			TermPositions termPositions = TermPositions();
			termPositions.Seek(term);
			return termPositions;
		}
Пример #46
0
 public WildcardQuery(Term term) : base(term)
 {
 }
		public override TermEnum Terms(Term t)
		{
			return tis.Terms(t);
		}
Пример #48
0
 /// <summary>The termCompare method in FuzzyTermEnum uses Levenshtein distance to 
 /// calculate the distance between the given term and the comparing term. 
 /// </summary>
 protected internal override bool TermCompare(Term term)
 {
     System.String termText = term.Text();
     if ((System.Object) field == (System.Object) term.Field() && termText.StartsWith(prefix))
     {
         System.String target = termText.Substring(prefixLength);
         int targetlen = target.Length;
         int dist = EditDistance(text, target, textlen, targetlen);
         distance = 1 - ((double) dist / (double) System.Math.Min(textlen, targetlen));
         return (distance > minimumSimilarity);
     }
     endEnum = true;
     return false;
 }
Пример #49
0
            public virtual Explanation Explain(Monodoc.Lucene.Net.Index.IndexReader reader, int doc)
            {
                Explanation result = new Explanation();

                result.SetDescription("weight(" + Query + " in " + doc + "), product of:");

                System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
                System.Text.StringBuilder query    = new System.Text.StringBuilder();
                query.Append('\"');
                for (int i = 0; i < Enclosing_Instance.terms.Count; i++)
                {
                    if (i != 0)
                    {
                        docFreqs.Append(" ");
                        query.Append(" ");
                    }

                    Term term = (Term)Enclosing_Instance.terms[i];

                    docFreqs.Append(term.Text());
                    docFreqs.Append("=");
                    docFreqs.Append(searcher.DocFreq(term));

                    query.Append(term.Text());
                }
                query.Append('\"');

                Explanation idfExpl = new Explanation(idf, "idf(" + Enclosing_Instance.field + ": " + docFreqs + ")");

                // explain query weight
                Explanation queryExpl = new Explanation();

                queryExpl.SetDescription("queryWeight(" + Query + "), product of:");

                Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");

                if (Enclosing_Instance.GetBoost() != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }
                queryExpl.AddDetail(idfExpl);

                Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

                // explain Field weight
                Explanation fieldExpl = new Explanation();

                fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.field + ":" + query + " in " + doc + "), product of:");

                Explanation tfExpl = Scorer(reader).Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

                byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
                float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(Field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

                if (queryExpl.GetValue() == 1.0f)
                {
                    return(fieldExpl);
                }

                return(result);
            }
Пример #50
0
		public override void  Close()
		{
			base.Close();
			searchTerm = null;
			field = null;
			text = null;
		}
Пример #51
0
 /// <summary> Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.</summary>
 public FuzzyQuery(Term term):this(term, defaultMinSimilarity, 0)
 {
 }
Пример #52
0
 /// <summary> Empty prefix and minSimilarity of 0.5f are used.
 /// 
 /// </summary>
 /// <param name="">reader
 /// </param>
 /// <param name="">term
 /// </param>
 /// <throws>  IOException </throws>
 /// <seealso cref="Term, float, int)">
 /// </seealso>
 public FuzzyTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term):this(reader, term, FuzzyQuery.defaultMinSimilarity, 0)
 {
 }
        /// <summary>Add a single term at the next position in the phrase.</summary>
        /// <seealso cref="PhraseQuery#Add(Term)">
        /// </seealso>
        public virtual void  Add(Term term)
		{
			Add(new Term[]{term});
		}
Пример #54
0
 /// <summary> This is the standard FuzzyTermEnum with an empty prefix.
 /// 
 /// </summary>
 /// <param name="">reader
 /// </param>
 /// <param name="">term
 /// </param>
 /// <param name="">minSimilarity
 /// </param>
 /// <throws>  IOException </throws>
 /// <seealso cref="Term, float, int)">
 /// </seealso>
 public FuzzyTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term, float minSimilarity):this(reader, term, minSimilarity, 0)
 {
 }
        /// <summary> Allows to specify the relative position of terms within the phrase.
        /// 
        /// </summary>
        /// <seealso cref="int)">
        /// </seealso>
        /// <param name="">terms
        /// </param>
        /// <param name="">position
        /// </param>
        public virtual void  Add(Term[] terms, int position)
        {
            if (termArrays.Count == 0)
                field = terms[0].Field();
			
            for (int i = 0; i < terms.Length; i++)
            {
                if ((System.Object) terms[i].Field() != (System.Object) field)
                {
                    throw new System.ArgumentException("All phrase terms must be in the same field (" + field + "): " + terms[i]);
                }
            }
			
            termArrays.Add(terms);
            positions.Add((System.Int32) position);
        }
Пример #56
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)));
 }
Пример #57
0
		/// <summary>Equality compare on the term </summary>
		protected internal abstract bool TermCompare(Term term);
Пример #58
0
		/// <summary>Returns an enumeration of all terms after a given term.
		/// The enumeration is ordered by Term.compareTo().  Each term
		/// is greater than all that precede it in the enumeration.
		/// </summary>
		public abstract TermEnum Terms(Term t);
Пример #59
0
		/// <summary>Returns the number of documents containing the term <code>t</code>. </summary>
		public abstract int DocFreq(Term t);
Пример #60
0
 // inherit javadoc
 public override int DocFreq(Term term)
 {
     return(reader.DocFreq(term));
 }