title: Lucene - How can you modify a Query object's terms?
body: <p>I want to add new fields to my Lucene-based search engine site, however I want to be able to intercept queries and modify them before I pass them on to the Searcher.</p>
  
  <p>For example each document has the field <code>userid</code> so you can search for documents authored by a particular user by their ID, e.g. <code>foo bar userid:123</code> however I want to add the ability to search by username.</p>
  
  <p>I'd like to add a field <code>user:RonaldMcDonald</code> to queries (<strong>not</strong> to documents), however I want to be able to intercept that term and replace it with an equivalent <code>userid:123</code> term (my own code would be responsible for converting "RonaldMcDonald" to "123").</p>
  
  <p>Here's the simple code I'm using right now:</p>
  
  <pre><code>Int32 get = (pageIndex + 1) * pageSize;
  
  Query query;
  
  try {
  
      query = _queryParser.Parse( queryText );
  
  } catch(ParseException pex) {
  
      log.Add("Could not parse query.");
      throw new SearchException( "Could not parse query text.", pex );
  }
  
  log.Add("Parsed query.");
  
  TopDocs result = _searcher.Search( query, get );
  </code></pre>
  
  <p>I've had a look at the Query class, but I can't see any way to retrieve, remove, or insert terms.</p>