-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathindex.html
828 lines (527 loc) · 36.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="author" content="Ethan Hann">
<meta name="lang:clipboard.copy" content="Copy to clipboard">
<meta name="lang:clipboard.copied" content="Copied to clipboard">
<meta name="lang:search.language" content="en">
<meta name="lang:search.pipeline.stopwords" content="True">
<meta name="lang:search.pipeline.trimmer" content="True">
<meta name="lang:search.result.none" content="No matching documents">
<meta name="lang:search.result.one" content="1 matching document">
<meta name="lang:search.result.other" content="# matching documents">
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../images/logo.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.3.0">
<title>Indexing - RediSearch-PHP</title>
<link rel="stylesheet" href="../assets/stylesheets/application.572ca0f0.css">
<link rel="stylesheet" href="../assets/stylesheets/application-palette.22915126.css">
<meta name="theme-color" content="#ef5350">
<script src="../assets/javascripts/modernizr.962652e9.js"></script>
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
<link rel="stylesheet" href="../css/style.css">
</head>
<body dir="ltr" data-md-color-primary="red" data-md-color-accent="red">
<svg class="md-svg">
<defs>
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
viewBox="0 0 416 448" id="__github">
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
99.5z" />
</svg>
</defs>
</svg>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
<a href="#indexing" tabindex="1" class="md-skip">
Skip to content
</a>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href=".." title="RediSearch-PHP" class="md-header-nav__button md-logo">
<img src="../images/logo.png" width="24" height="24">
</a>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
</div>
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
RediSearch-PHP
</span>
<span class="md-header-nav__topic">
Indexing
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
<label class="md-icon md-search__icon" for="__search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">

</button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result">
<div class="md-search-result__meta">
Type to start searching
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<div class="md-header-nav__source">
<a href="https://github.com/ethanhann/redisearch-php/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container">
<main class="md-main">
<div class="md-main__inner md-grid" data-md-component="container">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" data-md-level="0">
<label class="md-nav__title md-nav__title--site" for="__drawer">
<a href=".." title="RediSearch-PHP" class="md-nav__button md-logo">
<img src="../images/logo.png" width="48" height="48">
</a>
RediSearch-PHP
</label>
<div class="md-nav__source">
<a href="https://github.com/ethanhann/redisearch-php/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." title="Getting Started" class="md-nav__link">
Getting Started
</a>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-2" type="checkbox" id="nav-2" checked>
<label class="md-nav__link" for="nav-2">
Documentation
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-2">
Documentation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active">
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Indexing
</label>
<a href="./" title="Indexing" class="md-nav__link md-nav__link--active">
Indexing
</a>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#field-types" title="Field Types" class="md-nav__link">
Field Types
</a>
</li>
<li class="md-nav__item">
<a href="#adding-documents" title="Adding Documents" class="md-nav__link">
Adding Documents
</a>
</li>
<li class="md-nav__item">
<a href="#updating-a-document" title="Updating a Document" class="md-nav__link">
Updating a Document
</a>
</li>
<li class="md-nav__item">
<a href="#batch-indexing" title="Batch Indexing" class="md-nav__link">
Batch Indexing
</a>
</li>
<li class="md-nav__item">
<a href="#indexing-from-a-hash" title="Indexing From a Hash" class="md-nav__link">
Indexing From a Hash
</a>
</li>
<li class="md-nav__item">
<a href="#aliasing" title="Aliasing" class="md-nav__link">
Aliasing
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#adding-an-alias" title="Adding an Alias" class="md-nav__link">
Adding an Alias
</a>
</li>
<li class="md-nav__item">
<a href="#updating-an-alias" title="Updating an Alias" class="md-nav__link">
Updating an Alias
</a>
</li>
<li class="md-nav__item">
<a href="#deleting-an-alias" title="Deleting an Alias" class="md-nav__link">
Deleting an Alias
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../searching/" title="Searching" class="md-nav__link">
Searching
</a>
</li>
<li class="md-nav__item">
<a href="../aggregating/" title="Aggregating" class="md-nav__link">
Aggregating
</a>
</li>
<li class="md-nav__item">
<a href="../suggesting/" title="Suggesting" class="md-nav__link">
Suggesting
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../laravel-support/" title="Laravel Support" class="md-nav__link">
Laravel Support
</a>
</li>
<li class="md-nav__item">
<a href="../changelog/" title="Changelog" class="md-nav__link">
Changelog
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#field-types" title="Field Types" class="md-nav__link">
Field Types
</a>
</li>
<li class="md-nav__item">
<a href="#adding-documents" title="Adding Documents" class="md-nav__link">
Adding Documents
</a>
</li>
<li class="md-nav__item">
<a href="#updating-a-document" title="Updating a Document" class="md-nav__link">
Updating a Document
</a>
</li>
<li class="md-nav__item">
<a href="#batch-indexing" title="Batch Indexing" class="md-nav__link">
Batch Indexing
</a>
</li>
<li class="md-nav__item">
<a href="#indexing-from-a-hash" title="Indexing From a Hash" class="md-nav__link">
Indexing From a Hash
</a>
</li>
<li class="md-nav__item">
<a href="#aliasing" title="Aliasing" class="md-nav__link">
Aliasing
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#adding-an-alias" title="Adding an Alias" class="md-nav__link">
Adding an Alias
</a>
</li>
<li class="md-nav__item">
<a href="#updating-an-alias" title="Updating an Alias" class="md-nav__link">
Updating an Alias
</a>
</li>
<li class="md-nav__item">
<a href="#deleting-an-alias" title="Deleting an Alias" class="md-nav__link">
Deleting an Alias
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<a href="https://github.com/ethanhann/redisearch-php/edit/master/docs-src/indexing.md" title="Edit this page" class="md-icon md-content__icon"></a>
<h1 id="indexing">Indexing<a class="headerlink" href="#indexing" title="Permanent link">¶</a></h1>
<h2 id="field-types">Field Types<a class="headerlink" href="#field-types" title="Permanent link">¶</a></h2>
<p>There are four types of fields that can be added to a document: <strong>TextField</strong>, <strong>NumericField</strong>, <strong>GeoField</strong> and <strong>TagField</strong>.</p>
<p>They are instantiated like this:</p>
<div class="codehilite"><pre><span></span><span class="k">new</span> <span class="nx">TextField</span><span class="p">(</span><span class="s1">'author'</span><span class="p">,</span> <span class="s1">'Charles Dickens'</span><span class="p">);</span>
<span class="k">new</span> <span class="nx">NumericField</span><span class="p">(</span><span class="s1">'price'</span><span class="p">,</span> <span class="mf">9.99</span><span class="p">);</span>
<span class="k">new</span> <span class="nx">GeoField</span><span class="p">(</span><span class="s1">'place'</span><span class="p">,</span> <span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">));</span>
<span class="k">new</span> <span class="nx">TagField</span><span class="p">(</span><span class="s1">'color'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">);</span>
</pre></div>
<p>Fields can also be made with the FieldFactory class:</p>
<div class="codehilite"><pre><span></span><span class="c1">// Alternative syntax for: new TextField('author', 'Charles Dickens');</span>
<span class="nx">FieldFactory</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'author'</span><span class="p">,</span> <span class="s1">'Charles Dickens'</span><span class="p">);</span>
<span class="c1">// Alternative syntax for: new NumericField('price', 9.99);</span>
<span class="nx">FieldFactory</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'price'</span><span class="p">,</span> <span class="mf">9.99</span><span class="p">);</span>
<span class="c1">// Alternative syntax for: new GeoField('place', new GeoLocation(-77.0366, 38.8977));</span>
<span class="nx">FieldFactory</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'place'</span><span class="p">,</span> <span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">));</span>
<span class="c1">// Alternative syntax for: new TagField('color', 'red');</span>
<span class="nx">FieldFactory</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'color'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">);</span>
</pre></div>
<h2 id="adding-documents">Adding Documents<a class="headerlink" href="#adding-documents" title="Permanent link">¶</a></h2>
<p>Add an array of field objects:</p>
<div class="codehilite"><pre><span></span><span class="nv">$bookIndex</span><span class="o">-></span><span class="na">add</span><span class="p">([</span>
<span class="k">new</span> <span class="nx">TextField</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'Tale of Two Cities'</span><span class="p">),</span>
<span class="k">new</span> <span class="nx">TextField</span><span class="p">(</span><span class="s1">'author'</span><span class="p">,</span> <span class="s1">'Charles Dickens'</span><span class="p">),</span>
<span class="k">new</span> <span class="nx">NumericField</span><span class="p">(</span><span class="s1">'price'</span><span class="p">,</span> <span class="mf">9.99</span><span class="p">),</span>
<span class="k">new</span> <span class="nx">GeoField</span><span class="p">(</span><span class="s1">'place'</span><span class="p">,</span> <span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">)),</span>
<span class="k">new</span> <span class="nx">TagField</span><span class="p">(</span><span class="s1">'color'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">),</span>
<span class="p">]);</span>
</pre></div>
<p>Add an associative array:</p>
<div class="codehilite"><pre><span></span><span class="nv">$bookIndex</span><span class="o">-></span><span class="na">add</span><span class="p">([</span>
<span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'Tale of Two Cities'</span><span class="p">,</span>
<span class="s1">'author'</span> <span class="o">=></span> <span class="s1">'Charles Dickens'</span><span class="p">,</span>
<span class="s1">'price'</span> <span class="o">=></span> <span class="mf">9.99</span><span class="p">,</span>
<span class="s1">'place'</span> <span class="o">=></span> <span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">),</span>
<span class="s1">'color'</span> <span class="o">=></span> <span class="k">new</span> <span class="nx">TagField</span><span class="p">(</span><span class="s1">'color'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">),,</span>
<span class="p">]);</span>
</pre></div>
<p>Create a document with the index's makeDocument method, then set field values:</p>
<div class="codehilite"><pre><span></span><span class="nv">$document</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">();</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome.'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">author</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'Jack'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">price</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="mf">9.99</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">place</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">));</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">add</span><span class="p">(</span><span class="nv">$document</span><span class="p">);</span>
</pre></div>
<p>DocBlocks can (optionally) be used to type hint field property names:</p>
<div class="codehilite"><pre><span></span><span class="sd">/** @var BookDocument $document */</span>
<span class="nv">$document</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">();</span>
<span class="c1">// "title" will auto-complete correctly in your IDE provided BookDocument has a "title" property or @property annotation.</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome.'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">add</span><span class="p">(</span><span class="nv">$document</span><span class="p">);</span>
</pre></div>
<div class="codehilite"><pre><span></span><span class="cp"><?php</span>
<span class="k">namespace</span> <span class="nx">Your\Documents</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Ehann\RediSearch\Document\Document</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Ehann\RediSearch\Fields\NumericField</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Ehann\RediSearch\Fields\TextField</span><span class="p">;</span>
<span class="sd">/**</span>
<span class="sd"> * @property TextField title</span>
<span class="sd"> * @property TextField author</span>
<span class="sd"> * @property NumericField price</span>
<span class="sd"> * @property GeoField place</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">BookDocument</span> <span class="k">extends</span> <span class="nx">Document</span>
<span class="p">{</span>
<span class="p">}</span>
</pre></div>
<h2 id="updating-a-document">Updating a Document<a class="headerlink" href="#updating-a-document" title="Permanent link">¶</a></h2>
<p>Documents are updated with an index's replace method.</p>
<div class="codehilite"><pre><span></span><span class="c1">// Make a document.</span>
<span class="nv">$document</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">();</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome.'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">author</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'Jack'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">price</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="mf">9.99</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">place</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">));</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">add</span><span class="p">(</span><span class="nv">$document</span><span class="p">);</span>
<span class="c1">// Update a couple fields</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome: Part 2.'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">price</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="mf">19.99</span><span class="p">);</span>
<span class="c1">// Update the document.</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">replace</span><span class="p">(</span><span class="nv">$document</span><span class="p">);</span>
</pre></div>
<p>A document can also be updating when its ID is specified:</p>
<div class="codehilite"><pre><span></span><span class="c1">// Make a document.</span>
<span class="nv">$document</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">();</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome.'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">author</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'Jack'</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">price</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="mf">9.99</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">place</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="k">new</span> <span class="nx">GeoLocation</span><span class="p">(</span><span class="o">-</span><span class="mf">77.0366</span><span class="p">,</span> <span class="mf">38.8977</span><span class="p">));</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">add</span><span class="p">(</span><span class="nv">$document</span><span class="p">);</span>
<span class="c1">// Create a new document and assign the old document's ID to it.</span>
<span class="nv">$newDocument</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">(</span><span class="nv">$document</span><span class="o">-></span><span class="na">getId</span><span class="p">());</span>
<span class="c1">// Set a couple fields.</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">''</span><span class="p">);</span>
<span class="nv">$document</span><span class="o">-></span><span class="na">author</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'Jack'</span><span class="p">);</span>
<span class="nv">$newDocument</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="s1">'How to be awesome: Part 2.'</span><span class="p">);</span>
<span class="nv">$newDocument</span><span class="o">-></span><span class="na">price</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="mf">19.99</span><span class="p">);</span>
<span class="c1">// Update the document.</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">replace</span><span class="p">(</span><span class="nv">$newDocument</span><span class="p">);</span>
</pre></div>
<h2 id="batch-indexing">Batch Indexing<a class="headerlink" href="#batch-indexing" title="Permanent link">¶</a></h2>
<p>Batch indexing is possible with the <strong>addMany</strong> method.
To index an external collection, make sure to set the document's ID to the ID of the record in the external collection.</p>
<div class="codehilite"><pre><span></span><span class="c1">// Get a record set from your DB (or some other datastore).</span>
<span class="nv">$records</span> <span class="o">=</span> <span class="nv">$someDatabase</span><span class="o">-></span><span class="na">findAll</span><span class="p">();</span>
<span class="nv">$documents</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">foreach</span> <span class="p">(</span><span class="nv">$records</span> <span class="k">as</span> <span class="nv">$record</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Make a new document with the external record's ID.</span>
<span class="nv">$newDocument</span> <span class="o">=</span> <span class="nv">$bookIndex</span><span class="o">-></span><span class="na">makeDocument</span><span class="p">(</span><span class="nv">$record</span><span class="o">-></span><span class="na">id</span><span class="p">);</span>
<span class="nv">$newDocument</span><span class="o">-></span><span class="na">title</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="nv">$record</span><span class="o">-></span><span class="na">title</span><span class="p">);</span>
<span class="nv">$newDocument</span><span class="o">-></span><span class="na">author</span><span class="o">-></span><span class="na">setValue</span><span class="p">(</span><span class="nv">$record</span><span class="o">-></span><span class="na">author</span><span class="p">);</span>
<span class="nv">$documents</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$newDocument</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// Add all the documents at once.</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">addMany</span><span class="p">(</span><span class="nv">$documents</span><span class="p">);</span>
<span class="c1">// It is possible to increase indexing speed by disabling atomicity by passing true as the second parameter.</span>
<span class="c1">// Note that this is only possible when using the phpredis extension.</span>
<span class="nv">$bookIndex</span><span class="o">-></span><span class="na">addMany</span><span class="p">(</span><span class="nv">$documents</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span>
</pre></div>
<h2 id="indexing-from-a-hash">Indexing From a Hash<a class="headerlink" href="#indexing-from-a-hash" title="Permanent link">¶</a></h2>
<p>Redis hashes are key/value pairs referenced by a key.
It is possible to index an existing hash with the <strong>addHash</strong> method.
The document's ID has to be the same as the hash's key.
Attempting to index a hash that does not exist will result in an exception.</p>
<p>Index a hash with the key "foo":</p>
<div class="codehilite"><pre><span></span><span class="x">$document = $bookIndex->makeDocument('foo');</span>
<span class="x">$bookIndex->addHash($document);</span>
</pre></div>
<p>Replace a document in the index from a hash:</p>
<div class="codehilite"><pre><span></span><span class="x">$document = $bookIndex->makeDocument('foo');</span>
<span class="x">$bookIndex->replaceHash($document);</span>
</pre></div>
<h2 id="aliasing">Aliasing<a class="headerlink" href="#aliasing" title="Permanent link">¶</a></h2>
<p>Indexes can be aliased.</p>
<p>Note that an exception will be thrown if any alias method is called before an index's <a href="/#create-the-schema">schema</a> is created. </p>
<h3 id="adding-an-alias">Adding an Alias<a class="headerlink" href="#adding-an-alias" title="Permanent link">¶</a></h3>
<p>An alias can be added for an index like this:</p>
<div class="codehilite"><pre><span></span><span class="nv">$index</span><span class="o">-></span><span class="na">addAlias</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">);</span>
</pre></div>
<h3 id="updating-an-alias">Updating an Alias<a class="headerlink" href="#updating-an-alias" title="Permanent link">¶</a></h3>
<p>Assuming an alias has already been added to an index, like this:</p>
<div class="codehilite"><pre><span></span><span class="nv">$oldIndex</span><span class="o">-></span><span class="na">addAlias</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">);</span>
</pre></div>
<p>...it can be reassigned to a different index like this:</p>
<div class="codehilite"><pre><span></span><span class="nv">$newIndex</span><span class="o">-></span><span class="na">updateAlias</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">);</span>
</pre></div>
<h3 id="deleting-an-alias">Deleting an Alias<a class="headerlink" href="#deleting-an-alias" title="Permanent link">¶</a></h3>
<p>An alias can be deleted like this:</p>
<div class="codehilite"><pre><span></span><span class="nv">$index</span><span class="o">-></span><span class="na">deleteAlias</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">);</span>
</pre></div>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid">
<a href=".." title="Getting Started" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
</div>
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
Getting Started
</span>
</div>
</a>
<a href="../searching/" title="Searching" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Searching
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
<div class="md-footer-copyright__highlight">
© 2018 - Ethan Hann
</div>
powered by
<a href="https://www.mkdocs.org">MkDocs</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/">
Material for MkDocs</a>
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.a353778b.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>