const stringFieldsSymbol = Symbol('__cachedStringFields')

function reduceType(type, reducer, accumulator, path = [], maxDepth = 10) {
  if (maxDepth < 0) {
    return accumulator
  }
  if (Array.isArray(type.fields)) {
    return type.fields.reduce(
      (acc, field, index) =>
        reduceType(field.type, reducer, acc, path.concat(field.name), maxDepth - 1),
      reducer(accumulator, type, path)
    )
  }
  return reducer(accumulator, type, path)
}

function getCachedStringFieldPaths(type, maxDepth) {
  if (!type[stringFieldsSymbol]) {
    type[stringFieldsSymbol] = getStringFieldPaths(type, maxDepth)
  }
  return type[stringFieldsSymbol]
}

function getStringFieldPaths(type, maxDepth) {
  const reducer = (accumulator, childType, path) =>
    childType.jsonType === 'string' ? [...accumulator, path] : accumulator

  return reduceType(type, reducer, [], [], maxDepth)
}

export default function resolveSearchFields(type) {
  return getCachedStringFieldPaths(type, 4).map(path => path.join('.'))
}

@@ -123,13 +123,8 @@
 epth
- = 10
 ) %7B%0A
@@ -178,16 +178,45 @@
 %7D%0A  if (
+type.jsonType === 'array' && 
 Array.is
@@ -226,22 +226,18 @@
 ay(type.
+o
 f
-ields
 )) %7B%0A   
@@ -248,64 +248,373 @@
 urn 
-type.fields.reduce(%0A      (acc, field, index) =%3E%0A       
+reduceArray(type, reducer, accumulator, path, maxDepth)%0A  %7D%0A  if (type.jsonType === 'object' && Array.isArray(type.fields)) %7B%0A    return reduceObject(type, reducer, accumulator, path, maxDepth)%0A  %7D%0A  return reducer(accumulator, type, path)%0A%7D%0A%0Afunction reduceArray(arrayType, reducer, accumulator, path, maxDepth) %7B%0A  return arrayType.of.reduce(%0A    (acc, ofType) =%3E
  red
@@ -625,15 +625,11 @@
 ype(
-field.t
+ofT
 ype,
@@ -651,27 +651,8 @@
 path
-.concat(field.name)
 , ma
@@ -672,18 +672,70 @@
     
-  reducer(
+accumulator%0A  )%0A%7D%0A%0Afunction reduceObject(objectType, reducer, 
 accu
@@ -747,30 +747,162 @@
 or, 
-type, pa
+path, maxDep
 th)
+ %7B
 %0A  
-  )%0A  %7D%0A
+return objectType.fields.reduce((acc, field) =%3E %7B%0A    const segment = %60$%7Bfield.name%7D$%7Bfield.type.jsonType === 'array' ? '%5B%5D' : ''%7D%60%0A  
   re
@@ -916,33 +916,91 @@
 duce
-r(accumulator, type, path
+Type(field.type, reducer, acc, path.concat(segment), maxDepth - 1)%0A  %7D, accumulator
 )%0A%7D%0A

Improve text search within arrays (#947)