-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add 'type' field support for Search Index creation. #1438
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ea8f245
Add 'type' field support for Search Index creation.
vbabanin da2ef16
Fix scala issue.
vbabanin 0c039f7
Apply suggestions from code review
vbabanin d0a2359
Update mongodb.server.release.
vbabanin f312b4c
Merge branch 'master' into JAVA-5323
vbabanin 924e435
Make nullable constructor.
vbabanin 1cc17b0
Add since to Javadoc.
vbabanin f037bd0
Make nullable constructor in Scala.
vbabanin b231c02
Fix issue with Optional.
vbabanin 334cf35
Fix test.
vbabanin 11ab1a8
Merge branch 'refs/heads/master' into JAVA-5323
vbabanin ad204cf
Make name nullable.
vbabanin d827d68
Revert "Make name nullable."
vbabanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
driver-core/src/main/com/mongodb/client/model/SearchIndexType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.client.model; | ||
|
||
import com.mongodb.annotations.Sealed; | ||
import org.bson.BsonString; | ||
import org.bson.BsonValue; | ||
|
||
import static com.mongodb.assertions.Assertions.notNull; | ||
|
||
/** | ||
* This interface represents an Atlas Search Index type, which is utilized for creating specific types of indexes. | ||
* <p> | ||
* It provides methods for creating and converting Atlas Search Index types to {@link BsonValue}. | ||
* </p> | ||
* | ||
* @mongodb.server.release 7.0 | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @see SearchIndexModel The model class that utilizes this index type. | ||
* @since 5.2 | ||
*/ | ||
@Sealed | ||
public interface SearchIndexType { | ||
|
||
/** | ||
* Returns a {@link SearchIndexType} instance representing the "search" index type. | ||
* | ||
* @return The requested {@link SearchIndexType}. | ||
*/ | ||
static SearchIndexType search() { | ||
return new SearchIndexTypeBson(new BsonString("search")); | ||
} | ||
|
||
/** | ||
* Returns a {@link SearchIndexType} instance representing the "verctorSearch" index type. | ||
vbabanin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @return The requested {@link SearchIndexType}. | ||
*/ | ||
static SearchIndexType vectorSearch() { | ||
return new SearchIndexTypeBson(new BsonString("vectorSearch")); | ||
} | ||
|
||
/** | ||
* Creates a {@link SearchIndexType} from a {@link BsonValue} in situations when there is no builder method | ||
* that better satisfies your needs. | ||
* This method cannot be used to validate the syntax. | ||
* <p> | ||
* <i>Example</i><br> | ||
* The following code creates two functionally equivalent {@link SearchIndexType}s, | ||
* though they may not be {@linkplain Object#equals(Object) equal}. | ||
* <pre>{@code | ||
* SearchIndexType method1 = SearchIndexType.vectorSearch(); | ||
* SearchIndexType method2 = SearchIndexType.of(new BsonString("vectorSearch")); | ||
vbabanin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* }</pre> | ||
* | ||
* @param indexType A {@link BsonValue} representing the required {@link SearchIndexType}. | ||
* @return The requested {@link SearchIndexType}. | ||
*/ | ||
static SearchIndexType of(final BsonValue indexType) { | ||
notNull("indexType", indexType); | ||
return new SearchIndexTypeBson(indexType); | ||
} | ||
|
||
/** | ||
* Converts this object to {@link BsonValue}. | ||
* | ||
* @return A {@link BsonValue} representing this {@link SearchIndexType}. | ||
*/ | ||
BsonValue toBsonValue(); | ||
} |
52 changes: 52 additions & 0 deletions
52
driver-core/src/main/com/mongodb/client/model/SearchIndexTypeBson.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mongodb.client.model; | ||
|
||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.bson.BsonValue; | ||
|
||
import java.util.Objects; | ||
|
||
final class SearchIndexTypeBson implements SearchIndexType { | ||
private final BsonValue bsonValue; | ||
|
||
SearchIndexTypeBson(final BsonValue bsonValue) { | ||
this.bsonValue = bsonValue; | ||
} | ||
|
||
@Override | ||
public BsonValue toBsonValue() { | ||
return bsonValue; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SearchIndexTypeBson that = (SearchIndexTypeBson) o; | ||
return Objects.equals(bsonValue, that.bsonValue); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bsonValue); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.