示例#1
0
 /// <summary> <p>Removes all fields with the given name from the document.
 /// If there is no field with the specified name, the document remains unchanged.</p>
 /// <p> Note that the removeField(s) methods like the add method only make sense
 /// prior to adding a document to an index. These methods cannot
 /// be used to change the content of an existing index! In order to achieve this,
 /// a document has to be deleted from an index and a new changed version of that
 /// document has to be added.</p>
 /// </summary>
 public void  RemoveFields(System.String name)
 {
     for (int i = fields.Count - 1; i >= 0; i--)
     {
         Field field = (Field)fields[i];
         if (field.Name().Equals(name))
         {
             fields.RemoveAt(i);
         }
     }
 }
示例#2
0
 /// <summary> Returns an array of bytes for the first (or only) field that has the name
 /// specified as the method parameter. This method will return <code>null</code>
 /// if no binary fields with the specified name are available.
 /// There may be non-binary fields with the same name.
 ///
 /// </summary>
 /// <param name="name">the name of the field.
 /// </param>
 /// <returns> a <code>byte[]</code> containing the binary field value.
 /// </returns>
 public byte[] GetBinaryValue(System.String name)
 {
     for (int i = 0; i < fields.Count; i++)
     {
         Field field = (Field)fields[i];
         if (field.Name().Equals(name) && (field.IsBinary()))
         {
             return(field.BinaryValue());
         }
     }
     return(null);
 }
示例#3
0
 /// <summary>Returns a field with the given name if any exist in this document, or
 /// null.  If multiple fields exists with this name, this method returns the
 /// first value added.
 /// </summary>
 public Field GetField(System.String name)
 {
     for (int i = 0; i < fields.Count; i++)
     {
         Field field = (Field)fields[i];
         if (field.Name().Equals(name))
         {
             return(field);
         }
     }
     return(null);
 }
示例#4
0
 /// <summary> <p>Removes field with the specified name from the document.
 /// If multiple fields exist with this name, this method removes the first field that has been added.
 /// If there is no field with the specified name, the document remains unchanged.</p>
 /// <p> Note that the removeField(s) methods like the add method only make sense
 /// prior to adding a document to an index. These methods cannot
 /// be used to change the content of an existing index! In order to achieve this,
 /// a document has to be deleted from an index and a new changed version of that
 /// document has to be added.</p>
 /// </summary>
 public void  RemoveField(System.String name)
 {
     System.Collections.IEnumerator it = fields.GetEnumerator();
     while (it.MoveNext())
     {
         Field field = (Field)it.Current;
         if (field.Name().Equals(name))
         {
             fields.Remove(field);
             return;
         }
     }
 }
示例#5
0
        /// <summary> Returns an array of byte arrays for of the fields that have the name specified
        /// as the method parameter. This method will return <code>null</code> if no
        /// binary fields with the specified name are available.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a  <code>byte[][]</code> of binary field values.
        /// </returns>
        public byte[][] GetBinaryValues(System.String name)
        {
            System.Collections.IList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Field field = (Field)fields[i];
                if (field.Name().Equals(name) && (field.IsBinary()))
                {
                    byte[] byteArray       = field.BinaryValue();
                    byte[] resultByteArray = new byte[byteArray.Length];
                    for (int index = 0; index < byteArray.Length; index++)
                    {
                        resultByteArray[index] = (byte)byteArray[index];
                    }

                    result.Add(resultByteArray);
                }
            }

            if (result.Count == 0)
            {
                return(null);
            }

            System.Collections.ICollection c = result;
            System.Object[] objects          = new byte[result.Count][];

            System.Type     type = objects.GetType().GetElementType();
            System.Object[] objs = (System.Object[])Array.CreateInstance(type, c.Count);

            System.Collections.IEnumerator e = c.GetEnumerator();
            int ii = 0;

            while (e.MoveNext())
            {
                objs[ii++] = e.Current;
            }

            // If objects is smaller than c then do not return the new array in the parameter
            if (objects.Length >= c.Count)
            {
                objs.CopyTo(objects, 0);
            }

            return((byte[][])objs);
        }
示例#6
0
        /// <summary> Returns an array of values of the field specified as the method parameter.
        /// This method can return <code>null</code>.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>String[]</code> of field values
        /// </returns>
        public System.String[] GetValues(System.String name)
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Field field = (Field)fields[i];
                if (field.Name().Equals(name) && (!field.IsBinary()))
                {
                    result.Add(field.StringValue());
                }
            }

            if (result.Count == 0)
            {
                return(null);
            }

            return((System.String[])(result.ToArray(typeof(System.String))));
        }
示例#7
0
        /// <summary> Returns an array of {@link Field}s with the given name.
        /// This method can return <code>null</code>.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>Field[]</code> array
        /// </returns>
        public Field[] GetFields(System.String name)
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Field field = (Field)fields[i];
                if (field.Name().Equals(name))
                {
                    result.Add(field);
                }
            }

            if (result.Count == 0)
            {
                return(null);
            }

            return((Field[])result.ToArray(typeof(Field)));
        }
示例#8
0
        /// <summary> Returns an array of {@link Field}s with the given name.
        /// Do not use with lazy loaded fields.
        /// This method returns an empty array when there are no
        /// matching fields.  It never returns null.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>Field[]</code> array
        /// </returns>
        public Field[] GetFields(System.String name)
        {
            List <Field> result = new List <Field>();

            for (int i = 0; i < fields.Count; i++)
            {
                Field field = (Field)fields[i];
                if (field.Name().Equals(name))
                {
                    result.Add(field);
                }
            }

            if (result.Count == 0)
            {
                return(NO_FIELDS);
            }

            return(result.ToArray());
        }
示例#9
0
		private static KeyValuePair<string, RavenJToken> CreateProperty(Field fld, Document document)
		{
			var stringValue = fld.StringValue();
			if (document.GetField(fld.Name() + "_ConvertToJson") != null)
			{
				var val = RavenJToken.Parse(fld.StringValue()) as RavenJObject;
				return new KeyValuePair<string, RavenJToken>(fld.Name(), val);
			}
			if (stringValue == Constants.NullValue)
				stringValue = null;
			if (stringValue == Constants.EmptyString)
				stringValue = string.Empty; 
			return new KeyValuePair<string, RavenJToken>(fld.Name(), stringValue);
		}
示例#10
0
                static protected Property GetPropertyFromDocument (Field f, Document doc, bool from_primary_index)
                {
                        // Note: we don't use the document that we pass in,
                        // but in theory we could.  At some later point we
                        // might need to split a property's data across two or
                        // more fields in the document.

                        if (f == null)
                                return null;

                        bool internal_prop = false;

                        string field_name;
                        field_name = f.Name ();
                        if (field_name.Length < 7
                            || ! field_name.StartsWith ("prop:")) {
                                if (DumpIndexMode)
                                        internal_prop = true;
                                else
                                        return null;
                        }

                        string field_value;
                        field_value = f.StringValue ();

                        Property prop;
                        prop = new Property ();

                        if (DumpIndexMode) {
                                prop.Type = CodeToType ( internal_prop ? 'k' : field_name [5]);
                                prop.Key = (internal_prop ? field_name : field_name.Substring (7));
                                prop.Value = (internal_prop ? field_value : field_value.Substring (3));
                        } else {
                                prop.Type = CodeToType (field_name [5]);
                                prop.Key = field_name.Substring (7);
                                prop.Value = field_value.Substring (3);
                        }

                        prop.IsSearched = (field_value [0] == 's');
                        prop.IsPersistent = (field_value [1] == 'p');
                        prop.IsMutable = ! from_primary_index;
                        prop.IsStored = true; // Unstored fields cannot be retrieved

                        return prop;
                }
示例#11
0
		private static JProperty CreateProperty(Field fld, Document document)
		{
			var stringValue = fld.StringValue();
			if (document.GetField(fld.Name() + "_ConvertToJson") != null)
			{
				object val = JsonConvert.DeserializeObject(stringValue);
				return new JProperty(fld.Name(), val);
			}
			if (stringValue == Constants.NullValue)
				stringValue = null;
			return new JProperty(fld.Name(), stringValue);
		}
示例#12
0
文件: Index.cs 项目: dplaskon/ravendb
 private static JProperty CreateProperty(Field fld, Document document)
 {
     if (document.GetField(fld.Name() + "_ConvertToJson") != null)
     {
         var val = JsonConvert.DeserializeObject(fld.StringValue());
         return new JProperty(fld.Name(), val);
     }
     return new JProperty(fld.Name(), fld.StringValue());
 }
		// FIXME: This basically queries the value against the field
		// and is really really slow!
		private bool FieldIsPredicate (Field field, string value)
		{
			string field_name = field.Name ();
			string field_value = field.StringValue ();
			Console.WriteLine ("Reverse searching for '{0}' value in {1}='{2}'", value, field_name, field_value);
			// Simply run the value of the property against the right analyzer
			// and check if there is any match
			TokenStream source = IndexingAnalyzer.TokenStream (field_name, new StringReader (field_value));
			StringBuilder sb = new StringBuilder ();
			try {
				Lucene.Net.Analysis.Token token;
				while (true) {
					token = source.Next ();
					if (token == null)
						break;
					sb.Append (token.TermText ());
					sb.Append (" ");
					break;
				}
			} finally {
				try {
					source.Close ();
				} catch { }
			}

			string field_analyzed = sb.ToString ();
			sb.Length = 0;

			source = QueryAnalyzer.TokenStream (field_name, new StringReader (value));
			try {
				Lucene.Net.Analysis.Token token;
				while (true) {
					token = source.Next ();
					if (token == null)
						break;
					sb.Append (token.TermText ());
					sb.Append (" ");
					break;
				}
			} finally {
				try {
					source.Close ();
				} catch { }
			}

			string value_analyzed = sb.ToString ();
			return field_analyzed.Contains (value_analyzed);
		}
示例#14
0
 public SearchField(Field field, IndexField properties)
     : this(field.Name(), properties.Caption, field.StringValue(), field.StringValue(), properties.Boost, properties.IsTitle, true, properties.Order)
 { 
 }
示例#15
0
 public SearchField(Field field, string caption, bool isTitle)
     : this(field.Name(), caption, field.StringValue(), field.StringValue(), field.GetBoost(), isTitle, true, 0)
 { 
 }
示例#16
0
 public SearchField(Field field)
     : this(field.Name(), field.Name(), field.StringValue(), field.StringValue(), field.GetBoost(), false, false, 0)
 { 
 }