def from_lucene_str(
    lucene_str: str
) -> Tuple[str, List[Tuple[QueryAdjustment, str, Tuple[int, int]]]]:
  """Returns an abstract string from a lucene string.

  Args:
    lucene_str: str, A valid lucene string.

  Returns:
    A tuple of string and adjustments.
  """
  adjustments = []

  re_patterns = {
      r' \(contents\:"(.*?)"\)': [Field.CONTENTS, Operator.APPEND],
      r' \(title\:"(.*?)"\)': [Field.TITLE, Operator.APPEND],
      r' \-\(contents\:"(.*?)"\)': [Field.CONTENTS, Operator.MINUS],
      r' \-\(title\:"(.*?)"\)': [Field.TITLE, Operator.MINUS],
      r' \+\(contents\:"(.*?)"\)': [Field.CONTENTS, Operator.PLUS],
      r' \+\(title\:"(.*?)"\)': [Field.TITLE, Operator.PLUS],
  }

  matches = [
      match for re_pattern in re_patterns.keys()
      for match in re.finditer(re_pattern, lucene_str)
  ]
  for match in matches:
    span = match.span()
    matched_expression = match.group()
    # unescape
    term = match.groups()[0].replace('\\', '').strip()  # pytype: disable=attribute-error
    adjustment = QueryAdjustment(
        field=re_patterns[match.re.pattern][0],
        operator=re_patterns[match.re.pattern][1],
        term=term)
    adjustments.append((adjustment, matched_expression, span))
  adjustments = sorted(adjustments, key=lambda x: x[-1])

  base_query = lucene_str
  for (adjustment, matched_expression, span) in adjustments:
    base_query = base_query.replace(matched_expression, '', 1)
  # unescape
  base_query = base_query.replace('\\', '').strip()

  final_query = base_query
  for (adjustment, _, _) in adjustments:
    final_query += (f' {adjustment.field.value} {adjustment.operator.value} '
                    f'{adjustment.term}')

  return final_query, adjustments
Returns an abstract string from a lucene string.

  Args:
    lucene_str: str, A valid lucene string.

  Returns:
    A tuple of string and adjustments.
  
language/search_agents/muzero/state_tree.py