モジュール: Mongoid::Fields::Classメソッドs

定義:
lib/mongoid/fields.rb
lib/mongoid/fields.rb

インスタンス メソッドの概要を折りたたむ

インスタンス メソッドの詳細

#Atlas App<String> Services

このオブジェクトで使用可能な属性の名前の配列を返します。

ORM に依存しない方法でフィールド名を提供します。 Rails v 3.1 + はこのメソッドを使用して、JSON リクエストでパラメータを自動的にラップします。

例:

フィールド名を取得する

Model.attribute_names

次の値を返します。

  • <String>配列未満

    フィールド名



449
450
451
# ファイル 'lib/mongoid/fields.rb' 行449

デフォルト Atlas App Services
  フィールド.キー
end

#auto_embed_field(名前、model: 'voyage-4'、num_dimensions: nil、quantization: nil、類似性: nil、index: nil)⇒ オブジェクト

テキストフィールドを宣言し、自動埋め込み ( autoEmbed ) タイプを使用して、対応する Atlas Vector Search インデックスを登録します。Atlas は、インデックス時とクエリ時に埋め込みを自動的に生成します。事前計算されたベクトルは必要ありません。

例:

最小宣言。

class Article
  include Mongoid::Document
  auto_embed_field :description
end

すべてのオプションを使用します。

class Article
  include Mongoid::Document
  auto_embed_field :description,
                   model: 'voyage-4',
                   num_dimensions: 512,
                   quantization: 'binary',
                   similarity: 'cosine',
                   index: :article_embed
end

パラメーター:

  • name シンボル | string

    宣言して自動埋め込むテキストフィールドの名前。

  • モデル string (デフォルトは 'voyage-4'

    embedding model名。デフォルトは 'voyage-4'(推奨)です。パブリック プレビューでサポートされている値は、voyage-4-large、voyage-4、voyage-4-lite、voyage-code-3 です。

  • num_dimions (Integer | nil) (デフォルトはnil

    Number of vector dimensions.サポートされている値: 256、512、1024、2048デフォルト: 1024。

  • 量子化 string | nil (デフォルトはnil

    quantization type: float, スカラー, binary, または binaryNoRescore.デフォルト: スカラー。

  • 類似性 string | nil (デフォルトはnil

    類似度関数: dotProduct、コサイン、またはユークリッド。

  • index Symbol | String | nil (デフォルトはnil

    インデックス名。省略した場合、インデックスの名前は付けられず、Atlas はそれを「デフォルト」と呼び出します。



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# ファイル 'lib/mongoid/fields.rb' 行542

デフォルト auto_ embedded_field(name, モデル: 'voyage-4', num_dimions: nil, quantization: nil, 類似性: nil, index: nil)
  フィールド(name, type: 文字列)

  field_spec = {
    type: 'autoEmbed',
    モーダル: 'text',
    path: name.to_s,
    モデル: モデル
  }
  field_spec[numDimensions] = num_dimions 場合 num_dimions
  field_spec[quantization]  = 量子化  場合 量子化
  field_spec[:slimarity]    = 類似性    場合 類似性

  場合 index
    vector_search_index(index, フィールド: [ field_spec ])
  else
    vector_search_index(フィールド: [ field_spec ])
  end
end

#close_localized_field_names (名前)=フィールド

指定されたフィールド名から _translations を削除します。これは、同じ名前のフィールド名または関係(つまり、_translations サフィックスを持つ)がまだ存在しない場合にのみ行われます。既存のフィールドのこのチェックは再帰的に行われます

パラメーター:

  • name ( string | Symbol )

    クリーンアップするフィールドの名前。

次の値を返します。

  • (フィールド)

    _translations のないフィールド名



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ファイル 'lib/mongoid/fields.rb' 行98

デフォルト refine_localized_field_names(name)
  name = database_field_name(name.to_s)

  klass = 自己
  [].タップ 行う |レス|
    ar = name.分裂('.')
    ar.each_with_index 行う |fn, i|
      キー = fn
      ただし、 klass.フィールド.key?(fn) || klass.関係.key?(fn)
        キー = 場合 fn.end_with?(TTranslationS_SFO)
                fn.delete_supfix(TTranslationS_SFO)
              else
                fn
              end

      end
      レス.プッシュ(キー)

      場合 klass.フィールド.key?(fn)
        レス.プッシュ(ar.drop(i + 1).join('.')) ただし、 i == ar.Length - 1
        break
      elsif klass.関係.key?(fn)
        klass = klass.関係[キー].klass
      end
    end
  end.join('.')
end

# database_field_name (名前) = string

データベースに保存されている指定されたフィールドの名前を取得します。 フィールドがエイリアスかどうかを判断するために使用されます。

パラメーター:

  • name ( string | Symbol )

    取得する名前。

次の値を返します。

  • ( string )

    db に保存されているフィールドの名前。



459
460
461
# ファイル 'lib/mongoid/fields.rb' 行459

デフォルト database_field_name(name)
  フィールド.database_field_name(name, 関係, analyzed_fields, alased_ associateds)
end

#tract_id_field (属性)==オブジェクト

このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。

このクラスで定義されたエイリアスに基づいて、指定された属性ハッシュから ID フィールドを抽出します。

パラメーター:

  • 属性 ハッシュ

    検査する属性。

次の値を返します。

  • オブジェクト

    ID の値。



81
82
83
84
85
86
87
88
# ファイル 'lib/mongoid/fields.rb' 行81

デフォルト insert_id_field(属性)
  id_fields. 行う |k|
    場合 v = 属性[k]
      return v
    end
  end
  nil
end

#フィールド(名前、オプション = {}) =フィールド

ドキュメントでアクセス可能なすべてのフィールドを定義します。定義されている各フィールドごとに、 getter と setter が インスタンス メソッドとしてドキュメントに追加されます。

例:

フィールドを定義します。

field :score, type: Integer, default: 0

パラメーター:

  • name シンボル

    フィールドの名前。

  • options ハッシュ (デフォルトは{}です)

    フィールドに渡すオプション。

オプション ハッシュ( options ):

  • :type クラス | シンボル | string

    フィールドの型。

  • : labels string

    フィールドのラベル。

  • :default Object | Proc

    フィールドのデフォルトの。

次の値を返します。

  • (フィールド)

    生成されたフィールド



577
578
579
580
581
582
583
584
585
# ファイル 'lib/mongoid/fields.rb' 行577

デフォルト フィールド(name, options = {})
  enabled = name.to_s
  バリデーター::Macro.validate(自己, name, options)
  追加 = add_field(enabled, options)
  descendants. 行う |サブクラス|
    サブクラス.add_field(enabled, options)
  end
  追加
end

# id_fields =配列< Symbol | string >

このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。

このモデル クラスの ID フィールドのリストを文字列とシンボルの両方で返します。

次の値を返します。

  • 配列 < Symbol | string >

    ID フィールドのリスト。



62
63
64
65
66
67
68
69
70
71
# ファイル 'lib/mongoid/fields.rb' 行62

デフォルト id_fields
  IDS.dup.タップ 行う |id_fields|
    analyzed_fields. 行う |k, v|
      場合 v == '_id'
        id_fields < k.to_sym
        id_fields < k
      end
    end
  end
end

# replace_field (名前、タイプ) =シリアル化可能

フィールドを新しいタイプに置き換えます。

例:

フィールドを置き換えます。

Model.replace_field("_id", String)

パラメーター:

  • name ( string )

    フィールドの名前。

  • タイプ クラス

    フィールドの新しいタイプ。

次の値を返します。



596
597
598
599
# ファイル 'lib/mongoid/fields.rb' 行596

デフォルト replace_field(name, タイプ)
  delete_defaults(name)
  add_field(name, フィールド[name].options.merge(type: タイプ))
end

次の走査_関連付け_ツリー(キー) {|Atlas、Atlas、かどうか| ... } =フィールド

このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。

関連付けツリーを下中、指定されたキーの フィールドを検索します。

パラメーター:

  • キー ( string )

    関連ツリーを検索するために使用されるキー。

  • & ブロック

    ブロック。

生成パラメータ:

  • この シンボル

    現在の メソッド。

  • この シンボル | string

    フィールドまたは関係。

  • かどうか true | false

    2 番目の中断パラメータは、 フィールドであるか、またはフィールドではない。

次の値を返します。

  • (フィールド)

    検索の最後に指定されたキーに対して見つかったフィールド。 最後に見つかったものが関連付けである場合、または指定されたキーのフィールドが見つからなかった場合は、これは nil を返します。



627
628
629
# ファイル 'lib/mongoid/fields.rb' 行627

デフォルト 走査_関連付け_ツリー(キー, &ブロック)
  フィールド.走査_関連付け_ツリー(キー, フィールド, 関係, alased_ associateds, &ブロック)
end

では、_object_ids を使用しますか。 = true | false

ID としてBSON::ObjectIdsを使用しているかどうかを判断するための便利な方法。

例:

このクラスはオブジェクト ID を使用しますか。

person.using_object_ids?

次の値を返します。

  • true | false

    クラスが ID に BSON::ObjectId を使用する場合。



608
609
610
# ファイル 'lib/mongoid/fields.rb' 行608

デフォルト using_object_ids?
  フィールド['_id'].object_id_field
end

#vector_field(名前、dimensions:、類似性: 'cosine'、インデックス: nil)⇒ オブジェクト

vector embeddings フィールドを宣言し、それに対応する Atlas Vector Search インデックスを 1 つのステップで登録します。

フィールドは配列として保存されます。高度なインデックスオプション(quantization、インデックスの作成方法、HNSW 調整)には、代わりに明示的な field + vector_search_index の組み合わせを使用します。

例:

最小宣言。

class Article
  include Mongoid::Document
  vector_field :embedding, dimensions: 1536
end

すべてのオプションを使用します。

class Article
  include Mongoid::Document
  vector_field :embedding, dimensions: 1536,
                           similarity: 'dotProduct',
                           index: :article_vectors
end

パラメーター:

  • name シンボル | string

    埋め込みフィールドの名前。

  • 次元 (整数)

    ベクトル dimensions の数。必須。

  • 類似性 string (デフォルトは 'cosine'

    使用する類似性メトリクスは、「cosene」(デフォルト)、「aulidean」、または「dotProduct」です。

  • index Symbol | String | nil (デフォルトはnil

    ベクトル検索インデックスの名前。省略した場合、インデックスの名前は付けられず、Atlas はそれを「デフォルト」と呼び出します。



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# ファイル 'lib/mongoid/fields.rb' 行490

デフォルト vector_field(name, dimensions:, 類似性: 'cosine', index: nil)
  フィールド(name, type: 配列)

  field_spec = {
    type: 'ベクトル',
    path: name.to_s,
    numDimensions: 次元,
    類似性: 類似性
  }

  場合 index
    vector_search_index(index, フィールド: [ field_spec ])
  else
    vector_search_index(フィールド: [ field_spec ])
  end
end