Exemplo n.º 1
0
 public IndexFieldInfo(string name, string value, FieldInfoType type, Field.Store store, Field.Index index, Field.TermVector termVector)
 {
     Name       = name;
     Value      = value;
     Type       = type;
     Store      = store;
     Index      = index;
     TermVector = termVector;
 }
Exemplo n.º 2
0
        /// <seealso cref="IndexReader.GetIndexedFieldNames(Field.TermVector tvSpec)">
        /// </seealso>
        /// <deprecated>  Replaced by {@link #GetFieldNames (IndexReader.FieldOption fldOption)}
        /// </deprecated>
        public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
        {
            bool storedTermVector;
            bool storePositionWithTermVector;
            bool storeOffsetWithTermVector;

            if (tvSpec == Field.TermVector.NO)
            {
                storedTermVector = false;
                storePositionWithTermVector = false;
                storeOffsetWithTermVector = false;
            }
            else if (tvSpec == Field.TermVector.YES)
            {
                storedTermVector = true;
                storePositionWithTermVector = false;
                storeOffsetWithTermVector = false;
            }
            else if (tvSpec == Field.TermVector.WITH_POSITIONS)
            {
                storedTermVector = true;
                storePositionWithTermVector = true;
                storeOffsetWithTermVector = false;
            }
            else if (tvSpec == Field.TermVector.WITH_OFFSETS)
            {
                storedTermVector = true;
                storePositionWithTermVector = false;
                storeOffsetWithTermVector = true;
            }
            else if (tvSpec == Field.TermVector.WITH_POSITIONS_OFFSETS)
            {
                storedTermVector = true;
                storePositionWithTermVector = true;
                storeOffsetWithTermVector = true;
            }
            else
            {
                throw new System.ArgumentException("unknown termVector parameter " + tvSpec);
            }

            // maintain a unique set of field names
            System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
            for (int i = 0; i < fieldInfos.Size(); i++)
            {
                FieldInfo fi = fieldInfos.FieldInfo(i);
                if (fi.isIndexed && fi.storeTermVector == storedTermVector && fi.storePositionWithTermVector == storePositionWithTermVector && fi.storeOffsetWithTermVector == storeOffsetWithTermVector)
                {
                    fieldSet.Add(fi.name, fi.name);
                }
            }
            return fieldSet;
        }
Exemplo n.º 3
0
 public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
 {
     System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
     for (int i = 0; i < readers.Count; i++)
     {
         IndexReader reader = ((IndexReader)readers[i]);
         System.Collections.ICollection names = reader.GetIndexedFieldNames(tvSpec);
         for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext();)
         {
             System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry)iterator.Current;
             System.String s = fi.Key.ToString();
             if (fieldSet.ContainsKey(s) == false)
             {
                 fieldSet.Add(s, s);
             }
         }
     }
     return(fieldSet);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Process Field
 /// </summary>
 /// <param name="doc">
 /// The doc.
 /// </param>
 /// <param name="fieldKey">
 /// The field key.
 /// </param>
 /// <param name="fieldValue">
 /// The field value.
 /// </param>
 /// <param name="storage">
 /// The storage.
 /// </param>
 /// <param name="index">
 /// The index.
 /// </param>
 /// <param name="vector">
 /// The vector.
 /// </param>
 /// <param name="boost">
 /// The boost.
 /// </param>
 protected virtual void ProcessField(Document doc, string fieldKey, string fieldValue, LuceneField.Store storage, LuceneField.Index index, LuceneField.TermVector vector, float boost)
 {
     if ((!fieldKey.IsNullOrEmpty() && !fieldValue.IsNullOrEmpty()) &&
         (index != LuceneField.Index.NO || storage != LuceneField.Store.NO))
     {
         doc.Add(CreateField(fieldKey, fieldValue.ToLowerInvariant(), storage, index, vector, boost));
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Process Field
 /// </summary>
 /// <param name="doc">
 /// The doc.
 /// </param>
 /// <param name="fieldKey">
 /// The field key.
 /// </param>
 /// <param name="fieldValue">
 /// The field value.
 /// </param>
 /// <param name="storage">
 /// The storage.
 /// </param>
 /// <param name="index">
 /// The index.
 /// </param>
 /// <param name="vector">
 /// The vector.
 /// </param>
 protected virtual void ProcessField(Document doc, string fieldKey, string fieldValue, LuceneField.Store storage, LuceneField.Index index, LuceneField.TermVector vector)
 {
     this.ProcessField(doc, fieldKey, fieldValue, storage, index, vector, 1f);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create a Field
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="storageType">
        /// The storage type.
        /// </param>
        /// <param name="indexType">
        /// The index type.
        /// </param>
        /// <param name="vectorType">
        /// The vector type.
        /// </param>
        /// <param name="boost">
        /// The boost.
        /// </param>
        /// <returns>
        /// Abstract Field
        /// </returns>
        protected AbstractField CreateField(string name, string value, LuceneField.Store storageType, LuceneField.Index indexType, LuceneField.TermVector vectorType, float boost)
        {
            var field = new LuceneField(name, value, storageType, indexType, vectorType);

            field.SetBoost(boost);
            return(field);
        }
Exemplo n.º 7
0
        public /*internal*/ Document Doc(int n)
        {
            indexStream.Seek(n * 8L);
            long position = indexStream.ReadLong();

            fieldsStream.Seek(position);

            Document doc       = new Document();
            int      numFields = fieldsStream.ReadVInt();

            for (int i = 0; i < numFields; i++)
            {
                int       fieldNumber = fieldsStream.ReadVInt();
                FieldInfo fi          = fieldInfos.FieldInfo(fieldNumber);

                byte bits = fieldsStream.ReadByte();

                bool compressed = (bits & FieldsWriter.FIELD_IS_COMPRESSED) != 0;
                bool tokenize   = (bits & FieldsWriter.FIELD_IS_TOKENIZED) != 0;

                if ((bits & FieldsWriter.FIELD_IS_BINARY) != 0)
                {
                    byte[] b = new byte[fieldsStream.ReadVInt()];
                    fieldsStream.ReadBytes(b, 0, b.Length);
                    if (compressed)
                    {
                        doc.Add(new Field(fi.name, Uncompress(b), Field.Store.COMPRESS));
                    }
                    else
                    {
                        doc.Add(new Field(fi.name, b, Field.Store.YES));
                    }
                }
                else
                {
                    Field.Index index;
                    Field.Store store = Field.Store.YES;

                    if (fi.isIndexed && tokenize)
                    {
                        index = Field.Index.TOKENIZED;
                    }
                    else if (fi.isIndexed && !tokenize)
                    {
                        index = Field.Index.UN_TOKENIZED;
                    }
                    else
                    {
                        index = Field.Index.NO;
                    }

                    Field.TermVector termVector = null;
                    if (fi.storeTermVector)
                    {
                        if (fi.storeOffsetWithTermVector)
                        {
                            if (fi.storePositionWithTermVector)
                            {
                                termVector = Field.TermVector.WITH_POSITIONS_OFFSETS;
                            }
                            else
                            {
                                termVector = Field.TermVector.WITH_OFFSETS;
                            }
                        }
                        else if (fi.storePositionWithTermVector)
                        {
                            termVector = Field.TermVector.WITH_POSITIONS;
                        }
                        else
                        {
                            termVector = Field.TermVector.YES;
                        }
                    }
                    else
                    {
                        termVector = Field.TermVector.NO;
                    }

                    if (compressed)
                    {
                        store = Field.Store.COMPRESS;
                        byte[] b = new byte[fieldsStream.ReadVInt()];
                        fieldsStream.ReadBytes(b, 0, b.Length);
                        Field f = new Field(fi.name, System.Text.Encoding.GetEncoding("UTF-8").GetString(Uncompress(b)), store, index, termVector);
                        f.SetOmitNorms(fi.omitNorms);
                        doc.Add(f);
                    }
                    else
                    {
                        Field f = new Field(fi.name, fieldsStream.ReadString(), store, index, termVector);
                        f.SetOmitNorms(fi.omitNorms);
                        doc.Add(f);
                    }
                }
            }

            return(doc);
        }
Exemplo n.º 8
0
 public void AddField(string name, string value, Field.Store store, Field.Index index, Field.TermVector termVector)
 {
     fields.Add(new IndexFieldInfo(name, value, FieldInfoType.StringField, store, index, termVector));
 }
Exemplo n.º 9
0
        public /*internal*/ Document Doc(int n, string[] fields)
        {
            if (fields == null || fields.Length == 0)
            {
                return(Doc(n));
            }

            // FIXME: use Hashset
            ArrayList field_list          = new ArrayList(fields);
            int       num_required_fields = field_list.Count;

            indexStream.Seek(n * 8L);
            long position = indexStream.ReadLong();

            fieldsStream.Seek(position);

            Document doc       = new Document();
            int      numFields = fieldsStream.ReadVInt();

            for (int i = 0; i < numFields && num_required_fields > 0; i++)
            {
                int       fieldNumber = fieldsStream.ReadVInt();
                FieldInfo fi          = fieldInfos.FieldInfo(fieldNumber);
                if (field_list.Contains(fi.name))
                {
                    num_required_fields--;

                    byte bits = fieldsStream.ReadByte();

                    bool compressed = (bits & FieldsWriter.FIELD_IS_COMPRESSED) != 0;
                    bool tokenize   = (bits & FieldsWriter.FIELD_IS_TOKENIZED) != 0;

                    if ((bits & FieldsWriter.FIELD_IS_BINARY) != 0)
                    {
                        byte[] b = new byte[fieldsStream.ReadVInt()];
                        fieldsStream.ReadBytes(b, 0, b.Length);
                        if (compressed)
                        {
                            doc.Add(new Field(fi.name, Uncompress(b), Field.Store.COMPRESS));
                        }
                        else
                        {
                            doc.Add(new Field(fi.name, b, Field.Store.YES));
                        }
                    }
                    else
                    {
                        Field.Index index;
                        Field.Store store = Field.Store.YES;

                        if (fi.isIndexed && tokenize)
                        {
                            index = Field.Index.TOKENIZED;
                        }
                        else if (fi.isIndexed && !tokenize)
                        {
                            index = Field.Index.UN_TOKENIZED;
                        }
                        else
                        {
                            index = Field.Index.NO;
                        }

                        Field.TermVector termVector = null;
                        if (fi.storeTermVector)
                        {
                            if (fi.storeOffsetWithTermVector)
                            {
                                if (fi.storePositionWithTermVector)
                                {
                                    termVector = Field.TermVector.WITH_POSITIONS_OFFSETS;
                                }
                                else
                                {
                                    termVector = Field.TermVector.WITH_OFFSETS;
                                }
                            }
                            else if (fi.storePositionWithTermVector)
                            {
                                termVector = Field.TermVector.WITH_POSITIONS;
                            }
                            else
                            {
                                termVector = Field.TermVector.YES;
                            }
                        }
                        else
                        {
                            termVector = Field.TermVector.NO;
                        }

                        if (compressed)
                        {
                            store = Field.Store.COMPRESS;
                            byte[] b = new byte[fieldsStream.ReadVInt()];
                            fieldsStream.ReadBytes(b, 0, b.Length);
                            Field f = new Field(fi.name, System.Text.Encoding.GetEncoding("UTF-8").GetString(Uncompress(b)), store, index, termVector);
                            f.SetOmitNorms(fi.omitNorms);
                            doc.Add(f);
                        }
                        else
                        {
                            Field f = new Field(fi.name, fieldsStream.ReadString(), store, index, termVector);
                            f.SetOmitNorms(fi.omitNorms);
                            doc.Add(f);
                        }
                    }
                }
                else
                {
                    byte bits = fieldsStream.ReadByte();

                    bool compressed = (bits & FieldsWriter.FIELD_IS_COMPRESSED) != 0;
                    bool tokenize   = (bits & FieldsWriter.FIELD_IS_TOKENIZED) != 0;

                    if ((bits & FieldsWriter.FIELD_IS_BINARY) != 0)
                    {
                        //byte[] b = new byte[fieldsStream.ReadVInt()];
                        //fieldsStream.ReadBytes(b, 0, b.Length);
                        int length = fieldsStream.ReadVInt();
                        for (int j = 0; j < length; j++)
                        {
                            fieldsStream.ReadByte();
                        }
                    }
                    else
                    {
                        if (compressed)
                        {
                            //byte[] b = new byte[fieldsStream.ReadVInt()];
                            //fieldsStream.ReadBytes(b, 0, b.Length);
                            int length = fieldsStream.ReadVInt();
                            for (int j = 0; j < length; j++)
                            {
                                fieldsStream.ReadByte();
                            }
                        }
                        else
                        {
                            //fieldsStream.ReadString ();
                            int length = fieldsStream.ReadVInt();
                            for (int j = 0; j < length; j++)
                            {
                                byte b = fieldsStream.ReadByte();
                                if ((b & 0x80) == 0)
                                {
                                    continue;
                                }
                                else if ((b & 0xE0) != 0xE0)
                                {
                                    fieldsStream.ReadByte();
                                }
                                else
                                {
                                    fieldsStream.ReadByte();
                                    fieldsStream.ReadByte();
                                }
                            }
                        }
                    }
                }
            }

            return(doc);
        }
Exemplo n.º 10
0
 /// <summary> Get a list of unique field names that exist in this index, are indexed, and have
 /// the specified term vector information.
 ///
 /// </summary>
 /// <param name="tvSpec">specifies which term vector information should be available for the fields
 /// </param>
 /// <returns> Collection of Strings indicating the names of the fields
 ///
 /// </returns>
 /// <deprecated>  Replaced by {@link #GetFieldNames(IndexReader.FieldOption)}
 /// </deprecated>
 public abstract System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec);
Exemplo n.º 11
0
 public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
 {
     return(in_Renamed.GetIndexedFieldNames(tvSpec));
 }