예제 #1
0
        public static IndexableField InstantiateSortField(string key, object value)
        {
            IndexableField field;

            if (value is Number)
            {
                Number number = ( Number )value;
                if (value is float?)
                {
                    field = new SortedNumericDocValuesField(key, NumericUtils.floatToSortableInt(number.floatValue()));
                }
                else if (value is double?)
                {
                    field = new SortedNumericDocValuesField(key, NumericUtils.doubleToSortableLong(number.doubleValue()));
                }
                else
                {
                    field = new SortedNumericDocValuesField(key, number.longValue());
                }
            }
            else
            {
                if (LuceneExplicitIndex.KEY_DOC_ID.Equals(key))
                {
                    field = new NumericDocValuesField(key, long.Parse(value.ToString()));
                }
                else
                {
                    field = new SortedSetDocValuesField(key, new BytesRef(value.ToString()));
                }
            }
            return(field);
        }
예제 #2
0
        /// <summary>
        /// Adds a new <see cref="SortedSetDocValuesField"/> field. </summary>
        /// <remarks>
        /// If you also need to store the value, you should add a
        /// separate <see cref="StoredField"/> instance.
        /// </remarks>
        /// <param name="document">This <see cref="Document"/>.</param>
        /// <param name="name"> field name </param>
        /// <param name="bytes"> binary content </param>
        /// <returns>The field that was added to this <see cref="Document"/>.</returns>
        /// <exception cref="System.ArgumentNullException"> if the field <paramref name="name"/> is <c>null</c> </exception>
        public static SortedSetDocValuesField AddSortedSetDocValuesField(this Document document, string name, BytesRef bytes)
        {
            var field = new SortedSetDocValuesField(name, bytes);

            document.Add(field);
            return(field);
        }
예제 #3
0
        /// <summary>
        /// Adds a new <see cref="SortedSetDocValuesField"/> field. </summary>
        /// <remarks>
        /// If you also need to store the value, you should add a
        /// separate <see cref="StoredField"/> instance.
        /// </remarks>
        /// <param name="document">This <see cref="Document"/>.</param>
        /// <param name="name"> field name </param>
        /// <param name="bytes"> binary content </param>
        /// <returns>The field that was added to this <see cref="Document"/>.</returns>
        /// <exception cref="ArgumentNullException"> if this <paramref name="document"/>, the field <paramref name="name"/> is <c>null</c>. </exception>
        public static SortedSetDocValuesField AddSortedSetDocValuesField(this Document document, string name, BytesRef bytes)
        {
            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            var field = new SortedSetDocValuesField(name, bytes);

            document.Add(field);
            return(field);
        }