You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
Copy file name to clipboardExpand all lines: docs/migrations.rst
+38-57Lines changed: 38 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,34 +4,47 @@ Migrations
4
4
5
5
.. important::
6
6
7
-
If you're not familiar with django Migrations, please check `Migrations Documentation <https://docs.djangoproject.com/en/1.7/topics/migrations/>`_ 1st.
7
+
If you're not familiar with django Migrations, please check `django Migrations Documentation <https://docs.djangoproject.com/en/1.7/topics/migrations/>`_ 1st.
8
8
9
9
10
10
.. important::
11
11
12
12
The order of Migrations.operations matters, you can only apply a index to a field if a field exists, if you delete a model/field you should remove any operation first before removing model/field.
13
13
14
14
15
-
Creating
16
-
--------
17
-
18
-
Trigger
19
-
*******
15
+
BaseVectorOperation options
16
+
***************************
20
17
21
-
For creating of trigger is provided :class:`~pg_fts.migrations.CreateFTSTriggerOperation`.
18
+
The following arguments are available to all FTSMigration types
For creating of trigger is provided :class:`~pg_fts.migrations.CreateFTSTriggerOperation`.
42
+
43
+
``CreateFTSTriggerOperation``
44
+
-----------------------------
45
+
46
+
.. class:: CreateFTSTriggerOperation(options**)
47
+
35
48
How it works
36
49
++++++++++++
37
50
@@ -91,20 +104,9 @@ Index
91
104
92
105
For creating of indexes is provided :class:`~pg_fts.migrations.CreateFTSIndexOperation`.
93
106
94
-
``name``
95
-
96
-
.. attribute:: CreateFTSIndexOperation.name
97
-
98
-
Name of the model
99
-
100
-
``fts_vector``
101
-
102
-
.. attribute:: CreateFTSIndexOperation.fts_vector
103
-
104
-
Name of the :class:`~pg_fts.fields.TSVectorField`
105
-
106
107
107
108
``index``
109
+
---------
108
110
109
111
.. attribute:: CreateFTSIndexOperation.index
110
112
@@ -116,24 +118,26 @@ Options:
116
118
117
119
For information about the ``gin`` and ``gist`` indexes types consult :pg_docs:`PostgreSQL documentation 12.9. GiST and GIN Index Types <textsearch-indexes.html>`
118
120
121
+
Example::
119
122
120
-
Migrating from existing application
121
-
-----------------------------------
122
-
123
-
For existing application with data is provided :class:`~pg_fts.migrations.UpdateVectorOperation`, this will update the vector.
124
-
125
-
``name``
126
-
127
-
.. attribute:: UpdateVectorOperation.name
128
-
129
-
Name of the model
123
+
class Migration(migrations.Migration)
124
+
dependencies = [
125
+
('article', '0003_fts_create_field'),
126
+
]
130
127
131
-
``fts_vector``
128
+
operations = [
129
+
CreateFTSIndexOperation(
130
+
name='Article',
131
+
fts_vector='fts_index',
132
+
index='gin'
133
+
),
134
+
]
132
135
133
-
.. attribute:: UpdateVectorOperation.fts_vector
134
136
135
-
Name of the :class:`~pg_fts.fields.TSVectorField`
137
+
Migrating from existing application
138
+
-----------------------------------
136
139
140
+
For existing application with data is provided :class:`~pg_fts.migrations.UpdateVectorOperation`, this will update the vector.
137
141
138
142
Changing and Removing
139
143
---------------------
@@ -184,38 +188,15 @@ Removing Index
184
188
185
189
For removing the index is provided :class:`~pg_fts.migrations.DeleteFTSIndexOperation`.
186
190
187
-
``name``
188
-
189
-
.. attribute:: DeleteFTSIndexOperation.name
190
-
191
-
Name of the model
192
-
193
-
``fts_vector``
194
-
195
-
.. attribute:: DeleteFTSIndexOperation.fts_vector
196
-
197
-
Name of the :class:`~pg_fts.fields.TSVectorField`
198
-
199
-
The previous index type, important for regressions.
200
191
201
192
``index``
193
+
---------
202
194
203
195
.. attribute:: CreateFTSIndexOperation.index
204
196
197
+
The previous index type, important for regressions.
205
198
206
199
Removing Trigger
207
200
****************
208
201
209
202
For removing the index is provided :class:`~pg_fts.migrations.DeleteFTSTriggerOperation`.
The following arguments are available to all FTSRank types
11
+
12
+
``lookup``
13
+
----------
14
+
15
+
.. attribute:: FTSRank.lookup
16
+
17
+
The :class:`~pg_fts.fields.TSVectorField` and its available lookup's ``search``, ``isearch`` and ``tsquery``.
18
+
19
+
Will raise exception if lookup isn't valid.
20
+
21
+
.. seealso::
22
+
23
+
For :class:`~pg_fts.fields.TSVectorField` lookups check :doc:`TSVectorField lookups</tsvector_field>`
24
+
25
+
``normalization``
26
+
-----------------
27
+
28
+
.. attribute:: FTSRank.normalization
29
+
30
+
A list or tuple of integers with the normalization values, can be used a bit mask
31
+
``[1,2]`` will be converted to ``1|2`` in sql.
32
+
33
+
34
+
Accepted Values = 0, 1, 2, 4, 8, 16, 32
35
+
36
+
Default is PostgresSQL function default.
37
+
38
+
Will raise exception if ``normalization`` isn't valid.
39
+
40
+
``weights``
41
+
-----------
42
+
43
+
.. attribute:: FTSRank.weights
44
+
45
+
A list or tuple of integers/floats [D-weight, C-weight, B-weight, A-weight] with the weight values ``[0.1, 0.2, 0.4, 1]`` will be converted to ``{0.1, 0.2, 0.4, 1.0}`` in sql.
46
+
47
+
Default is PostgresSQL function default.
48
+
49
+
Will raise exception if ``weights`` isn't valid.
50
+
51
+
.. seealso::
52
+
53
+
More about ``normalization`` and ``weights`` check PostgreSQL documentation :pg_docs:`12.3.3. Ranking Search Results <textsearch-controls.html#TEXTSEARCH-RANKING>`
54
+
55
+
56
+
``FTSRank``
57
+
***********
58
+
59
+
.. class:: FTSRank(**options)
60
+
61
+
Uses PostgreSQL ``ts_rank`` function, ranks on frequency of matching lexemes.
62
+
63
+
Examples:
64
+
65
+
Search and order by rank::
66
+
67
+
Article.objects.annotate(
68
+
rank=(FTSRank(fts__search='once upon a time'))).order_by('-rank')
69
+
70
+
Search and with normalization::
71
+
72
+
Article.objects.annotate(
73
+
normalized=(FTSRank(
74
+
fts__search='once upon a time',
75
+
noramlization=(1,2)
76
+
))).order_by('-normalized')
77
+
78
+
79
+
``FTSRankCd``
80
+
*************
81
+
82
+
.. class:: FTSRankCd(**options)
83
+
84
+
Uses PostgreSQL ``ts_rank_cd`` function, ranks over cover density.
85
+
86
+
Usage is the same as FTSRank, just with this class.
87
+
88
+
Multiple dictionaries support
89
+
*****************************
90
+
91
+
For this case there are two classes ``FTSRankDictionay``, ``FTSRankCdDictionary``.
92
+
93
+
The usage is the same as normal ``FTSRank`` or ``FTSRankCd``, was added the special support for lookups with dictionary transformation.
0 commit comments