Skip to content

Commit 9371990

Browse files
authored
Merge pull request plone#1225 from plone/polish-indexing
Spruce up Backend - Indexing chapter
2 parents 255c876 + ff98953 commit 9371990

File tree

1 file changed

+65
-50
lines changed

1 file changed

+65
-50
lines changed

docs/backend/indexing.md

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ html_meta:
33
"description": "Using Plone's catalog to index content and make it searchable."
44
"property=og:description": "Using Plone's catalog to index content and make it searchable."
55
"property=og:title": "Indexing"
6-
"keywords": "indexing, indexes, indexer, catalog, searching, FieldIndex, SearchableText, textindexer"
6+
"keywords": "Plone, indexing, indexes, indexer, catalog, searching, FieldIndex, KeywordIndex, DateIndex, DateRangeIndex, BooleanIndex, ZCTextIndex, SearchableText, textindexer"
77
---
88

99
(backend-indexing-label)=
@@ -12,44 +12,51 @@ html_meta:
1212

1313
To make Plone content searchable, one can use different indexes to index content.
1414

15-
The most important index types are:
15+
The most important index types are the following.
1616

1717
- `FieldIndex`
1818
- `KeywordIndex`
1919
- `DateIndex`
20-
- `DateRangeindex`
20+
- `DateRangeIndex`
2121
- `BooleanIndex`
2222
- `ZCTextIndex`
2323

24-
The most important indexes are:
24+
The most important indexes are described in the following sections.
2525

26-
## `SearchableText`
2726

28-
The `SearchableText` is a `ZCTextIndex` for indexing full text and is used by default for `Dublin core` fields like Title, Description and Text.
27+
(backend-indexing-searchabletext-label)=
28+
29+
## `SearchableText`
2930

30-
### TextIndexer
31+
The `SearchableText` is a `ZCTextIndex` for indexing full text.
32+
It is used by default for Dublin Core fields such as `Title`, `Description`, and `Text`.
3133

32-
To add other fields to the `SearchableText`, one can use the `plone.app.dexterity.textindexer`.
3334

34-
For enabling the indexer just add the behavior to the list of behaviors of your content types.
35+
(backend-indexing-textindexer-label)=
3536

36-
In your *profiles/default/types/YOURTYPE.xml* add the behavior::
37+
## `TextIndexer`
3738

38-
<?xml version="1.0"?>
39-
<object name="example.conference.presenter" meta_type="Dexterity FTI"
40-
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
41-
i18n:domain="example.conference">
39+
To add other fields to the `SearchableText`, one can use the `plone.app.dexterity.textindexer`.
4240

43-
<!-- enabled behaviors -->
44-
<property name="behaviors" purge="false">
45-
<element value="plone.textindexer" />
46-
</property>
41+
For enabling the indexer, add the behavior to the list of behaviors of your content types.
4742

48-
</object>
43+
In your `profiles/default/types/YOURTYPE.xml` add the behavior.
4944

45+
```xml
46+
<?xml version="1.0"?>
47+
<object name="example.conference.presenter" meta_type="Dexterity FTI"
48+
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
49+
i18n:domain="example.conference">
50+
51+
<!-- enabled behaviors -->
52+
<property name="behaviors" purge="false">
53+
<element value="plone.textindexer" />
54+
</property>
55+
</object>
56+
```
5057

5158
Now you need to mark the fields you want to have in your SearchableText.
52-
This can be done with the searchable directive:
59+
This can be done with the `searchable` directive.
5360

5461
```python
5562
from plone.app.dexterity import textindexer
@@ -63,7 +70,7 @@ class IMyBehavior(Schema):
6370

6471
```
6572

66-
If you want to mark fields of an existing 3rd party behavior, it can be done using this utility function:
73+
If you want to mark fields of an existing third party behavior, it can be done using the following utility function.
6774

6875
```python
6976
from plone.app.dexterity.behaviors.metadata import ICategorization
@@ -73,7 +80,7 @@ utils.searchable(ICategorization, 'categorization')
7380
```
7481

7582
The `title` and `description` on `plone.app.dexterity`'s `IBasic` behavior are marked as searchable by default.
76-
For marking them as no longer searchable, there is a utility function:
83+
For marking them as no longer searchable, there is a utility function.
7784

7885
```python
7986
from plone.app.dexterity.behaviors.metadata import IBasic
@@ -82,11 +89,9 @@ from plone.app.dexterity.textindexer import utils
8289
utils.no_longer_searchable(IBasic, 'title')
8390
```
8491

85-
Alternatively, if you specified your model as a plone.supermodel XML model,
86-
you can mark the field searchable by using `indexer:searchable="true"`:
92+
Alternatively, if you specified your model as a `plone.supermodel` XML model, you can mark the field searchable by using `indexer:searchable="true"`.
8793

8894
```xml
89-
9095
<model xmlns="http://namespaces.plone.org/supermodel/schema"
9196
xmlns:indexer="http://namespaces.plone.org/supermodel/indexer">
9297
<schema based-on="plone.supermodel.model.Schema">
@@ -100,21 +105,27 @@ you can mark the field searchable by using `indexer:searchable="true"`:
100105
</model>
101106
```
102107

108+
The `SearchableText` indexer now includes your custom field on your behavior.
109+
The field of your content type is indexed if the `plone.textindexer` behavior is enabled on your content type.
103110

104-
Your SearchableText indexer includes now your custom field on your behavior.
105-
It is enabled on your content type, if the `plone.textindexer` behavior is enabled there too.
106111

112+
(backend-indexing-registering-custom-field-converter-label)=
107113

108-
#### Registering a custom field converter
114+
## Registering a custom field converter
109115

116+
By default a field is converted to a searchable text by rendering the widget in display mode and transforming the result to `text/plain`.
117+
However if you need to convert your custom field in a different way, you have to provide a more specific converter multi-adapter.
110118

111-
By default, a field is converted to a searchable text by rendering the widget in display mode and transforming the result to `text/plain`.
112-
However, if you need to convert your custom field in a different way, you only have to provide a more specific converter multi-adapter.
113119

114-
Convert multi-adapter specification:
120+
(backend-indexing-convert-multi-adapter-specification-label)=
115121

116-
:Interface: `plone.app.dexterity.textindexer.IDexterityTextIndexFieldConverter`
117-
:Discriminators: context, field, widget
122+
### Convert multi-adapter specification
123+
124+
Interface
125+
: `plone.app.dexterity.textindexer.IDexterityTextIndexFieldConverter`
126+
127+
Discriminators
128+
: context, field, widget
118129

119130
Example:
120131

@@ -147,15 +158,15 @@ ZCML:
147158
</configure>
148159
```
149160

150-
There is already an adapter for converting files properly.
161+
There is already an adapter for converting files properly.
151162

152163

164+
(backend-indexing-extending-indexed-data-label)=
153165

154-
#### Extending indexed data
166+
## Extending indexed data
155167

156-
157-
Sometimes you need to extend the SearchableText with additional data which is not stored in a field.
158-
It is possible to register a named adapter which provides additional data:
168+
Sometimes you need to extend the `SearchableText` with additional data which is not stored in a field.
169+
It is possible to register a named adapter which provides additional data.
159170

160171
```python
161172
from plone.app.dexterity import textindexer
@@ -187,26 +198,30 @@ ZCML:
187198
</configure>
188199
```
189200

190-
This is a **named** adapter! This makes it possible to register multiple
191-
extenders for the same object on different behavior interfaces. The name of
192-
the adapter does not matter, but it's recommended to use the name of the
193-
behavior (this may reduce conflicts).
201+
This is a **named** adapter!
202+
The named registration allows registering multiple extenders on different behavior interfaces applying to the same object.
203+
The name of the adapter does not matter, but it's recommended to use the name of the behavior to reduce potential conflicts.
194204

195-
If your behavior has a defined factory (which is not attribute storage), then
196-
you need to define a marker interface and register the adapter on this marker
197-
interface (dexterity objects do not provide behavior interfaces of behaviors,
198-
which are not using attribute storage).
205+
If your behavior has a defined factory (which is not attribute storage), then you need to define a marker interface and register the adapter on this marker interface.
206+
Dexterity objects do not provide behavior interfaces of behaviors, which are not using attribute storage.
199207

200208

209+
(backend-indexing-portal-type-fieldindex-label)=
201210

202211
## `portal_type` (`FieldIndex`)
203212

204-
Indexes the `portal_type` field and contains values like `Folder`.
213+
Indexes the `portal_type` field and contains values such as `Folder`.
214+
215+
216+
(backend-indexing-path-pathindex-label)=
217+
218+
## `path` (`PathIndex`)
219+
220+
Indexes the object path, such as `/news/news-item-1`.
205221

206-
## `path` (`PathIndex)`
207222

208-
Indexes the object path, like `/news/news-item-1`.
223+
(backend-indexing-subject-keywordindex-label)=
209224

210225
## `Subject` (`KeywordIndex`)
211226

212-
Indexes the `Subject` field which contains a list of object categories.
227+
Indexes the `Subject` field which contains a list of object categories.

0 commit comments

Comments
 (0)