Skip to content

Commit

Permalink
Merge pull request #2706 from bikusta/simple-search-engine-array
Browse files Browse the repository at this point in the history
doc: Fix simple search engine cookbook
  • Loading branch information
SenseException authored Dec 15, 2024
2 parents c4b43c2 + 09641e5 commit 1c57a0c
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions docs/en/cookbook/simple-search-engine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Simple Search Engine

It is very easy to implement a simple keyword search engine with MongoDB. Because of
its flexible schema less nature we can store the keywords we want to search through directly
on the document. MongoDB is capable of indexing the embedded documents so the results are fast
on the document. MongoDB is capable of indexing an array field, so the results are fast
and scalable.

Sample Model: Product
Expand All @@ -25,15 +25,9 @@ setup a document like the following with a ``$keywords`` property that is mapped
#[Field(type: 'string')]
public string $title;
/** @var Collection<string> */
#[Field(type: 'collection')]
#[Index]
public Collection $keywords;
public function __construct()
{
$this->keywords = new ArrayCollection();
}
public array $keywords = [];
}
Working with Keywords
Expand All @@ -47,11 +41,11 @@ Now, create a product and add some keywords:
$product = new Product();
$product->title = 'Nike Air Jordan 2011';
$product->keywords->add('nike shoes');
$product->keywords->add('jordan shoes');
$product->keywords->add('air jordan');
$product->keywords->add('shoes');
$product->keywords->add('2011');
$product->keywords[] = 'nike shoes';
$product->keywords[] = 'jordan shoes';
$product->keywords[] = 'air jordan';
$product->keywords[] = 'shoes';
$product->keywords[] = '2011';
$dm->persist($product);
$dm->flush();
Expand Down

0 comments on commit 1c57a0c

Please sign in to comment.