use of com.yelp.nrtsearch.server.grpc.Field in project nrtsearch by Yelp.
the class AnalyzerCreatorTest method testHasAnalyzerIndexAnalyzerPresent.
@Test
public void testHasAnalyzerIndexAnalyzerPresent() {
Field field = Field.newBuilder().setIndexAnalyzer(getPredefinedAnalyzer()).build();
assertTrue(hasAnalyzer(field));
}
use of com.yelp.nrtsearch.server.grpc.Field in project nrtsearch by Yelp.
the class AnalyzerCreatorTest method testHasAnalyzerSearchAnalyzerPresent.
@Test
public void testHasAnalyzerSearchAnalyzerPresent() {
Field field = Field.newBuilder().setIndexAnalyzer(getPredefinedAnalyzer()).build();
assertTrue(hasAnalyzer(field));
}
use of com.yelp.nrtsearch.server.grpc.Field in project nrtsearch by Yelp.
the class AnalyzerCreatorTest method testHasAnalyzerNoAnalyzer.
@Test
public void testHasAnalyzerNoAnalyzer() {
Field field = Field.newBuilder().build();
assertFalse(hasAnalyzer(field));
}
use of com.yelp.nrtsearch.server.grpc.Field in project nrtsearch by Yelp.
the class FieldDefCreatorTest method testPluginProvidesFieldType.
@Test
public void testPluginProvidesFieldType() {
init(Collections.singletonList(new TestFieldTypePlugin()));
Field field = Field.newBuilder().setType(FieldType.CUSTOM).setAdditionalProperties(Struct.newBuilder().putFields("type", Value.newBuilder().setStringValue("custom_field_type").build()).build()).build();
FieldDef testFieldDef = FieldDefCreator.getInstance().createFieldDef("test_field", field);
assertTrue(testFieldDef instanceof TestFieldDef);
}
use of com.yelp.nrtsearch.server.grpc.Field in project nrtsearch by Yelp.
the class RegisterFieldsHandler method handle.
/* Sets the FieldDef for every field specified in FieldDefRequest and saves it in IndexState.fields member
* returns the String representation of the same */
@Override
public FieldDefResponse handle(final IndexState indexState, FieldDefRequest fieldDefRequest) throws RegisterFieldsException {
assert indexState != null;
final Map<String, FieldDef> pendingFieldDefs = new HashMap<>();
final Map<String, String> saveStates = new HashMap<>();
Set<String> seen = new HashSet<>();
// request (or, from the saved json):
for (int pass = 0; pass < 2; pass++) {
List<Field> fields = fieldDefRequest.getFieldList();
for (Field currentField : fields) {
String fieldName = currentField.getName();
if (pass == 1 && seen.contains(fieldName)) {
continue;
}
;
if (pass == 0 && FieldType.VIRTUAL.equals(currentField.getType())) {
// request
continue;
}
if (!IndexState.isSimpleName(fieldName)) {
throw new RegisterFieldsException("invalid field name \"" + fieldName + "\": must be [a-zA-Z_][a-zA-Z0-9]*");
}
if (fieldName.endsWith("_boost")) {
throw new RegisterFieldsException("invalid field name \"" + fieldName + "\": field names cannot end with _boost");
}
if (seen.contains(fieldName)) {
throw new RegisterFieldsException("field \"" + fieldName + "\" appears at least twice in this request");
}
seen.add(fieldName);
try {
// convert Proto object to Json String
String currentFieldAsJsonString = JsonFormat.printer().print(currentField);
saveStates.put(fieldName, currentFieldAsJsonString);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
FieldDef fieldDef = parseOneFieldType(indexState, pendingFieldDefs, fieldName, currentField);
if (fieldDef instanceof IdFieldDef) {
verifyOnlyOneIdFieldExists(indexState, pendingFieldDefs, fieldDef);
}
pendingFieldDefs.put(fieldName, fieldDef);
if (fieldDef instanceof IndexableFieldDef) {
addChildFields((IndexableFieldDef) fieldDef, pendingFieldDefs);
}
}
}
// add FieldDef and its corresponding JsonObject to states variable in IndexState
for (Map.Entry<String, FieldDef> ent : pendingFieldDefs.entrySet()) {
if (IndexState.isChildName(ent.getKey())) {
// child field will be present in top level field json
indexState.addField(ent.getValue(), null);
} else {
JsonObject fieldAsJsonObject = jsonParser.parse(saveStates.get(ent.getKey())).getAsJsonObject();
indexState.addField(ent.getValue(), fieldAsJsonObject);
}
}
String response = indexState.getAllFieldsJSON();
FieldDefResponse reply = FieldDefResponse.newBuilder().setResponse(response).build();
return reply;
}
Aggregations