Skip to content

Commit

Permalink
feat(psl): [prep work] GA "fullTextSearch" preview feature for MySQL,…
Browse files Browse the repository at this point in the history
… rename it to "nativeFullTextSearchPostgres" for Postgres
  • Loading branch information
jkomyno committed Nov 26, 2024
1 parent 06d4b2f commit 91fc22e
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions libs/user-facing-errors/src/query_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ pub struct QueryParameterLimitExceeded {
#[derive(Debug, UserFacingError, Serialize)]
#[user_facing(
code = "P2030",
message = "Cannot find a fulltext index to use for the search, try adding a @@fulltext([Fields...]) to your schema"
message = "Cannot find a fulltext index to use for the native search, try adding a @@fulltext([Fields...]) to your schema"
)]
pub struct MissingFullTextSearchIndex {}
pub struct MissingNativeFullTextSearchIndex {}

#[derive(Debug, UserFacingError, Serialize)]
#[user_facing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Conne
AdvancedJsonNullability |
IndexColumnLengthPrefixing |
FullTextIndex |
FullTextSearch |
FullTextSearchWithIndex |
NativeFullTextSearch |
NativeFullTextSearchWithIndex |
MultipleFullTextAttributesPerModel |
ImplicitManyToManyRelation |
DecimalType |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Conne
CreateSkipDuplicates |
Enums |
EnumArrayPush |
FullTextSearch |
FullTextSearchWithoutIndex |
NativeFullTextSearch |
NativeFullTextSearchWithoutIndex |
InsensitiveFilters |
Json |
JsonFiltering |
Expand Down
5 changes: 3 additions & 2 deletions psl/psl-core/src/common/preview_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ features!(
FilterJson,
FullTextIndex,
FullTextSearch,
NativeFullTextSearchPostgres,
GroupBy,
ImprovedQueryRaw,
InteractiveTransactions,
Expand Down Expand Up @@ -90,7 +91,6 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
active: enumflags2::make_bitflags!(PreviewFeature::{
Deno
| DriverAdapters
| FullTextSearch
| Metrics
| MultiSchema
| NativeDistinct
Expand All @@ -117,6 +117,7 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
| FilteredRelationCount
| FilterJson
| FullTextIndex
| FullTextSearch
| GroupBy
| ImprovedQueryRaw
| InteractiveTransactions
Expand All @@ -136,7 +137,7 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
| TransactionApi
| UncheckedScalarInputs
}),
hidden: enumflags2::make_bitflags!(PreviewFeature::{ReactNative | TypedSql}),
hidden: enumflags2::make_bitflags!(PreviewFeature::{ReactNative | TypedSql | NativeFullTextSearchPostgres}),
};

#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions psl/psl-core/src/datamodel_connector/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ capabilities!(
AnyId, // Any (or combination of) uniques and not only id fields can constitute an id for a model.
SqlQueryRaw,
MongoDbQueryRaw,
FullTextSearch,
FullTextSearchWithoutIndex,
FullTextSearchWithIndex,
NativeFullTextSearch,
NativeFullTextSearchWithoutIndex,
NativeFullTextSearchWithIndex,
AdvancedJsonNullability, // Connector distinguishes between their null type and JSON null.
UndefinedType, // Connector distinguishes `null` and `undefined`
DecimalType, // Connector supports Prisma Decimal type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ mod chunking {
Ok(())
}

#[connector_test(capabilities(FullTextSearchWithoutIndex), exclude(MongoDb))]
#[connector_test(capabilities(NativeFullTextSearchWithoutIndex), exclude(MongoDb))]
async fn order_by_relevance_should_fail(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async fn create_row(runner: &Runner, data: &str) -> TestResult<()> {
Ok(())
}

#[test_suite(schema(schema), capabilities(FullTextSearchWithoutIndex))]
#[test_suite(schema(schema), capabilities(NativeFullTextSearchWithoutIndex))]
mod search_filter_without_index {
use indoc::indoc;

Expand Down Expand Up @@ -178,7 +178,7 @@ mod search_filter_without_index {
}
}

#[test_suite(schema(schema), capabilities(FullTextSearchWithIndex))]
#[test_suite(schema(schema), capabilities(NativeFullTextSearchWithIndex))]
mod search_filter_with_index {
use indoc::indoc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ async fn create_row(runner: &Runner, data: &str) -> TestResult<()> {
Ok(())
}

#[test_suite(schema(schema), capabilities(FullTextSearchWithoutIndex))]
#[test_suite(schema(schema), capabilities(NativeFullTextSearchWithoutIndex))]
mod order_by_relevance_without_index {
use indoc::indoc;

Expand Down Expand Up @@ -572,7 +572,7 @@ mod order_by_relevance_without_index {
}
}

#[test_suite(schema(schema), capabilities(FullTextSearchWithIndex))]
#[test_suite(schema(schema), capabilities(NativeFullTextSearchWithIndex))]
mod order_by_relevance_with_index {
use indoc::indoc;

Expand Down
8 changes: 4 additions & 4 deletions query-engine/connectors/query-connector/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl ConnectorError {
},
)),

ErrorKind::MissingFullTextSearchIndex => Some(KnownError::new(
user_facing_errors::query_engine::MissingFullTextSearchIndex {},
ErrorKind::NativeMissingFullTextSearchIndex => Some(KnownError::new(
user_facing_errors::query_engine::MissingNativeFullTextSearchIndex {},
)),
ErrorKind::TransactionAborted { message } => Some(KnownError::new(
user_facing_errors::query_engine::InteractiveTransactionError { error: message.clone() },
Expand Down Expand Up @@ -270,8 +270,8 @@ pub enum ErrorKind {
#[error("The query parameter limit supported by your database is exceeded: {0}.")]
QueryParameterLimitExceeded(String),

#[error("Cannot find a fulltext index to use for the search")]
MissingFullTextSearchIndex,
#[error("Cannot find a fulltext index to use for the native search")]
NativeMissingFullTextSearchIndex,

#[error("Replica Set required for Transactions")]
MongoReplicaSetRequired,
Expand Down
4 changes: 3 additions & 1 deletion query-engine/connectors/sql-query-connector/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ impl SqlError {
SqlError::QueryParameterLimitExceeded(e) => {
ConnectorError::from_kind(ErrorKind::QueryParameterLimitExceeded(e))
}
SqlError::MissingFullTextSearchIndex => ConnectorError::from_kind(ErrorKind::MissingFullTextSearchIndex),
SqlError::MissingFullTextSearchIndex => {
ConnectorError::from_kind(ErrorKind::NativeMissingFullTextSearchIndex)
}
SqlError::InvalidIsolationLevel(msg) => ConnectorError::from_kind(ErrorKind::InternalConversionError(msg)),
SqlError::ExternalError(error_id) => ConnectorError::from_kind(ErrorKind::ExternalError(error_id)),
SqlError::TooManyConnections(e) => ConnectorError::from_kind(ErrorKind::TooManyConnections(e)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl FilterVisitorExt for FilterVisitor {
fn visit_scalar_filter(&mut self, filter: ScalarFilter, ctx: &Context<'_>) -> ConditionTree<'static> {
match filter.condition {
ScalarCondition::Search(_, _) | ScalarCondition::NotSearch(_, _) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
let mut projections = match filter.condition.clone() {
ScalarCondition::Search(_, proj) => proj,
ScalarCondition::NotSearch(_, proj) => proj,
Expand Down Expand Up @@ -958,7 +958,7 @@ fn default_scalar_filter(
comparable.not_equals(Expression::from(field_ref.aliased_col(alias, ctx)).all())
}
ScalarCondition::Search(value, _) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
let query: String = value
.into_value()
.unwrap()
Expand All @@ -968,7 +968,7 @@ fn default_scalar_filter(
comparable.matches(query)
}
ScalarCondition::NotSearch(value, _) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
let query: String = value
.into_value()
.unwrap()
Expand Down Expand Up @@ -1140,7 +1140,7 @@ fn insensitive_scalar_filter(
comparable.compare_raw("NOT ILIKE", Expression::from(field_ref.aliased_col(alias, ctx)).all())
}
ScalarCondition::Search(value, _) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
let query: String = value
.into_value()
.unwrap()
Expand All @@ -1150,7 +1150,7 @@ fn insensitive_scalar_filter(
comparable.matches(query)
}
ScalarCondition::NotSearch(value, _) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
let query: String = value
.into_value()
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl OrderByBuilder {
}
OrderBy::ToManyAggregation(order_by) => self.build_order_aggr_rel(order_by, needs_reversed_order, ctx),
OrderBy::Relevance(order_by) => {
reachable_only_with_capability!(ConnectorCapability::FullTextSearch);
reachable_only_with_capability!(ConnectorCapability::NativeFullTextSearch);
self.build_order_relevance(order_by, needs_reversed_order, ctx)
}
})
Expand Down
3 changes: 2 additions & 1 deletion query-engine/schema/src/query_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ impl QuerySchema {
}

pub(crate) fn can_full_text_search(&self) -> bool {
self.has_feature(PreviewFeature::FullTextSearch) && self.has_capability(ConnectorCapability::FullTextSearch)
// TODO: add connector-specific `self.has_native_feature(ConnectorCapability::NativeFullTextSearch)` in conjunction with the next bool.
self.has_capability(ConnectorCapability::NativeFullTextSearch)
}

/// Returns whether the loaded connector supports the join strategy.
Expand Down

0 comments on commit 91fc22e

Please sign in to comment.