Skip to content
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

feat: FullText Search in laravel-oci8 #800

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

jonas-elias
Copy link

@jonas-elias jonas-elias commented Aug 3, 2023

Title 😎
Hello, this pull request implements the "whereFullText()" method for laravel/oci8.

Description 🤯
The implementation utilizes the CONTAINS Oracle feature to perform a text search using the ctxsys.context index. To facilitate the creation of the index, a migration method named "fullText(nameColumn)" is included.

Additional notes 🤨
I have made modifications to the "testDropAllTables()" method to incorporate a constraint for secondary tables created by Oracle. This change prevents an error when dropping secondary tables whose parent tables have text reference indexes, and ensures the proper disposal of secondary tables (Oracle's automatic cascade). The relevant column "SECONDARY" is described in the documentation (references 3 and 4).

Running tests 🚀
./vendor/phpunit/phpunit/phpunit --filter=testWhereFullText
./vendor/phpunit/phpunit/phpunit --filter=testOrWhereFullText

References 🖥

  1. Oracle Documentation - CONTAINS
  2. Oracle Base - Full Text Indexing Using Oracle Text
  3. Oracle Documentation - ALL_TABLES
  4. Oracle Documentation - STATVIEW

Please review the changes, and if everything looks good, consider merging the pull request. Thank you 😁!

Copy link
Contributor

@hpacleb hpacleb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes and maybe add an orWhereFullText test as well.

src/Oci8/Query/Grammars/OracleGrammar.php Outdated Show resolved Hide resolved
src/Oci8/Query/Grammars/OracleGrammar.php Outdated Show resolved Hide resolved
@jonas-elias
Copy link
Author

A few notes and maybe add an orWhereFullText test as well.

Added!! Thanks for remember!

@jonas-elias
Copy link
Author

Relevant issues have been addressed... Now it is possible to utilize the "orWhereFullText()" and the option "labelSearch" not need passing in the "$options" of the "whereFullText()" method.

Copy link
Contributor

@hpacleb hpacleb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, tested locally and everything seems to work as expected. Looks good to me.

@yajra
Copy link
Owner

yajra commented Aug 5, 2023

Everything looks correct except for multiple column fullText:

$table->fullText(['name', 'username', 'email'], 'users_fulltext_search');

Error

Error Code    : 29851
Error Message : ORA-29851: cannot build a domain index on more than one column
Position      : 51
Statement     : create index users_fulltext_search on users (name, username, email) indextype is ctxsys.context parameters ('sync(on commit)')
Bindings      : []
 (Connection: oracle, SQL: create index users_fulltext_search on users (name, username, email) indextype is ctxsys.context parameters ('sync(on commit)'))

Tested on Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production

tests/Database/Oci8SchemaGrammarTest.php Outdated Show resolved Hide resolved
@yajra yajra requested a review from hpacleb August 12, 2023 02:10
@jonas-elias jonas-elias requested a review from yajra December 6, 2023 04:28
@yajra
Copy link
Owner

yajra commented Dec 14, 2023

@jonas-elias thank you for the updates. We will review it as soon as we can.

Ping @hpacleb ^_^

@richardcardoso198
Copy link

Any updates on this?

@yajra yajra changed the base branch from 10.x to master December 31, 2024 07:02
@yajra yajra changed the title FullText Search in laravel-oci8 feat: FullText Search in laravel-oci8 Dec 31, 2024
@yajra
Copy link
Owner

yajra commented Dec 31, 2024

Updated and targeted to master (Laravel 11) branch

Copy link
Owner

@yajra yajra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. For checking in actual projects.

@yajra
Copy link
Owner

yajra commented Dec 31, 2024

Test Code

$table->fullText(['name', 'username', 'email'], 'users_fulltext_search');

Error

Error Code    : 6550
Error Message : ORA-06550: line 1, column 7:
PLS-00201: identifier 'CTX_DDL' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ORA-06550: line 2, column 17:
PLS-00201: identifier 'CTX_DDL' must be declared
ORA-06550: line 2, column 17:
PL/SQL: Statement ignored
Help: https://docs.oracle.com/error-help/db/ora-06550/
Position      : 6
Statement     : BEGIN ctx_ddl.create_preference('users_fulltext_search_preference', 'MULTI_COLUMN_DATASTORE');
                ctx_ddl.set_attribute('users_fulltext_search_preference', 'COLUMNS', 'name, username, email'); END;
Bindings      : []
 (Connection: oracle, SQL: BEGIN ctx_ddl.create_preference('users_fulltext_search_preference', 'MULTI_COLUMN_DATASTORE');
                ctx_ddl.set_attribute('users_fulltext_search_preference', 'COLUMNS', 'name, username, email'); END;)

Encountered the error above which might be due to Oracle23ai free docker instance.


Using a single column, the PR seems to work fine:

$table->fullText('name', 'users_fulltext_search');

@yajra
Copy link
Owner

yajra commented Dec 31, 2024

2 Tests failing:

There were 2 failures:

1) Yajra\Oci8\Tests\Database\Oci8SchemaGrammarTest::testAddingMSingleColumnFullTextIndex
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'...te 'create index name on users (name) indextype is\n
+'...te 'create index name on "USERS" (name) indextype is \n
                 ctxsys.c...'

2) Yajra\Oci8\Tests\Database\Oci8SchemaGrammarTest::testAddingMultipleColumnsFullTextIndex
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'... 'create index name_0 on users (firstname) indextype is\n
-                ctxsys.context parameters (''datastore name_preference sync(on commit)'')'; execute immediate 'create index name_1 on users (lastname) indextype is\n
+'... 'create index name_0 on "USERS" (firstname) indextype is \n
+                ctxsys.context parameters (''datastore name_preference sync(on commit)'')'; execute immediate 'create index name_1 on "USERS" (lastname) indextype is \n
                 ctxsys.c...'

@yajra yajra self-requested a review January 21, 2025 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants