@dotcms/react 1.1.1 → 1.2.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,15 +20,16 @@ The `@dotcms/react` SDK is the DotCMS official React library. It empowers React
20
20
  - [DotCMSEditableText](#dotcmseditabletext)
21
21
  - [useEditableDotCMSPage](#useeditabledotcmspage)
22
22
  - [useDotCMSShowWhen](#usedotcmsshowwhen)
23
+ - [useAISearch](#useaisearch)
23
24
  - [Troubleshooting](#troubleshooting)
24
25
  - [Common Issues & Solutions](#common-issues--solutions)
25
26
  - [Debugging Tips](#debugging-tips)
26
27
  - [Version Compatibility](#version-compatibility)
27
28
  - [Still Having Issues?](#still-having-issues)
28
29
  - [Migration from Alpha to 1.0.X](./MIGRATION.md)
29
- - [dotCMS Support](#dotcms-support)
30
- - [How To Contribute](#how-to-contribute)
31
- - [Licensing Information](#licensing-information)
30
+ - [Support](#support)
31
+ - [Contributing](#contributing)
32
+ - [Licensing](#licensing)
32
33
 
33
34
  ## Prerequisites & Setup
34
35
 
@@ -443,6 +444,141 @@ const MyEditButton = () => {
443
444
  };
444
445
  ```
445
446
 
447
+ ### useAISearch
448
+
449
+ `useAISearch` is a hook that enables AI-powered semantic search capabilities for your dotCMS content. It manages search state, handles API calls, and provides real-time status updates.
450
+
451
+ | Param | Type | Required | Description |
452
+ | ----------- | ----------------------- | -------- | ------------------------------------------------------------------------------ |
453
+ | `client` | `DotCMSClient` | ✅ | The dotCMS client instance created with `createDotCMSClient()` |
454
+ | `indexName` | `string` | ✅ | Name of the AI search index to query |
455
+ | `params` | `DotCMSAISearchParams` | ✅ | Search configuration including query params (limit, offset) and AI config |
456
+
457
+ #### Return Value
458
+
459
+ The hook returns an object with the following properties:
460
+
461
+ | Property | Type | Description |
462
+ | ---------- | ---------------------------------------- | -------------------------------------------------------------- |
463
+ | `response` | `DotCMSAISearchResponse<T> \| null` | Full search response including metadata and results |
464
+ | `results` | `DotCMSAISearchContentletData<T>[] \| undefined` | Array of search results with match scores |
465
+ | `status` | `DotCMSEntityStatus` | Current state: `IDLE`, `LOADING`, `SUCCESS`, or `ERROR` |
466
+ | `search` | `(prompt: string) => Promise<void>` | Function to execute a search with a text prompt |
467
+ | `reset` | `() => void` | Function to reset search state to idle |
468
+
469
+ #### Usage
470
+
471
+ ```tsx
472
+ 'use client';
473
+
474
+ import { useState } from 'react';
475
+ import { useAISearch } from '@dotcms/react';
476
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
477
+ import { dotCMSClient } from '@/lib/dotCMSClient';
478
+
479
+ interface BlogPost extends DotCMSBasicContentlet {
480
+ body: string;
481
+ author: string;
482
+ }
483
+
484
+ const AISearchComponent = () => {
485
+ const [searchQuery, setSearchQuery] = useState('');
486
+
487
+ const { results, status, search, reset } = useAISearch<BlogPost>({
488
+ client: dotCMSClient,
489
+ indexName: 'blog-search-index',
490
+ params: {
491
+ query: {
492
+ limit: 10,
493
+ offset: 0,
494
+ contentType: 'Blog'
495
+ },
496
+ config: {
497
+ threshold: 0.5,
498
+ responseLength: 1024
499
+ }
500
+ }
501
+ });
502
+
503
+ const handleSearch = async () => {
504
+ if (searchQuery.trim()) {
505
+ await search(searchQuery);
506
+ }
507
+ };
508
+
509
+ const handleReset = () => {
510
+ setSearchQuery('');
511
+ reset();
512
+ };
513
+
514
+ return (
515
+ <div className="search-container">
516
+ <div className="search-bar">
517
+ <input
518
+ type="text"
519
+ value={searchQuery}
520
+ onChange={(e) => setSearchQuery(e.target.value)}
521
+ placeholder="Search with AI..."
522
+ />
523
+ <button onClick={handleSearch} disabled={status.state === 'LOADING'}>
524
+ {status.state === 'LOADING' ? 'Searching...' : 'Search'}
525
+ </button>
526
+ <button onClick={handleReset}>Reset</button>
527
+ </div>
528
+
529
+ {status.state === 'ERROR' && (
530
+ <div className="error">
531
+ Error: {status.error.message}
532
+ </div>
533
+ )}
534
+
535
+ {status.state === 'SUCCESS' && results && (
536
+ <div className="results">
537
+ <h2>Found {results.length} results</h2>
538
+ {results.map((result) => (
539
+ <article key={result.identifier}>
540
+ <h3>{result.title}</h3>
541
+ <p>Author: {result.author}</p>
542
+ {result.matches?.map((match, idx) => (
543
+ <div key={idx} className="match">
544
+ <span>Relevance: {match.distance.toFixed(2)}</span>
545
+ <p>{match.extractedText}</p>
546
+ </div>
547
+ ))}
548
+ </article>
549
+ ))}
550
+ </div>
551
+ )}
552
+ </div>
553
+ );
554
+ };
555
+
556
+ export default AISearchComponent;
557
+ ```
558
+
559
+ #### Features
560
+
561
+ - **Automatic State Management**: Handles loading, success, error, and idle states
562
+ - **Type-Safe Results**: Generic typing ensures type safety for your content types
563
+ - **Search Validation**: Automatically validates and trims search prompts
564
+ - **Configurable Parameters**: Support for pagination, thresholds, and AI configuration
565
+ - **Error Handling**: Provides detailed error information through status state
566
+ - **Reset Capability**: Easy state reset for clearing search results
567
+
568
+ #### Configuration Options
569
+
570
+ **Query Parameters (`params.query`):**
571
+ - `limit`: Maximum number of results (default: 1000)
572
+ - `offset`: Number of results to skip (default: 0)
573
+ - `siteId`: Filter by specific site
574
+ - `contentType`: Filter by content type
575
+ - `languageId`: Filter by language
576
+
577
+ **AI Configuration (`params.config`):**
578
+ - `threshold`: Minimum similarity score (default: 0.5)
579
+ - `distanceFunction`: Vector distance algorithm (default: cosine)
580
+ - `responseLength`: Maximum response text length (default: 1024)
581
+
446
582
  ## Troubleshooting
447
583
 
448
584
  ### Common Issues & Solutions
@@ -579,7 +715,7 @@ If you're still experiencing problems after trying these solutions:
579
715
  - Error messages
580
716
  - Code samples
581
717
 
582
- ## dotCMS Support
718
+ ## Support
583
719
 
584
720
  We offer multiple channels to get help with the dotCMS React SDK:
585
721
 
@@ -595,9 +731,9 @@ When reporting issues, please include:
595
731
  - Minimal reproduction steps
596
732
  - Expected vs. actual behavior
597
733
 
598
- ## How To Contribute
734
+ ## Contributing
599
735
 
600
- GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS UVE SDK! If you'd like to contribute, please follow these steps:
736
+ GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the dotCMS React SDK! If you'd like to contribute, please follow these steps:
601
737
 
602
738
  1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
603
739
  2. Create a feature branch (`git checkout -b feature/amazing-feature`)
@@ -607,7 +743,7 @@ GitHub pull requests are the preferred method to contribute code to dotCMS. We w
607
743
 
608
744
  Please ensure your code follows the existing style and includes appropriate tests.
609
745
 
610
- ## Licensing Information
746
+ ## Licensing
611
747
 
612
748
  dotCMS comes in multiple editions and as such is dual-licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization, and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds several enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://www.dotcms.com/cms-platform/features).
613
749