Skip to content

Commit 051ad36

Browse files
committed
RDoc-3256 Document extensions > Attachments > Indexing [Fix article - C#]
1 parent b864961 commit 051ad36

File tree

4 files changed

+473
-163
lines changed

4 files changed

+473
-163
lines changed

Documentation/5.4/Raven.Documentation.Pages/document-extensions/attachments/indexing.dotnet.markdown

Lines changed: 117 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,129 @@
55

66
* Indexing attachments allows you to query for documents based on their attachments' details and content.
77

8-
* **Static indexes**:
8+
* **Static indexes**:
99
Both attachments' details and content can be indexed within a static-index definition.
1010

1111
* **Auto-indexes**:
1212
Auto-indexing attachments via dynamic queries is not available at this time.
1313

14-
15-
* In this page:
16-
* [Syntax](../../document-extensions/attachments/indexing#syntax)
17-
* [Examples](../../document-extensions/attachments/indexing#examples)
18-
* [Leveraging indexed attachments](../../document-extensions/attachments/indexing#leveraging-indexed-attachments)
14+
* In this page:
15+
* [Index attachments details](../../document-extensions/attachments/indexing#index-attachments-details)
16+
* [Index details & content - by attachment name](../../document-extensions/attachments/indexing#index-details-&-content---by-attachment-name)
17+
* [Index details & content - all attachments](../../document-extensions/attachments/indexing#index-details-&-content---all-attachments)
18+
* [Leveraging indexed attachments](../../document-extensions/attachments/indexing#leveraging-indexed-attachments)
19+
* [Syntax](../../document-extensions/attachments/indexing#syntax)
1920

2021
{NOTE/}
2122

2223
---
2324

24-
{PANEL: Syntax}
25+
{PANEL: Index attachments details}
26+
27+
**The index**:
2528

26-
### Using AttachmentsFor()
29+
* To index **attachments' details**, call `AttachmentsFor()` within the index definition.
2730

28-
The `AttachmentsFor` method returns information about each attachment that extends
29-
a specified document, including their names, sizes, and content type.
31+
* `AttachmentsFor()` provides access to the **name**, **size**, **hash**, and **content-type** of each attachment a document has.
32+
These details can then be used when defining the index-fields.
33+
Once the index is deployed, you can query the index to find Employee documents based on these attachment properties.
34+
35+
* To index **attachments' content**, see the examples [below](../../document-extensions/attachments/indexing#index-details-&-content---by-attachment-name).
3036

3137
{CODE-TABS}
32-
{CODE-TAB:csharp:Method syntax@DocumentExtensions\Attachments\IndexingAttachments.cs /}
33-
{CODE-TAB:csharp:Result result@DocumentExtensions\Attachments\IndexingAttachments.cs /}
38+
{CODE-TAB:csharp:LINQ_index index_1@documentExtensions\attachments\IndexingAttachments.cs /}
39+
{CODE-TAB:csharp:JS_index index_1_js@documentExtensions\attachments\IndexingAttachments.cs /}
3440
{CODE-TABS/}
3541

36-
The `AttachmentsFor` method is available in `AbstractIndexCreationTask`.
42+
---
3743

38-
### Using LoadAttachment()/LoadAttachments()
44+
**Query the Index**:
3945

40-
`LoadAttachment()` loads an attachment to the index by document and attachment name.
41-
`LoadAttachments()` loads all the attachments of a given document.
46+
You can now query for Employee documents based on their attachments details.
4247

43-
{CODE:csharp syntax_2@DocumentExtensions\Attachments\IndexingAttachments.cs /}
48+
{CODE-TABS}
49+
{CODE-TAB:csharp:Query query_1@documentExtensions\attachments\IndexingAttachments.cs /}
50+
{CODE-TAB:csharp:Query_async query_1_async@documentExtensions\attachments\IndexingAttachments.cs /}
51+
{CODE-TAB:csharp:DocumentQuery query_1_documentQuery@documentExtensions\attachments\IndexingAttachments.cs /}
52+
{CODE-TAB-BLOCK:sql:RQL}
53+
from index "Employees/ByAttachmentDetails"
54+
where AttachmentNames == "photo.jpg" and AttachmentSizes > 20000
55+
{CODE-TAB-BLOCK/}
56+
{CODE-TABS/}
4457

45-
| Parameter | Type | Description |
46-
| - | - | - |
47-
| **doc** | A server-side document, an entity | The document whose attachments you want to load |
48-
| **name** | `string` | The name of the attachment you want to load |
58+
{PANEL/}
4959

50-
#### GetContentAs Methods
60+
{PANEL: Index details & content - by attachment name}
5161

52-
To access the attachment content itself, use `GetContentAsStream()`. To
53-
convert the content into a `string`, use `GetContentAsString()` with
54-
the desired character encoding.
62+
{CONTENT-FRAME: }
5563

56-
{CODE-BLOCK: csharp}
57-
public Stream GetContentAsStream();
64+
**Sample data**:
5865

59-
public string GetContentAsString(Encoding encoding);
66+
* Each Employee document in RavenDB's sample data already includes a _photo.jpg_ attachment.
6067

61-
public string GetContentAsString(); // Default: UTF-8
62-
{CODE-BLOCK/}
68+
* For all following examples, let's store a textual attachment (file _notes.txt_) on 3 documents in the 'Employees' collection.
6369

64-
{PANEL/}
70+
{CODE:csharp store_attachments@documentExtensions\attachments\IndexingAttachments.cs /}
6571

66-
{PANEL: Examples}
72+
{CONTENT-FRAME/}
73+
74+
---
6775

68-
#### Indexes with `AttachmentsFor()`
76+
**The index**:
77+
78+
* To index the **details & content** for a specific attachment, call `LoadAttachment()` within the index definition.
79+
80+
* In addition to accessing the attachment details, `LoadAttachment()` provides access to the attachment's content,
81+
which can be used when defining the index-fields.
6982

7083
{CODE-TABS}
71-
{CODE-TAB:csharp:LINQ-syntax AttFor_index_LINQ@DocumentExtensions\Attachments\IndexingAttachments.cs /}
72-
{CODE-TAB:csharp:JavaScript-syntax AttFor_index_JS@DocumentExtensions\Attachments\IndexingAttachments.cs /}
84+
{CODE-TAB:csharp:LINQ_index index_2@documentExtensions\attachments\IndexingAttachments.cs /}
85+
{CODE-TAB:csharp:JS_index index_2_js@documentExtensions\attachments\IndexingAttachments.cs /}
7386
{CODE-TABS/}
7487

75-
#### Indexes with `LoadAttachment()`
88+
---
89+
90+
**Query the Index**:
91+
92+
You can now query for Employee documents based on their attachment details and/or its content.
7693

7794
{CODE-TABS}
78-
{CODE-TAB:csharp:LINQ-syntax LoadAtt_index_LINQ@DocumentExtensions\Attachments\IndexingAttachments.cs /}
79-
{CODE-TAB:csharp:JavaScript-syntax LoadAtt_index_JS@DocumentExtensions\Attachments\IndexingAttachments.cs /}
95+
{CODE-TAB:csharp:Query query_2@documentExtensions\attachments\IndexingAttachments.cs /}
96+
{CODE-TAB:csharp:Query_async query_2_async@documentExtensions\attachments\IndexingAttachments.cs /}
97+
{CODE-TAB:csharp:DocumentQuery query_2_documentQuery@documentExtensions\attachments\IndexingAttachments.cs /}
98+
{CODE-TAB-BLOCK:sql:RQL}
99+
from index "Employees/ByAttachment"
100+
where search(AttachmentContent, "Colorado Dallas")
101+
{CODE-TAB-BLOCK/}
80102
{CODE-TABS/}
81103

82-
#### Indexes with `LoadAttachments()`
104+
{PANEL/}
105+
106+
{PANEL: Index details & content - all attachments}
107+
108+
**The index**:
109+
110+
* Use `LoadAttachments()` to be able to index the **details & content** of ALL attachments.
111+
112+
* Note how the index example below is employing the [Fanout index](../../indexes/indexing-nested-data#fanout-index---multiple-index-entries-per-document) pattern.
83113

84114
{CODE-TABS}
85-
{CODE-TAB:csharp:LINQ-syntax LoadAtts_index_LINQ@DocumentExtensions\Attachments\IndexingAttachments.cs /}
86-
{CODE-TAB:csharp:JavaScript-syntax LoadAtts_index_JS@DocumentExtensions\Attachments\IndexingAttachments.cs /}
115+
{CODE-TAB:csharp:LINQ_index index_3@documentExtensions\attachments\IndexingAttachments.cs /}
116+
{CODE-TAB:csharp:JS_index index_3_js@documentExtensions\attachments\IndexingAttachments.cs /}
87117
{CODE-TABS/}
88118

89-
#### Querying the Index
119+
---
120+
121+
**Query the Index**:
90122

91123
{CODE-TABS}
92-
{CODE-TAB:csharp:Sync query1@DocumentExtensions\Attachments\IndexingAttachments.cs /}
93-
{CODE-TAB:csharp:Async query2@DocumentExtensions\Attachments\IndexingAttachments.cs /}
94-
{CODE-TAB:csharp:DocumentQuery query3@DocumentExtensions\Attachments\IndexingAttachments.cs /}
124+
{CODE-TAB:csharp:Query query_3@documentExtensions\attachments\IndexingAttachments.cs /}
125+
{CODE-TAB:csharp:Query_async query_3_async@documentExtensions\attachments\IndexingAttachments.cs /}
126+
{CODE-TAB:csharp:DocumentQuery query_3_documentQuery@documentExtensions\attachments\IndexingAttachments.cs /}
127+
{CODE-TAB-BLOCK:sql:RQL}
128+
from index "Employees/ByAllAttachments"
129+
where search(AttachmentContent, "Colorado Dallas") or AttachmentSize > 20000
130+
{CODE-TAB-BLOCK/}
95131
{CODE-TABS/}
96132

97133
{PANEL/}
@@ -101,17 +137,50 @@ public string GetContentAsString(); // Default: UTF-8
101137
* Access to the indexed attachment content opens the door to many different applications,
102138
including many that can be integrated directly into RavenDB.
103139

104-
* In this [blog post](https://ayende.com/blog/192001-B/using-machine-learning-with-ravendb),
105-
Oren Eini demonstrates how image recognition can be applied to indexed attachments using the [additional sources](../../indexes/extending-indexes) feature.
140+
* This [blog post](https://ayende.com/blog/192001-B/using-machine-learning-with-ravendb) demonstrates
141+
how image recognition can be applied to indexed attachments using the [additional sources](../../indexes/extending-indexes) feature.
106142
The resulting index allows filtering and querying based on image content.
107143

108144
{PANEL/}
109145

146+
{PANEL: Syntax}
147+
148+
#### `AttachmentsFor`
149+
150+
{CODE:csharp syntax_1@documentExtensions\attachments\IndexingAttachments.cs /}
151+
152+
| Parameter | Type | Description |
153+
|--------------|----------|-----------------------------------------------------------------|
154+
| **document** | `object` | The document object whose attachments details you want to load. |
155+
156+
{CODE:csharp attachment_details@documentExtensions\attachments\IndexingAttachments.cs /}
157+
158+
---
159+
160+
#### `LoadAttachment`
161+
162+
{CODE:csharp syntax_2@documentExtensions\attachments\IndexingAttachments.cs /}
163+
164+
| Parameter | Type | Description |
165+
|---------------------|-----------|-------------------------------------------------|
166+
| **document** | `object` | The document whose attachment you want to load. |
167+
| **attachmentName** | `string` | The name of the attachment to load. |
168+
169+
{CODE:csharp attachment_object@documentExtensions\attachments\IndexingAttachments.cs /}
170+
171+
---
172+
173+
#### `LoadAttachments`
174+
175+
{CODE:csharp syntax_3@documentExtensions\attachments\IndexingAttachments.cs /}
176+
177+
{PANEL/}
178+
110179
## Related Articles
111180

112181
### Document Extensions
113182

114-
- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
183+
- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
115184

116185
### Indexes
117186

Documentation/5.4/Raven.Documentation.Pages/document-extensions/attachments/indexing.js.markdown

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030

3131
---
3232

33-
* To index attachments' details, call `attachmentsFor()` within the index definition.
33+
* To index **attachments' details**, call `attachmentsFor()` within the index definition.
3434

3535
* `attachmentsFor()` provides access to the **name**, **size**, **hash**, and **content-type** of each attachment a document has.
3636
These details can then be used when defining the index-fields.
37+
Once the index is deployed, you can query the index to find Employee documents based on these attachment properties.
3738

38-
* To index attachments' content, see the examples below.
39+
* To index **attachments' content**, see the examples [below](../../document-extensions/attachments/indexing#index-details-&-content---by-attachment-name).
3940

4041
{CODE:nodejs index_1@documentExtensions\attachments\indexAttachments.js /}
4142

@@ -68,7 +69,7 @@ where attachmentNames == "photo.jpg" and attachmentSizes > 20000
6869

6970
---
7071

71-
* Each Employee document in the Northwind sample data already includes a _photo.jpg_ attachment.
72+
* Each Employee document in RavenDB's sample data already includes a _photo.jpg_ attachment.
7273

7374
* For all following examples, let's store a textual attachment (file _notes.txt_) on 3 documents
7475
in the 'Employees' collection.

0 commit comments

Comments
 (0)