Skip to content

why use PREFIX with create ? #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
itmeicn opened this issue Jul 20, 2022 · 4 comments
Closed

why use PREFIX with create ? #45

itmeicn opened this issue Jul 20, 2022 · 4 comments
Labels
question Further information is requested

Comments

@itmeicn
Copy link

itmeicn commented Jul 20, 2022

FT.CREATE idx ON HASH PREFIX 1 blog:post: SCHEMA,PREFIX ? how to use it create?

@MacFJA
Copy link
Owner

MacFJA commented Jul 20, 2022

Hello,

You have 2 ways to set prefix(es), with the IndexBuilder, or with the Create command.

IndexBuilder

/** @var \MacFJA\RediSearch\Redis\Client $client */
$builder = (new \MacFJA\RediSearch\IndexBuilder())
    ->setIndex('idx')
    ->setPrefixes(['blog:post:']) // Setter take an array
    ->addTextField('title')
    ->addTextField('body');
$builder->create($client);
/** @var \MacFJA\RediSearch\Redis\Client $client */
$builder = (new \MacFJA\RediSearch\IndexBuilder())
    ->setIndex('idx')
    ->addPrefixes('blog:post:') // "Adder" take one or more arguments as prefixes
    ->addTextField('title')
    ->addTextField('body');
$builder->create($client);

Create

/** @var \MacFJA\RediSearch\Redis\Client $client */
$create = (new \MacFJA\RediSearch\Redis\Command\Create())
   ->setIndex('idx')
   ->setPrefixes('blog:post:')
   ->addTextField('title')
   ->addTextField('body');
$client->execute($create);

I hope that answer your question.

@MacFJA MacFJA added the question Further information is requested label Jul 20, 2022
@itmeicn
Copy link
Author

itmeicn commented Jul 21, 2022

thanks,I will. But I need more operations, such as CRUD. or detailed function description

@MacFJA
Copy link
Owner

MacFJA commented Jul 21, 2022

This library is a "low-level" implementation.
It reflect operation from RediSearch as close as possible.

If you want more high level I can suggest macfja/redisearch-integration (git).
This lib can offer method like persist (C and U of CRUD), remove (D of CRUD) and easier way to create a search (R of CRUD) on PHP object/class directly


But with only this library

C and U of CRUD

\MacFJA\RediSearch\Index::addDocumentFromArray will be the function to use

R of CRUD

\MacFJA\RediSearch\Redis\Command\Search will be the object to create and to use with a Client

D of CRUD

You will need to use other command or use \MacFJA\RediSearch\Redis\Client::executeRaw ($myClient->executeRaw('DEL', 'document_hash');)

@itmeicn
Copy link
Author

itmeicn commented Jul 23, 2022

Thanks a lot, I will already use 2.x.

@itmeicn itmeicn closed this as completed Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants