/*
(non-Javadoc)

@see mtas.search.spans.util.MtasSpanQuery#rewrite(org.apache.lucene.index.
IndexReader)
5007
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQ1 = (MtasSpanQuery) q1.rewrite(reader);
    MtasSpanQuery newQ2 = (MtasSpanQuery) q2.rewrite(reader);
    if (!newQ1.equals(q1) || !newQ2.equals(q2)) {
      return new MtasSpanNotQuery(newQ1, newQ2).rewrite(reader);
    } else {
      baseQuery = (SpanNotQuery) baseQuery.rewrite(reader);
      return super.rewrite(reader);
    }
  }
1276362
void store(IndexReader reader, String field, String prefix, ValueIndex value)
   {
      synchronized (cache)
      {
         Map<Key, ValueIndex> readerCache = cache.get(reader);
         if (readerCache == null)
         {
            readerCache = new HashMap<Key, ValueIndex>();
            cache.put(reader, readerCache);
         }
         readerCache.put(new Key(field, prefix), value);
      }
   }
1203260
public void replace(PushbackReader in, int bufferSize, Writer out, String format) throws IOException
    {
        InputReader reader = Input.getInstance(in, bufferSize);
        ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer(format);
        replace(reader, out, fsp);
    }
999735
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQ1 = (MtasSpanQuery) q1.rewrite(reader);
    MtasSpanQuery newQ2 = (MtasSpanQuery) q2.rewrite(reader);
    if (!newQ1.equals(q1) || !newQ2.equals(q2)) {
      return new MtasSpanIntersectingQuery(newQ1, newQ2).rewrite(reader);
    } else if (newQ1.equals(newQ2)) {
      return newQ1;
    } else {

      boolean returnNone;
      returnNone = newQ1.getMaximumWidth() != null
          && newQ1.getMaximumWidth() == 0;
      returnNone |= newQ2.getMaximumWidth() != null
          && newQ2.getMaximumWidth() == 0;
      if (returnNone) {
        return new MtasSpanMatchNoneQuery(this.getField());
      } else {
        return super.rewrite(reader);
      }
    }
  }
939268
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newBigQuery = bigQuery.rewrite(reader);
    MtasSpanQuery newSmallQuery = smallQuery.rewrite(reader);

    if (newBigQuery == null || newBigQuery instanceof MtasSpanMatchNoneQuery
        || newSmallQuery == null
        || newSmallQuery instanceof MtasSpanMatchNoneQuery) {
      return new MtasSpanMatchNoneQuery(field);
    }

    if (newSmallQuery.getMinimumWidth() != null
        && newBigQuery.getMaximumWidth() != null
        && newSmallQuery.getMinimumWidth() > (newBigQuery.getMaximumWidth()
            + leftBoundaryBigMaximum + rightBoundaryBigMaximum)) {
      return new MtasSpanMatchNoneQuery(field);
    }

    if (autoAdjustBigQuery) {
      if (newBigQuery instanceof MtasSpanRecurrenceQuery) {
        MtasSpanRecurrenceQuery recurrenceQuery = (MtasSpanRecurrenceQuery) newBigQuery;
        if (recurrenceQuery.getIgnoreQuery() == null
            && recurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery) {
          rightBoundaryBigMaximum += leftBoundaryBigMaximum
              + recurrenceQuery.getMaximumRecurrence();
          rightBoundaryBigMinimum += leftBoundaryBigMinimum
              + recurrenceQuery.getMinimumRecurrence();
          leftBoundaryBigMaximum = 0;
          leftBoundaryBigMinimum = 0;
          newBigQuery = new MtasSpanMatchAllQuery(field);
          // System.out.println("REPLACE WITH " + newBigQuery + " (["
          // + leftBoundaryMinimum + "," + leftBoundaryMaximum + "],["
          // + rightBoundaryMinimum + "," + rightBoundaryMaximum + "])");
          return new MtasSpanWithinQuery(newBigQuery, newSmallQuery,
              leftBoundaryBigMinimum, leftBoundaryBigMaximum,
              rightBoundaryBigMinimum, rightBoundaryBigMaximum,
              autoAdjustBigQuery).rewrite(reader);
        }
      } else if (newBigQuery instanceof MtasSpanMatchAllQuery) {
        if (leftBoundaryBigMaximum > 0) {
          rightBoundaryBigMaximum += leftBoundaryBigMaximum;
          rightBoundaryBigMinimum += leftBoundaryBigMinimum;
          leftBoundaryBigMaximum = 0;
          leftBoundaryBigMinimum = 0;
          // System.out.println("REPLACE WITH " + newBigQuery + " (["
          // + leftBoundaryMinimum + "," + leftBoundaryMaximum + "],["
          // + rightBoundaryMinimum + "," + rightBoundaryMaximum + "])");
          return new MtasSpanWithinQuery(newBigQuery, newSmallQuery,
              leftBoundaryBigMinimum, leftBoundaryBigMaximum,
              rightBoundaryBigMinimum, rightBoundaryBigMaximum,
              autoAdjustBigQuery).rewrite(reader);
        }
      } else if (newBigQuery instanceof MtasSpanSequenceQuery) {
        MtasSpanSequenceQuery sequenceQuery = (MtasSpanSequenceQuery) newBigQuery;
        if (sequenceQuery.getIgnoreQuery() == null) {
          List<MtasSpanSequenceItem> items = sequenceQuery.getItems();
          List<MtasSpanSequenceItem> newItems = new ArrayList<>();
          int newLeftBoundaryMinimum = 0;
          int newLeftBoundaryMaximum = 0;
          int newRightBoundaryMinimum = 0;
          int newRightBoundaryMaximum = 0;
          for (int i = 0; i < items.size(); i++) {
            // first item
            if (i == 0) {
              if (items.get(i).getQuery() instanceof MtasSpanMatchAllQuery) {
                newLeftBoundaryMaximum++;
                if (!items.get(i).isOptional()) {
                  newLeftBoundaryMinimum++;
                }
              } else if (items.get(i)
                  .getQuery() instanceof MtasSpanRecurrenceQuery) {
                MtasSpanRecurrenceQuery msrq = (MtasSpanRecurrenceQuery) items
                    .get(i).getQuery();
                if (msrq.getQuery() instanceof MtasSpanMatchAllQuery) {
                  newLeftBoundaryMaximum += msrq.getMaximumRecurrence();
                  if (!items.get(i).isOptional()) {
                    newLeftBoundaryMinimum += msrq.getMinimumRecurrence();
                  }
                } else {
                  newItems.add(items.get(i));
                }
              } else {
                newItems.add(items.get(i));
              }
              // last item
            } else if (i == (items.size() - 1)) {
              if (items.get(i).getQuery() instanceof MtasSpanMatchAllQuery) {
                newRightBoundaryMaximum++;
                if (!items.get(i).isOptional()) {
                  newRightBoundaryMinimum++;
                }
              } else if (items.get(i)
                  .getQuery() instanceof MtasSpanRecurrenceQuery) {
                MtasSpanRecurrenceQuery msrq = (MtasSpanRecurrenceQuery) items
                    .get(i).getQuery();
                if (msrq.getQuery() instanceof MtasSpanMatchAllQuery) {
                  newRightBoundaryMaximum += msrq.getMaximumRecurrence();
                  if (!items.get(i).isOptional()) {
                    newRightBoundaryMinimum += msrq.getMinimumRecurrence();
                  }
                } else {
                  newItems.add(items.get(i));
                }
              } else {
                newItems.add(items.get(i));
              }
              // other items
            } else {
              newItems.add(items.get(i));
            }
          }
          leftBoundaryBigMaximum += newLeftBoundaryMaximum;
          leftBoundaryBigMinimum += newLeftBoundaryMinimum;
          rightBoundaryBigMaximum += newRightBoundaryMaximum;
          rightBoundaryBigMinimum += newRightBoundaryMinimum;
          if (newItems.isEmpty()) {
            rightBoundaryBigMaximum = Math.max(0,
                rightBoundaryBigMaximum + leftBoundaryBigMaximum - 1);
            rightBoundaryBigMinimum = Math.max(0,
                rightBoundaryBigMinimum + leftBoundaryBigMinimum - 1);
            leftBoundaryBigMaximum = 0;
            leftBoundaryBigMinimum = 0;
            newItems.add(new MtasSpanSequenceItem(
                new MtasSpanMatchAllQuery(field), false));
          }
          if (!items.equals(newItems) || newLeftBoundaryMaximum > 0
              || newRightBoundaryMaximum > 0) {
            newBigQuery = (new MtasSpanSequenceQuery(newItems, null, null))
                .rewrite(reader);
            // System.out.println("REPLACE WITH " + newBigQuery + " (["
            // + leftBoundaryMinimum + "," + leftBoundaryMaximum + "],["
            // + rightBoundaryMinimum + "," + rightBoundaryMaximum + "])");
            return new MtasSpanWithinQuery(newBigQuery, newSmallQuery,
                leftBoundaryBigMinimum, leftBoundaryBigMaximum,
                rightBoundaryBigMinimum, rightBoundaryBigMaximum,
                autoAdjustBigQuery).rewrite(reader);
          }
        }
      }
    }

    if (!newBigQuery.equals(bigQuery) || !newSmallQuery.equals(smallQuery)) {
      return (new MtasSpanWithinQuery(newBigQuery, newSmallQuery,
          leftBoundaryBigMinimum, leftBoundaryBigMaximum,
          rightBoundaryBigMinimum, rightBoundaryBigMaximum, autoAdjustBigQuery))
              .rewrite(reader);
    } else if (newBigQuery.equals(newSmallQuery)) {
      return newBigQuery;
    } else {
      baseQuery = (SpanWithinQuery) baseQuery.rewrite(reader);
      return super.rewrite(reader);
    }
  }
276069
public static void rewrite(NamedList<Object> nl,
      MtasSolrSearchComponent searchComponent) throws IOException {
    rewrite(nl, searchComponent, true);
  }
1183757
def _rewrite_where(self, q):
        
        if isinstance(q, Lookup):
            self._rewrite_col(q.lhs)
        if isinstance(q, Node):
            for child in q.children:
                self._rewrite_where(child)
300903
private function _getIndexWriter()
    {
        if ($this->_writer === null) {
            include_once 'Zend/Search/Lucene/Index/Writer.php';
            $this->_writer = new Zend_Search_Lucene_Index_Writer(
                $this->_directory,
                $this->_segmentInfos,
                $this->_formatVersion
            );
        }

        return $this->_writer;
    }
428739
protected boolean doReindexing(boolean dropExisting, int nThreads) {
    boolean successful = false;
    Integer oldPoolSize = ((SearchIndex) handler).getIndexingThreadPoolSize();
    String newIndexPath = null;

    hotReindexingState = "Running. Started at " + LocalDateTime.now().format(sdf);
    try {

      isResponsibleForResuming.set(true);

      //hot async reindexing with drop exiting index data
      // set offline index state
      if (dropExisting) {
        // set offline cluster wide (will make merger disposed and volatile flushed)
        if (rpcService != null && changesFilter.isShared()) {
          rpcService.executeCommandOnAllNodes(changeIndexState, true, false, false);
        } else {
          handler.setOnline(false, false, true);
        }
      }
      // launch reindexing thread safely, resume nodes if any exception occurs
      if (handler instanceof SearchIndex) {
        if (dropExisting) {
          ((SearchIndex) handler).getIndex().reindex(itemMgr);
        } else {
          String oldIndexPath = ((SearchIndex) handler).getPath();
          newIndexPath = oldIndexPath + SUFFIX_ASYNC_REINDEXING;

          //try remove new index directory if already exist
          cleanIndexDirectory(oldIndexPath + SUFFIX_ASYNC_REINDEXING);

          //hot async reindexing without remove old index
          //create new index and register it
          MultiIndex newIndex = ((SearchIndex) handler).createNewIndex(SUFFIX_ASYNC_REINDEXING);
          ErrorLog errorLog = ((SearchIndex) handler).doInitErrorLog(newIndexPath);
          ((SearchIndex) handler).getIndexRegister().register(newIndex, errorLog);
          ((SearchIndex) handler).setIndexingThreadPoolSize(nThreads > 1 ? nThreads : 1);

          //set offline the new index
          newIndex.setOnline(false, true, false);

          //start create new index
          newIndex.reindex(itemMgr);

          //set  online to flush offline index
          newIndex.setOnline(true, true, false);

          //Suspend component, on cluster mode stop all index nodes
          //All the working threads will be suspended until the resume operation is performed.
          suspend();
          ((SearchIndex) handler).getIndexRegister().unregister(newIndex);

          final File indexDir = new File(oldIndexPath);
          final File newIndexDir = new File(oldIndexPath + SUFFIX_ASYNC_REINDEXING);

          //try remove old index directory
          LOG.info("Try to clean old lucene indexes of the workspace '" + workspaceName + "'");
          cleanIndexDirectory(oldIndexPath);

          //try rename new index folder .new
          LOG.info("try to rename new lucene indexes of the workspace '" + workspaceName + "'");
          SecurityHelper.doPrivilegedIOExceptionAction((PrivilegedExceptionAction<Void>) () -> {
            DirectoryHelper.renameFile(newIndexDir, indexDir);
            return null;
          });

          // Resume all the working threads that have been previously suspended.
          resume();
        }

        successful = true;
      } else {
        LOG.error("This kind of QuerHandler class doesn't support hot reindxing.");
      }
    } catch (RepositoryException e) {
      LOG.error("Error while reindexing the workspace", e);
    } catch (SecurityException e) {
      LOG.error("Can't change state to offline.", e);
    } catch (RPCException e) {
      LOG.error("Can't change state to offline.", e);
    } catch (IOException e) {
      LOG.error("Error while reindexing the workspace", e);
    }
    // safely change state back
    catch (SuspendException e) {
      LOG.error("Can't suspend SearchIndex component, " +
              "impossible to switch to newly created index, the old index still used", e);

    } catch (ResumeException e) {
      LOG.error("Can't resume SearchIndex component, impossible to set the index online", e);
    } finally {
      if (dropExisting) {
        // finish, setting indexes back online
        if (rpcService != null && changesFilter.isShared()) {
          try {
            // if dropExisting, then queries are no allowed
            rpcService.executeCommandOnAllNodes(changeIndexState, true, true, true);
          } catch (SecurityException e) {
            LOG.error("Error setting index back online in a cluster", e);
          } catch (RPCException e) {
            LOG.error("Error setting index back online in a cluster", e);
          }
        } else {
          try {
            handler.setOnline(true, true, true);
          } catch (IOException e) {
            LOG.error("Error setting index back online locally");
          }
        }
      } else {
        ((SearchIndex) handler).setIndexingThreadPoolSize(oldPoolSize);
      }
      if (successful) {
        hotReindexingState = "Finished at " + LocalDateTime.now().format(sdf);
        LOG.info("Reindexing finished successfully.");
      } else {
        hotReindexingState = "Stopped with errors at " + LocalDateTime.now().format(sdf);
        LOG.info("Reindexing halted with errors.");
        if (!dropExisting) {
          try {
            if (newIndexPath != null)
              cleanIndexDirectory(newIndexPath);
          } catch (IOException e) {
            LOG.error("Error while removing the folder of the index used for the hot reindexing", e);

          }
        }
      }
      isResponsibleForResuming.set(false);

      return successful;
    }
  }
235408
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    if (items.size() == 1) {
      MtasSpanQuery singleQuery = items.get(0).getQuery();
      if (leftMaximum != 0 || rightMaximum != 0) {
        singleQuery = new MtasExpandSpanQuery(singleQuery, leftMinimum,
            leftMaximum, rightMinimum, rightMaximum);
      }
      return singleQuery.rewrite(reader);
    } else {
      MtasSpanSequenceItem newItem;
      MtasSpanSequenceItem previousNewItem = null;
      ArrayList<MtasSpanSequenceItem> newItems = new ArrayList<>(items.size());
      int newLeftMinimum = leftMinimum;
      int newLeftMaximum = leftMaximum;
      int newRightMinimum = rightMinimum;
      int newRightMaximum = rightMaximum;
      MtasSpanQuery newIgnoreClause = ignoreQuery != null
          ? ignoreQuery.rewrite(reader) : null;
      boolean actuallyRewritten = ignoreQuery != null
          ? !newIgnoreClause.equals(ignoreQuery) : false;
      for (int i = 0; i < items.size(); i++) {
        newItem = items.get(i).rewrite(reader);
        if (newItem.getQuery() instanceof MtasSpanMatchNoneQuery) {
          if (!newItem.isOptional()) {
            return new MtasSpanMatchNoneQuery(field);
          } else {
            actuallyRewritten = true;
          }
        } else {
          actuallyRewritten |= !items.get(i).equals(newItem);
          MtasSpanSequenceItem previousMergedItem = MtasSpanSequenceItem.merge(
              previousNewItem, newItem, ignoreQuery, maximumIgnoreLength);
          if (previousMergedItem != null) {
            newItems.set((newItems.size() - 1), previousMergedItem);
            actuallyRewritten = true;
          } else {
            newItems.add(newItem);
          }
          previousNewItem = newItem;
        }
      }
      // check first and last
      if (ignoreQuery == null) {
        ArrayList<MtasSpanSequenceItem> possibleTrimmedItems = new ArrayList<>(
            newItems.size());
        MtasSpanSequenceItem firstItem = newItems.get(0);
        MtasSpanQuery firstQuery = firstItem.getQuery();
        if (firstQuery instanceof MtasSpanMatchAllQuery) {
          newLeftMaximum++;
          if (!firstItem.isOptional()) {
            newLeftMinimum++;
          }
        } else if (firstQuery instanceof MtasSpanRecurrenceQuery) {
          MtasSpanRecurrenceQuery firstRecurrenceQuery = (MtasSpanRecurrenceQuery) firstQuery;
          if (firstRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery
              && firstRecurrenceQuery.getIgnoreQuery() == null) {
            if (!firstItem.isOptional()) {
              newLeftMinimum += firstRecurrenceQuery.getMinimumRecurrence();
              newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();
            } else {
              if (firstRecurrenceQuery.getMinimumRecurrence() == 1
                  || firstRecurrenceQuery
                      .getMinimumRecurrence() <= newLeftMinimum) {
                newLeftMinimum += 0;
                newLeftMaximum += firstRecurrenceQuery.getMaximumRecurrence();
              } else {
                possibleTrimmedItems.add(firstItem);
              }
            }
          } else {
            possibleTrimmedItems.add(firstItem);
          }
        } else {
          possibleTrimmedItems.add(firstItem);
        }
        for (int i = 1; i < (newItems.size() - 1); i++) {
          possibleTrimmedItems.add(newItems.get(i));
        }
        if (newItems.size() > 1) {
          MtasSpanSequenceItem lastItem = newItems.get((newItems.size() - 1));
          MtasSpanQuery lastQuery = lastItem.getQuery();
          if (lastQuery instanceof MtasSpanMatchAllQuery) {
            newRightMaximum++;
            if (!lastItem.isOptional()) {
              newRightMinimum++;
            }
          } else if (lastQuery instanceof MtasSpanRecurrenceQuery) {
            MtasSpanRecurrenceQuery lastRecurrenceQuery = (MtasSpanRecurrenceQuery) lastQuery;
            if (lastRecurrenceQuery.getQuery() instanceof MtasSpanMatchAllQuery
                && lastRecurrenceQuery.getIgnoreQuery() == null) {
              if (!lastItem.isOptional()) {
                newRightMinimum += lastRecurrenceQuery.getMinimumRecurrence();
                newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();
              } else if (lastRecurrenceQuery.getMinimumRecurrence() == 1
                  || lastRecurrenceQuery
                      .getMinimumRecurrence() <= newRightMinimum) {
                newRightMinimum += 0;
                newRightMaximum += lastRecurrenceQuery.getMaximumRecurrence();
              } else {
                possibleTrimmedItems.add(lastItem);
              }
            } else {
              possibleTrimmedItems.add(lastItem);
            }
          } else {
            possibleTrimmedItems.add(lastItem);
          }
        }
        if (possibleTrimmedItems.size() < newItems.size()) {
          actuallyRewritten = true;
          newItems = possibleTrimmedItems;
        }
      }
      if (!actuallyRewritten) {
        if (leftMaximum != 0 || rightMaximum != 0) {
          newLeftMinimum = leftMinimum;
          newLeftMaximum = leftMaximum;
          newRightMinimum = rightMinimum;
          newRightMaximum = rightMaximum;
          leftMinimum = 0;
          leftMaximum = 0;
          rightMinimum = 0;
          rightMaximum = 0;
          MtasSpanQuery finalQuery = new MtasExpandSpanQuery(this,
              newLeftMinimum, newLeftMaximum, newRightMinimum, newRightMaximum);
          return finalQuery.rewrite(reader);
        } else {
          return super.rewrite(reader);
        }
      } else {
        if (!newItems.isEmpty()) {
          return new MtasSpanSequenceQuery(newItems, newLeftMinimum,
              newLeftMaximum, newRightMinimum, newRightMaximum, newIgnoreClause,
              maximumIgnoreLength).rewrite(reader);
        } else {
          return new MtasSpanMatchNoneQuery(field);
        }
      }
    }
  }
1216454
public RewriteResult match(String path) {

        for (CmsRewriteAlias alias : m_aliases) {
            try {
                Pattern pattern = Pattern.compile(alias.getPatternString());
                Matcher matcher = pattern.matcher(path);
                if (matcher.matches()) {
                    String newPath = matcher.replaceFirst(alias.getReplacementString());
                    return new RewriteResult(newPath, alias);
                }
            } catch (PatternSyntaxException e) {
                LOG.warn(e.getLocalizedMessage(), e);
            } catch (IndexOutOfBoundsException e) {
                LOG.warn(e.getLocalizedMessage(), e);
            }
        }
        return null;
    }
1326358
@SuppressWarnings({ "unchecked", "unused" })
  private static void rewriteMergeList(String key, String subKey,
      NamedList<Object> snl, NamedList<Object> tnl) {
    for (int i = 0; i < tnl.size(); i++) {
      Object item = snl.get(tnl.getName(i));
      if (item != null && tnl.getVal(i) instanceof NamedList) {
        NamedList<Object> tnnl = (NamedList<Object>) tnl.getVal(i);
        Object o = tnnl.get(key);
        NamedList<Object> tnnnl;
        if (o != null && o instanceof NamedList) {
          tnnnl = (NamedList<Object>) o;
        } else {
          tnnnl = new SimpleOrderedMap<>();
          tnnl.add(key, tnnnl);
        }
        tnnnl.add(subKey, item);
      }
    }
  }
176895
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQuery = query.rewrite(reader);
    if (maximumLeft == 0 && maximumRight == 0) {
      return newQuery;
    } else if (((maximumLeft == 0) || (maximumLeft == minimumLeft))
        && ((maximumRight == 0) || (maximumRight == minimumRight))) {
      MtasSpanQuery maximumExpandedQuery = new MtasMaximumExpandSpanQuery(
          newQuery, minimumLeft, maximumLeft, minimumRight, maximumRight);
      return maximumExpandedQuery.rewrite(reader);
    } else if (!query.equals(newQuery)) {
      return new MtasExpandSpanQuery(newQuery, minimumLeft, maximumLeft,
          minimumRight, maximumRight);
    } else {
      return super.rewrite(reader);
    }
  }
834881
void resetTail(long index) {
    for (SegmentedJournalReader reader : readers) {
      if (reader.getNextIndex() >= index) {
        reader.reset(index);
      }
    }
  }
1230241
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQuery = query.rewrite(reader);
    if (maximumRecurrence == 1) {
      return newQuery;
    } else {
      MtasSpanQuery newIgnoreQuery = (ignoreQuery != null)
          ? ignoreQuery.rewrite(reader) : null;
      if (newQuery instanceof MtasSpanRecurrenceQuery) {
        // for now too difficult, possibly merge later
      }
      if (!newQuery.equals(query)
          || (newIgnoreQuery != null && !newIgnoreQuery.equals(ignoreQuery))) {
        return new MtasSpanRecurrenceQuery(newQuery, minimumRecurrence,
            maximumRecurrence, newIgnoreQuery, maximumIgnoreLength)
                .rewrite(reader);
      } else {
        return super.rewrite(reader);
      }
    }
  }
34708
public MtasSpanSequenceItem rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newSpanQuery = spanQuery.rewrite(reader);
    if (!newSpanQuery.equals(spanQuery)) {
      return new MtasSpanSequenceItem(newSpanQuery, optional);
    } else {
      return this;
    }
  }
1362800
@SuppressWarnings({ "unchecked", "rawtypes" })
  public static void rewrite(ArrayList<?> al,
      MtasSolrSearchComponent searchComponent) throws IOException {
    for (int i = 0; i < al.size(); i++) {
      if (al.get(i) instanceof NamedList) {
        rewrite((NamedList) al.get(i), searchComponent);
      } else if (al.get(i) instanceof ArrayList) {
        rewrite((ArrayList) al.get(i), searchComponent);
      }
    }
  }