Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 2827d76

Browse files
committed
added docs to ranks and vector field
1 parent 47f0ef3 commit 2827d76

File tree

7 files changed

+298
-192
lines changed

7 files changed

+298
-192
lines changed

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ Features:
2727
Contents:
2828

2929
.. toctree::
30-
:maxdepth: 4
30+
:maxdepth: 2
3131

3232
install
3333
tutorial
3434
migrations
35+
ranks
36+
tsvector_field
3537
pg_fts
3638

3739

docs/migrations.rst

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,47 @@ Migrations
44

55
.. important::
66

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.
88

99

1010
.. important::
1111

1212
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.
1313

1414

15-
Creating
16-
--------
17-
18-
Trigger
19-
*******
15+
BaseVectorOperation options
16+
***************************
2017

21-
For creating of trigger is provided :class:`~pg_fts.migrations.CreateFTSTriggerOperation`.
18+
The following arguments are available to all FTSMigration types
2219

2320
``name``
21+
--------
2422

2523
.. attribute:: CreateFTSTriggerOperation.name
2624

2725
Name of the model
2826

2927
``fts_vector``
28+
--------------
3029

3130
.. attribute:: CreateFTSTriggerOperation.fts_vector
3231

3332
Name of the :class:`~pg_fts.fields.TSVectorField`
3433

34+
35+
Creating
36+
--------
37+
38+
Trigger
39+
*******
40+
41+
For creating of trigger is provided :class:`~pg_fts.migrations.CreateFTSTriggerOperation`.
42+
43+
``CreateFTSTriggerOperation``
44+
-----------------------------
45+
46+
.. class:: CreateFTSTriggerOperation(options**)
47+
3548
How it works
3649
++++++++++++
3750

@@ -91,20 +104,9 @@ Index
91104

92105
For creating of indexes is provided :class:`~pg_fts.migrations.CreateFTSIndexOperation`.
93106

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-
106107

107108
``index``
109+
---------
108110

109111
.. attribute:: CreateFTSIndexOperation.index
110112

@@ -116,24 +118,26 @@ Options:
116118

117119
For information about the ``gin`` and ``gist`` indexes types consult :pg_docs:`PostgreSQL documentation 12.9. GiST and GIN Index Types <textsearch-indexes.html>`
118120

121+
Example::
119122

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+
]
130127

131-
``fts_vector``
128+
operations = [
129+
CreateFTSIndexOperation(
130+
name='Article',
131+
fts_vector='fts_index',
132+
index='gin'
133+
),
134+
]
132135

133-
.. attribute:: UpdateVectorOperation.fts_vector
134136

135-
Name of the :class:`~pg_fts.fields.TSVectorField`
137+
Migrating from existing application
138+
-----------------------------------
136139

140+
For existing application with data is provided :class:`~pg_fts.migrations.UpdateVectorOperation`, this will update the vector.
137141

138142
Changing and Removing
139143
---------------------
@@ -184,38 +188,15 @@ Removing Index
184188

185189
For removing the index is provided :class:`~pg_fts.migrations.DeleteFTSIndexOperation`.
186190

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.
200191

201192
``index``
193+
---------
202194

203195
.. attribute:: CreateFTSIndexOperation.index
204196

197+
The previous index type, important for regressions.
205198

206199
Removing Trigger
207200
****************
208201

209202
For removing the index is provided :class:`~pg_fts.migrations.DeleteFTSTriggerOperation`.
210-
211-
``name``
212-
213-
.. attribute:: DeleteFTSTriggerOperation.name
214-
215-
Name of the model
216-
217-
``fts_vector``
218-
219-
.. attribute:: DeleteFTSTriggerOperation.fts_vector
220-
221-
Name of the :class:`~pg_fts.fields.TSVectorField`

docs/ranks.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Ranking
2+
=======
3+
4+
.. .. module:: pg_fts.ranks
5+
.. :synopsis: Built-in rank types.
6+
7+
RankBase options
8+
****************
9+
10+
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

Comments
 (0)