-
Notifications
You must be signed in to change notification settings - Fork 40
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
add ignore_above support for nrtsearch #735
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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
140 changes: 140 additions & 0 deletions
140
src/test/java/com/yelp/nrtsearch/server/grpc/IgnoreAboveTest.java
This file contains 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,140 @@ | ||
/* | ||
* Copyright 2022 Yelp 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.yelp.nrtsearch.server.grpc; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.yelp.nrtsearch.server.config.IndexStartConfig.IndexDataLocationType; | ||
import com.yelp.nrtsearch.server.grpc.AddDocumentRequest.MultiValuedField; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class IgnoreAboveTest { | ||
|
||
@Rule public final TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
private static final List<Field> fields = | ||
List.of( | ||
Field.newBuilder() | ||
.setName("id") | ||
.setType(FieldType._ID) | ||
.setStoreDocValues(true) | ||
.setSearch(true) | ||
.build(), | ||
Field.newBuilder() | ||
.setName("field1") | ||
.setStoreDocValues(true) | ||
.setSearch(true) | ||
.setMultiValued(true) | ||
.setIgnoreAbove(12) | ||
.setType(FieldType.TEXT) | ||
.build()); | ||
|
||
@After | ||
public void cleanup() { | ||
TestServer.cleanupAll(); | ||
} | ||
|
||
private void addInitialDoc(TestServer testServer) { | ||
AddDocumentRequest addDocumentRequest = | ||
AddDocumentRequest.newBuilder() | ||
.setIndexName("test_index") | ||
.putFields("id", MultiValuedField.newBuilder().addValue("1").build()) | ||
.putFields("field1", MultiValuedField.newBuilder().addValue("first Vendor").build()) | ||
.build(); | ||
testServer.addDocs(Stream.of(addDocumentRequest)); | ||
} | ||
|
||
private void addAdditionalDoc(TestServer testServer) { | ||
AddDocumentRequest addDocumentRequest = | ||
AddDocumentRequest.newBuilder() | ||
.setIndexName("test_index") | ||
.putFields("id", MultiValuedField.newBuilder().addValue("2").build()) | ||
.putFields( | ||
"field1", | ||
MultiValuedField.newBuilder() | ||
.addValue("second Vendor") | ||
.addValue("new Vendor") | ||
.build()) | ||
.build(); | ||
testServer.addDocs(Stream.of(addDocumentRequest)); | ||
} | ||
|
||
private void verifyDocs(TestServer testServer) { | ||
SearchRequest request = | ||
SearchRequest.newBuilder() | ||
.setIndexName("test_index") | ||
.addRetrieveFields("id") | ||
.setStartHit(0) | ||
.setTopHits(10) | ||
.setQuery( | ||
Query.newBuilder() | ||
.setMatchQuery( | ||
MatchQuery.newBuilder().setField("field1").setQuery("first").build()) | ||
.build()) | ||
.build(); | ||
SearchResponse response = testServer.getClient().getBlockingStub().search(request); | ||
assertEquals(1, response.getHitsCount()); | ||
request = | ||
SearchRequest.newBuilder() | ||
.setIndexName("test_index") | ||
.addRetrieveFields("id") | ||
.setStartHit(0) | ||
.setTopHits(10) | ||
.setQuery( | ||
Query.newBuilder() | ||
.setMatchQuery( | ||
MatchQuery.newBuilder().setField("field1").setQuery("second").build()) | ||
.build()) | ||
.build(); | ||
response = testServer.getClient().getBlockingStub().search(request); | ||
assertEquals(0, response.getHitsCount()); | ||
request = | ||
SearchRequest.newBuilder() | ||
.setIndexName("test_index") | ||
.addRetrieveFields("id") | ||
.setStartHit(0) | ||
.setTopHits(10) | ||
.setQuery( | ||
Query.newBuilder() | ||
.setMatchQuery( | ||
MatchQuery.newBuilder().setField("field1").setQuery("new").build()) | ||
.build()) | ||
.build(); | ||
response = testServer.getClient().getBlockingStub().search(request); | ||
assertEquals(1, response.getHitsCount()); | ||
} | ||
|
||
@Test | ||
public void testIgnoreAbove() throws IOException { | ||
TestServer primaryServer = | ||
TestServer.builder(folder) | ||
.withAutoStartConfig(true, Mode.PRIMARY, 0, IndexDataLocationType.LOCAL) | ||
.build(); | ||
primaryServer.createIndex("test_index"); | ||
primaryServer.registerFields("test_index", fields); | ||
primaryServer.startPrimaryIndex("test_index", -1, null); | ||
addInitialDoc(primaryServer); | ||
addAdditionalDoc(primaryServer); | ||
primaryServer.refresh("test_index"); | ||
verifyDocs(primaryServer); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this value still need to be retrievable somehow? This would keep it from being stored anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal of ignoreAbove is to avoid the lucene limit 32766. docValue also has this limit for Sorted and SortedSet. It will be only retrievable if it is Binary DocValue or Stored. So I just dropped it for all.
Do you think I should keep for Stored fields only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that for elasticsearch this setting keeps the value from being indexed or stored. Though for ES the _source would still contain the value.
I assume the client will want the value at some point (?). This could maybe be done in the field itself, though a child field could also be used potentially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what would be the best approach to do it in the field itself. I'll store the binary doc value if the doc type is binary already(It should work with Orbs case here. All large text field in orbs are single value text).
If it field is declared with Sorted or Sorted Set doc value, I cannot store it as Binary for large text, it will break sorting. Or if I store with the stored field, the fillDocTask will try to read from doc values since the field definition hasDocValues is true. It would be better if we can force retrieve from doc value. or stored fields, then we can retrieve the text from stored values.
I'll add the logic to store binary doc value for the single text field first to make sure orbs can work. For further improvements, I think we can do it in a separate pr since the current master breaks for large text any way.