Ejemplo n.º 1
0
        /// <summary> Enumerates all terms greater/equal than <code>lowerTerm</code>
        /// but less/equal than <code>upperTerm</code>.
        ///
        /// If an endpoint is null, it is said to be "open". Either or both
        /// endpoints may be open.  Open endpoints may not be exclusive
        /// (you can't select all but the first or last term without
        /// explicitly specifying the term to exclude.)
        ///
        /// </summary>
        /// <param name="reader">
        /// </param>
        /// <param name="field">An interned field that holds both lower and upper terms.
        /// </param>
        /// <param name="lowerTermText">The term text at the lower end of the range
        /// </param>
        /// <param name="upperTermText">The term text at the upper end of the range
        /// </param>
        /// <param name="includeLower">If true, the <code>lowerTerm</code> is included in the range.
        /// </param>
        /// <param name="includeUpper">If true, the <code>upperTerm</code> is included in the range.
        /// </param>
        /// <param name="collator">The collator to use to collate index Terms, to determine their
        /// membership in the range bounded by <code>lowerTerm</code> and
        /// <code>upperTerm</code>.
        ///
        /// </param>
        /// <throws>  IOException </throws>
        public TermRangeTermEnum(IndexReader reader, System.String field, System.String lowerTermText, System.String upperTermText, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator)
        {
            this.collator      = collator;
            this.upperTermText = upperTermText;
            this.lowerTermText = lowerTermText;
            this.includeLower  = includeLower;
            this.includeUpper  = includeUpper;
            this.field         = StringHelper.Intern(field);

            // do a little bit of normalization...
            // open ended range queries should always be inclusive.
            if (this.lowerTermText == null)
            {
                this.lowerTermText = "";
                this.includeLower  = true;
            }

            if (this.upperTermText == null)
            {
                this.includeUpper = true;
            }

            System.String startTermText = collator == null?this.lowerTermText:"";
            SetEnum(reader.Terms(new Term(this.field, startTermText)));
        }
Ejemplo n.º 2
0
 /// <summary>Creates one of these objects for a custom comparator/parser. </summary>
 internal Entry(System.String field, System.Object custom)
 {
     this.field  = StringHelper.Intern(field);
     this.type   = SortField.CUSTOM;
     this.custom = custom;
     this.locale = null;
 }
Ejemplo n.º 3
0
 internal Entry(System.String field, int type, System.Globalization.CultureInfo locale)
 {
     this.field  = StringHelper.Intern(field);
     this.type   = type;
     this.custom = null;
     this.locale = locale;
 }
Ejemplo n.º 4
0
        /// <summary> Create a stored field with binary value. Optionally the value may be compressed.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="value_Renamed">The binary value
        /// </param>
        /// <param name="offset">Starting offset in value where this Field's bytes are
        /// </param>
        /// <param name="length">Number of bytes to use for this Field, starting at offset
        /// </param>
        /// <param name="store">How <c>value</c> should be stored (compressed or not)
        /// </param>
        /// <throws>  IllegalArgumentException if store is <c>Store.NO</c>  </throws>
        public Field(System.String name, byte[] value_Renamed, int offset, int length, Store store)
        {
            if (name == null)
            {
                throw new System.ArgumentException("name cannot be null");
            }
            if (value_Renamed == null)
            {
                throw new System.ArgumentException("value cannot be null");
            }

            this.internalName = StringHelper.Intern(name); // field names are interned
            fieldsData        = value_Renamed;

            if (store == Store.NO)
            {
                throw new System.ArgumentException("binary values can't be unstored");
            }

            internalIsStored    = store.IsStored();
            internalIsIndexed   = false;
            internalIsTokenized = false;
            internalOmitTermFreqAndPositions = false;
            internalOmitNorms = true;

            internalIsBinary     = true;
            internalBinaryLength = length;
            internalbinaryOffset = offset;

            SetStoreTermVector(TermVector.NO);
        }
Ejemplo n.º 5
0
 internal Entry(System.String field, int type, Parser parser)
 {
     this.field  = StringHelper.Intern(field);
     this.type   = type;
     this.custom = parser;
     this.locale = null;
 }
Ejemplo n.º 6
0
 /// <summary> Returns an array of objects which represent that natural order
 /// of the term values in the given field.
 ///
 /// </summary>
 /// <param name="reader">    Terms are in this index.
 /// </param>
 /// <param name="enumerator">Use this to get the term values and TermDocs.
 /// </param>
 /// <param name="fieldname"> Comparables should be for this field.
 /// </param>
 /// <returns> Array of objects representing natural order of terms in field.
 /// </returns>
 /// <throws>  IOException If an error occurs reading the index. </throws>
 protected internal virtual System.IComparable[] fillCache(IndexReader reader, TermEnum enumerator, System.String fieldname)
 {
     System.String        field    = StringHelper.Intern(fieldname);
     System.IComparable[] retArray = new System.IComparable[reader.MaxDoc()];
     if (retArray.Length > 0)
     {
         TermDocs termDocs = reader.TermDocs();
         try
         {
             if (enumerator.Term() == null)
             {
                 throw new System.SystemException("no terms in field " + field);
             }
             do
             {
                 Term term = enumerator.Term();
                 if ((System.Object)term.Field() != (System.Object)field)
                 {
                     break;
                 }
                 System.IComparable termval = GetComparable(term.Text());
                 termDocs.Seek(enumerator);
                 while (termDocs.Next())
                 {
                     retArray[termDocs.Doc()] = termval;
                 }
             }while (enumerator.Next());
         }
         finally
         {
             termDocs.Close();
         }
     }
     return(retArray);
 }
Ejemplo n.º 7
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String   field    = StringHelper.Intern((System.String)entryKey.field);
                System.String[] retArray = new System.String[reader.MaxDoc()];
                TermDocs        termDocs = reader.TermDocs();
                TermEnum        termEnum = reader.Terms(new Term(field));

                try
                {
                    do
                    {
                        Term term = termEnum.Term();
                        if (term == null || (System.Object)term.Field() != (System.Object)field)
                        {
                            break;
                        }
                        System.String termval = term.Text();
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc()] = termval;
                        }
                    }while (termEnum.Next());
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                return(retArray);
            }
Ejemplo n.º 8
0
        /// <summary> Create a tokenized and indexed field that is not stored, optionally with
        /// storing term vectors.  This is useful for pre-analyzed fields.
        /// The TokenStream is read only when the Document is added to the index,
        /// i.e. you may not close the TokenStream until {@link IndexWriter#AddDocument(Document)}
        /// has been called.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="tokenStream">The TokenStream with the content
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or tokenStream is <code>null</code> </throws>
        public Field(System.String name, TokenStream tokenStream, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (tokenStream == null)
            {
                throw new System.NullReferenceException("tokenStream cannot be null");
            }

            this.name        = StringHelper.Intern(name);      // field names are interned
            this.fieldsData  = null;
            this.tokenStream = tokenStream;

            this.isStored     = false;
            this.isCompressed = false;

            this.isIndexed   = true;
            this.isTokenized = true;

            this.isBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 9
0
        private FieldInfo AddInternal(String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
        {
            name = StringHelper.Intern(name);
            var fi = new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);

            byNumber.Add(fi);
            byName[name] = fi;
            return(fi);
        }
Ejemplo n.º 10
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String field      = StringHelper.Intern((System.String)entryKey.field);
                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 type");
                    }
                    System.Object ret = null;
                    if ((System.Object)term.Field() == (System.Object)field)
                    {
                        System.String termtext = term.Text().Trim();

                        try
                        {
                            System.Int32.Parse(termtext);
                            ret = wrapper.GetInts(reader, field);
                        }
                        catch (System.FormatException nfe1)
                        {
                            try
                            {
                                System.Int64.Parse(termtext);
                                ret = wrapper.GetLongs(reader, field);
                            }
                            catch (System.FormatException nfe2)
                            {
                                try
                                {
                                    SupportClass.Single.Parse(termtext);
                                    ret = wrapper.GetFloats(reader, field);
                                }
                                catch (System.FormatException nfe3)
                                {
                                    ret = wrapper.GetStringIndex(reader, field);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new System.SystemException("field \"" + field + "\" does not appear to be indexed");
                    }
                    return(ret);
                }
                finally
                {
                    enumerator.Close();
                }
            }
Ejemplo n.º 11
0
        /// <summary>
        /// Lucene.Net specific. Needed for deserialization
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        private NumericRangeQuery(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            precisionStep = (int)info.GetValue("precisionStep", typeof(int));
            valSize       = (int)info.GetValue("valSize", typeof(int));
            min           = (System.ValueType)info.GetValue("min", typeof(System.ValueType));
            max           = (System.ValueType)info.GetValue("max", typeof(System.ValueType));
            minInclusive  = (bool)info.GetValue("minInclusive", typeof(bool));
            maxInclusive  = (bool)info.GetValue("maxInclusive", typeof(bool));

            field = StringHelper.Intern((string)info.GetValue("field", typeof(string)));
        }
Ejemplo n.º 12
0
        /// <summary> Create a field by specifying its name, value and how it will
        /// be saved in the index.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="internName">Whether to .intern() name or not
        /// </param>
        /// <param name="value">The string to process
        /// </param>
        /// <param name="store">Whether <c>value</c> should be stored in the index
        /// </param>
        /// <param name="index">Whether the field should be indexed, and if so, if it should
        /// be tokenized before indexing
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or value is <c>null</c> </throws>
        /// <throws>  IllegalArgumentException in any of the following situations: </throws>
        /// <summary> <list>
        /// <item>the field is neither stored nor indexed</item>
        /// <item>the field is not indexed but termVector is <c>TermVector.YES</c></item>
        /// </list>
        /// </summary>
        public Field(System.String name, bool internName, System.String value, Store store, Index index, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }

            if (value == null)
            {
                throw new System.NullReferenceException("value cannot be null");
            }

            if (name.Length == 0 && value.Length == 0)
            {
                throw new System.ArgumentException("name and value cannot both be empty");
            }

            if (index == Index.NO && store == Store.NO)
            {
                throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
            }

            if (index == Index.NO && termVector != TermVector.NO)
            {
                throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
            }

            if (internName)
            {
                // field names are optionally interned
                name = StringHelper.Intern(name);
            }

            this.internalName = name;

            this.fieldsData = value;

            this.internalIsStored = store.IsStored();

            this.internalIsIndexed   = index.IsIndexed();
            this.internalIsTokenized = index.IsAnalyzed();
            this.internalOmitNorms   = index.OmitNorms();

            if (index == Index.NO)
            {
                this.internalOmitTermFreqAndPositions = false;
            }

            this.internalIsBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 13
0
        private void  Read(IndexInput input, String fileName, IState state)
        {
            int firstInt = input.ReadVInt(state);

            if (firstInt < 0)
            {
                // This is a real format
                format = firstInt;
            }
            else
            {
                format = FORMAT_PRE;
            }

            if (format != FORMAT_PRE & format != FORMAT_START)
            {
                throw new CorruptIndexException("unrecognized format " + format + " in file \"" + fileName + "\"");
            }

            int size;

            if (format == FORMAT_PRE)
            {
                size = firstInt;
            }
            else
            {
                size = input.ReadVInt(state);                 //read in the size
            }

            for (int i = 0; i < size; i++)
            {
                String name            = StringHelper.Intern(input.ReadString(state));
                byte   bits            = input.ReadByte(state);
                bool   isIndexed       = (bits & IS_INDEXED) != 0;
                bool   storeTermVector = (bits & STORE_TERMVECTOR) != 0;
                bool   storePositionsWithTermVector = (bits & STORE_POSITIONS_WITH_TERMVECTOR) != 0;
                bool   storeOffsetWithTermVector    = (bits & STORE_OFFSET_WITH_TERMVECTOR) != 0;
                bool   omitNorms                = (bits & OMIT_NORMS) != 0;
                bool   storePayloads            = (bits & STORE_PAYLOADS) != 0;
                bool   omitTermFreqAndPositions = (bits & OMIT_TERM_FREQ_AND_POSITIONS) != 0;

                AddInternal(name, isIndexed, storeTermVector, storePositionsWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
            }

            if (input.FilePointer(state) != input.Length(state))
            {
                throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.FilePointer(state) + " vs size " + input.Length(state));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Lucene.Net specific. Needed for deserialization
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected SortField(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            //Should we add other fields as in NumericRangeQuery? {{DIGY}}

            type             = (int)info.GetValue("type", typeof(int));
            useLegacy        = (bool)info.GetValue("useLegacy", typeof(bool));
            reverse          = (bool)info.GetValue("reverse", typeof(bool));
            locale           = (System.Globalization.CultureInfo)info.GetValue("locale", typeof(System.Globalization.CultureInfo));
            comparatorSource = (FieldComparatorSource)info.GetValue("comparatorSource", typeof(FieldComparatorSource));
            factory          = (SortComparatorSource)info.GetValue("factory", typeof(FieldComparatorSource));
            parser           = (Parser)info.GetValue("parser", typeof(Parser));

            field = StringHelper.Intern((string)info.GetValue("field", typeof(string)));
        }
Ejemplo n.º 15
0
            public virtual ScoreDocComparator NewComparator(IndexReader reader, System.String fieldname)
            {
                System.String field      = StringHelper.Intern(fieldname);
                TermEnum      enumerator = reader.Terms(new Term(fieldname, ""));

                try
                {
                    return(new AnonymousClassScoreDocComparator(reader, enumerator, field, this));
                }
                finally
                {
                    enumerator.Close();
                }
            }
Ejemplo n.º 16
0
 // Sets field & type, and ensures field is not NULL unless
 // type is SCORE or DOC
 private void  InitFieldType(System.String field, int type)
 {
     this.type = type;
     if (field == null)
     {
         if (type != SCORE && type != DOC)
         {
             throw new System.ArgumentException("field can only be null when type is SCORE or DOC");
         }
     }
     else
     {
         this.field = StringHelper.Intern(field);
     }
 }
Ejemplo n.º 17
0
        protected internal AbstractField(System.String name, Field.Store store, Field.Index index, Field.TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            this.internalName = StringHelper.Intern(name); // field names are interned

            this.internalIsStored    = store.IsStored();
            this.internalIsIndexed   = index.IsIndexed();
            this.internalIsTokenized = index.IsAnalyzed();
            this.internalOmitNorms   = index.OmitNorms();

            this.internalIsBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 18
0
        internal static int DetectFieldType(IndexReader reader, System.String fieldKey)
        {
            System.String field      = StringHelper.Intern(fieldKey);
            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");
                }
                int ret = 0;
                if ((System.Object)term.Field() == (System.Object)field)
                {
                    System.String termtext = term.Text().Trim();

                    int tmpI32; long tmpI64; float tmpF;
                    if (System.Int32.TryParse(termtext, out tmpI32))
                    {
                        ret = SortField.INT;
                    }
                    else if (System.Int64.TryParse(termtext, out tmpI64))
                    {
                        ret = SortField.LONG;
                    }
                    else if (SupportClass.Single.TryParse(termtext, out tmpF))
                    {
                        ret = SortField.FLOAT;
                    }
                    else
                    {
                        ret = SortField.STRING;
                    }
                }
                else
                {
                    throw new System.SystemException("field \"" + field + "\" does not appear to be indexed");
                }
                return(ret);
            }
            finally
            {
                enumerator.Close();
            }
        }
Ejemplo n.º 19
0
        /// <summary> Create a stored field with binary value. Optionally the value may be compressed.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="value">The binary value
        /// </param>
        /// <param name="offset">Starting offset in value where this Field's bytes are
        /// </param>
        /// <param name="length">Number of bytes to use for this Field, starting at offset
        /// </param>
        /// <param name="store">How <code>value</code> should be stored (compressed or not)
        /// </param>
        /// <throws>  IllegalArgumentException if store is <code>Store.NO</code>  </throws>
        public Field(System.String name, byte[] value_Renamed, int offset, int length, Store store)
        {
            if (name == null)
            {
                throw new System.ArgumentException("name cannot be null");
            }
            if (value_Renamed == null)
            {
                throw new System.ArgumentException("value cannot be null");
            }

            this.name  = StringHelper.Intern(name);            // field names are interned
            fieldsData = value_Renamed;

            if (store == Store.YES)
            {
                isStored     = true;
                isCompressed = false;
            }
            else if (store == Store.COMPRESS)
            {
                isStored     = true;
                isCompressed = true;
            }
            else if (store == Store.NO)
            {
                throw new System.ArgumentException("binary values can't be unstored");
            }
            else
            {
                throw new System.ArgumentException("unknown store parameter " + store);
            }

            isIndexed   = false;
            isTokenized = false;
            omitTermFreqAndPositions = false;
            omitNorms = true;

            isBinary     = true;
            binaryLength = length;
            binaryOffset = offset;

            SetStoreTermVector(TermVector.NO);
        }
Ejemplo n.º 20
0
            public FieldForMerge(System.Object value_Renamed, FieldInfo fi, bool binary, bool compressed, bool tokenize)
            {
                this.isStored     = true;
                this.fieldsData   = value_Renamed;
                this.isCompressed = compressed;
                this.isBinary     = binary;
                if (binary)
                {
                    binaryLength = ((byte[])value_Renamed).Length;
                }

                this.isTokenized = tokenize;

                this.name      = StringHelper.Intern(fi.name);
                this.isIndexed = fi.isIndexed;
                this.omitNorms = fi.omitNorms;
                this.omitTermFreqAndPositions    = fi.omitTermFreqAndPositions;
                this.storeOffsetWithTermVector   = fi.storeOffsetWithTermVector;
                this.storePositionWithTermVector = fi.storePositionWithTermVector;
                this.storeTermVector             = fi.storeTermVector;
            }
Ejemplo n.º 21
0
        internal NumericRangeQuery(string field, int precisionStep, int valSize, T?min, T?max, bool minInclusive, bool maxInclusive)
        {
            System.Diagnostics.Debug.Assert((valSize == 32 || valSize == 64));
            if (precisionStep < 1)
            {
                throw new System.ArgumentException("precisionStep must be >=1");
            }
            this.field         = StringHelper.Intern(field);
            this.precisionStep = precisionStep;
            this.valSize       = valSize;
            this.min           = min;
            this.max           = max;
            this.minInclusive  = minInclusive;
            this.maxInclusive  = maxInclusive;

            // For bigger precisionSteps this query likely
            // hits too many terms, so set to CONSTANT_SCORE_FILTER right off
            // (especially as the FilteredTermEnum is costly if wasted only for AUTO tests because it
            // creates new enums from IndexReader for each sub-range)
            switch (valSize)
            {
            case 64:
                RewriteMethod = (precisionStep > 6)?CONSTANT_SCORE_FILTER_REWRITE:CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
                break;

            case 32:
                RewriteMethod = (precisionStep > 8)?CONSTANT_SCORE_FILTER_REWRITE:CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
                break;

            default:
                // should never happen
                throw new System.ArgumentException("valSize must be 32 or 64");
            }

            // shortcut if upper bound == lower bound
            if (min != null && min.Equals(max))
            {
                RewriteMethod = CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
            }
        }
Ejemplo n.º 22
0
        /// <summary> Create a tokenized and indexed field that is not stored, optionally with
        /// storing term vectors.  The Reader is read only when the Document is added to the index,
        /// i.e. you may not close the Reader until <see cref="IndexWriter.AddDocument(Document)" />
        /// has been called.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="reader">The reader with the content
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or reader is <c>null</c> </throws>
        public Field(System.String name, System.IO.TextReader reader, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (reader == null)
            {
                throw new System.NullReferenceException("reader cannot be null");
            }

            this.internalName = StringHelper.Intern(name); // field names are interned
            this.fieldsData   = reader;

            this.internalIsStored = false;

            this.internalIsIndexed   = true;
            this.internalIsTokenized = true;

            this.internalIsBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 23
0
        /// <summary> Create a field by specifying its name, value and how it will
        /// be saved in the index.
        ///
        /// </summary>
        /// <param name="name">The name of the field
        /// </param>
        /// <param name="internName">Whether to .intern() name or not
        /// </param>
        /// <param name="value">The string to process
        /// </param>
        /// <param name="store">Whether <code>value</code> should be stored in the index
        /// </param>
        /// <param name="index">Whether the field should be indexed, and if so, if it should
        /// be tokenized before indexing
        /// </param>
        /// <param name="termVector">Whether term vector should be stored
        /// </param>
        /// <throws>  NullPointerException if name or value is <code>null</code> </throws>
        /// <throws>  IllegalArgumentException in any of the following situations: </throws>
        /// <summary> <ul>
        /// <li>the field is neither stored nor indexed</li>
        /// <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
        /// </ul>
        /// </summary>
        public Field(System.String name, bool internName, System.String value_Renamed, Store store, Index index, TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            if (value_Renamed == null)
            {
                throw new System.NullReferenceException("value cannot be null");
            }
            if (name.Length == 0 && value_Renamed.Length == 0)
            {
                throw new System.ArgumentException("name and value cannot both be empty");
            }
            if (index == Index.NO && store == Store.NO)
            {
                throw new System.ArgumentException("it doesn't make sense to have a field that " + "is neither indexed nor stored");
            }
            if (index == Index.NO && termVector != TermVector.NO)
            {
                throw new System.ArgumentException("cannot store term vector information " + "for a field that is not indexed");
            }

            if (internName)
            {
                // field names are optionally interned
                name = StringHelper.Intern(name);
            }

            this.name = name;

            this.fieldsData = value_Renamed;

            if (store == Store.YES)
            {
                this.isStored     = true;
                this.isCompressed = false;
            }
            else if (store == Store.COMPRESS)
            {
                this.isStored     = true;
                this.isCompressed = true;
            }
            else if (store == Store.NO)
            {
                this.isStored     = false;
                this.isCompressed = false;
            }
            else
            {
                throw new System.ArgumentException("unknown store parameter " + store);
            }

            if (index == Index.NO)
            {
                this.isIndexed   = false;
                this.isTokenized = false;
                this.omitTermFreqAndPositions = false;
                this.omitNorms = true;
            }
            else if (index == Index.ANALYZED)
            {
                this.isIndexed   = true;
                this.isTokenized = true;
            }
            else if (index == Index.NOT_ANALYZED)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
            }
            else if (index == Index.NOT_ANALYZED_NO_NORMS)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
                this.omitNorms   = true;
            }
            else if (index == Index.ANALYZED_NO_NORMS)
            {
                this.isIndexed   = true;
                this.isTokenized = true;
                this.omitNorms   = true;
            }
            else
            {
                throw new System.ArgumentException("unknown index parameter " + index);
            }

            this.isBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 24
0
 /// <summary>Constructs a Term with the given field and text.
 /// <p/>Note that a null field or null text value results in undefined
 /// behavior for most Lucene APIs that accept a Term parameter.
 /// </summary>
 public Term(string fld, string txt)
 {
     field = StringHelper.Intern(fld);
     text  = txt;
 }
Ejemplo n.º 25
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String   field    = StringHelper.Intern((System.String)entryKey.field);
                int[]           retArray = new int[reader.MaxDoc()];
                System.String[] mterms   = new System.String[reader.MaxDoc() + 1];
                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
                {
                    do
                    {
                        Term term = termEnum.Term();
                        if (term == null || (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 + "\", but it's impossible to sort on " + "tokenized fields");
                        }
                        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);

                return(value_Renamed);
            }
Ejemplo n.º 26
0
        public static void  VerifyEquals(IndexReader r1, IndexReader r2, System.String idField)
        {
            Assert.AreEqual(r1.NumDocs(), r2.NumDocs());
            bool hasDeletes = !(r1.MaxDoc() == r2.MaxDoc() && r1.NumDocs() == r1.MaxDoc());

            int[] r2r1 = new int[r2.MaxDoc()];             // r2 id to r1 id mapping

            TermDocs termDocs1 = r1.TermDocs();
            TermDocs termDocs2 = r2.TermDocs();

            // create mapping from id2 space to id2 based on idField
            idField = StringHelper.Intern(idField);
            TermEnum termEnum = r1.Terms(new Term(idField, ""));

            do
            {
                Term term = termEnum.Term();
                if (term == null || (System.Object)term.Field() != (System.Object)idField)
                {
                    break;
                }

                termDocs1.Seek(termEnum);
                if (!termDocs1.Next())
                {
                    // This doc is deleted and wasn't replaced
                    termDocs2.Seek(termEnum);
                    Assert.IsFalse(termDocs2.Next());
                    continue;
                }

                int id1 = termDocs1.Doc();
                Assert.IsFalse(termDocs1.Next());

                termDocs2.Seek(termEnum);
                Assert.IsTrue(termDocs2.Next());
                int id2 = termDocs2.Doc();
                Assert.IsFalse(termDocs2.Next());

                r2r1[id2] = id1;

                // verify stored fields are equivalent
                try
                {
                    VerifyEquals(r1.Document(id1), r2.Document(id2));
                }
                catch (System.Exception t)
                {
                    System.Console.Out.WriteLine("FAILED id=" + term + " id1=" + id1 + " id2=" + id2 + " term=" + term);
                    System.Console.Out.WriteLine("  d1=" + r1.Document(id1));
                    System.Console.Out.WriteLine("  d2=" + r2.Document(id2));
                    throw t;
                }

                try
                {
                    // verify term vectors are equivalent
                    VerifyEquals(r1.GetTermFreqVectors(id1), r2.GetTermFreqVectors(id2));
                }
                catch (System.Exception e)
                {
                    System.Console.Out.WriteLine("FAILED id=" + term + " id1=" + id1 + " id2=" + id2);
                    TermFreqVector[] tv1 = r1.GetTermFreqVectors(id1);
                    System.Console.Out.WriteLine("  d1=" + tv1);
                    if (tv1 != null)
                    {
                        for (int i = 0; i < tv1.Length; i++)
                        {
                            System.Console.Out.WriteLine("    " + i + ": " + tv1[i]);
                        }
                    }

                    TermFreqVector[] tv2 = r2.GetTermFreqVectors(id2);
                    System.Console.Out.WriteLine("  d2=" + tv2);
                    if (tv2 != null)
                    {
                        for (int i = 0; i < tv2.Length; i++)
                        {
                            System.Console.Out.WriteLine("    " + i + ": " + tv2[i]);
                        }
                    }

                    throw e;
                }
            }while (termEnum.Next());

            termEnum.Close();

            // Verify postings
            TermEnum termEnum1 = r1.Terms(new Term("", ""));
            TermEnum termEnum2 = r2.Terms(new Term("", ""));

            // pack both doc and freq into single element for easy sorting
            long[] info1 = new long[r1.NumDocs()];
            long[] info2 = new long[r2.NumDocs()];

            for (; ;)
            {
                Term term1, term2;

                // iterate until we get some docs
                int len1;
                for (; ;)
                {
                    len1  = 0;
                    term1 = termEnum1.Term();
                    if (term1 == null)
                    {
                        break;
                    }
                    termDocs1.Seek(termEnum1);
                    while (termDocs1.Next())
                    {
                        int d1 = termDocs1.Doc();
                        int f1 = termDocs1.Freq();
                        info1[len1] = (((long)d1) << 32) | f1;
                        len1++;
                    }
                    if (len1 > 0)
                    {
                        break;
                    }
                    if (!termEnum1.Next())
                    {
                        break;
                    }
                }

                // iterate until we get some docs
                int len2;
                for (; ;)
                {
                    len2  = 0;
                    term2 = termEnum2.Term();
                    if (term2 == null)
                    {
                        break;
                    }
                    termDocs2.Seek(termEnum2);
                    while (termDocs2.Next())
                    {
                        int d2 = termDocs2.Doc();
                        int f2 = termDocs2.Freq();
                        info2[len2] = (((long)r2r1[d2]) << 32) | f2;
                        len2++;
                    }
                    if (len2 > 0)
                    {
                        break;
                    }
                    if (!termEnum2.Next())
                    {
                        break;
                    }
                }

                if (!hasDeletes)
                {
                    Assert.AreEqual(termEnum1.DocFreq(), termEnum2.DocFreq());
                }

                Assert.AreEqual(len1, len2);
                if (len1 == 0)
                {
                    break;                     // no more terms
                }
                Assert.AreEqual(term1, term2);

                // sort info2 to get it into ascending docid
                System.Array.Sort(info2, 0, len2 - 0);

                // now compare
                for (int i = 0; i < len1; i++)
                {
                    Assert.AreEqual(info1[i], info2[i]);
                }

                termEnum1.Next();
                termEnum2.Next();
            }
        }
Ejemplo n.º 27
0
        protected internal AbstractField(System.String name, Field.Store store, Field.Index index, Field.TermVector termVector)
        {
            if (name == null)
            {
                throw new System.NullReferenceException("name cannot be null");
            }
            this.name = StringHelper.Intern(name);             // field names are interned

            if (store == Field.Store.YES)
            {
                this.isStored     = true;
                this.isCompressed = false;
            }
            else if (store == Field.Store.COMPRESS)
            {
                this.isStored     = true;
                this.isCompressed = true;
            }
            else if (store == Field.Store.NO)
            {
                this.isStored     = false;
                this.isCompressed = false;
            }
            else
            {
                throw new System.ArgumentException("unknown store parameter " + store);
            }

            if (index == Field.Index.NO)
            {
                this.isIndexed   = false;
                this.isTokenized = false;
            }
            else if (index == Field.Index.ANALYZED)
            {
                this.isIndexed   = true;
                this.isTokenized = true;
            }
            else if (index == Field.Index.NOT_ANALYZED)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
            }
            else if (index == Field.Index.NOT_ANALYZED_NO_NORMS)
            {
                this.isIndexed   = true;
                this.isTokenized = false;
                this.omitNorms   = true;
            }
            else if (index == Field.Index.ANALYZED_NO_NORMS)
            {
                this.isIndexed   = true;
                this.isTokenized = true;
                this.omitNorms   = true;
            }
            else
            {
                throw new System.ArgumentException("unknown index parameter " + index);
            }

            this.isBinary = false;

            SetStoreTermVector(termVector);
        }
Ejemplo n.º 28
0
 internal void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
 {
     field = StringHelper.Intern(field);
 }
Ejemplo n.º 29
0
 internal Term(System.String fld, System.String txt, bool intern)
 {
     field = intern?StringHelper.Intern(fld):fld; // field names are interned
     text  = txt;                                 // unless already known to be
 }
Ejemplo n.º 30
0
 /// <summary>Constructs a Term with the given field and text.
 /// <p/>Note that a null field or null text value results in undefined
 /// behavior for most Lucene APIs that accept a Term parameter.
 /// </summary>
 public Term(System.String fld, System.String txt)
 {
     field = StringHelper.Intern(fld);
     text  = txt;
 }