title: Lucene search query dynamic update and add additional query fields?
body: <p>I am working on facet search, one of the requirement is to select id values from facet drop-down. <strong><em>id</em></strong> values will be in the range 1-digit to 16-digit, but in data these <strong><em>id</em></strong> values will be from 8-digit to 16-digit.  </p>
  
  <p>I have to support following use-cases, both from UI and REST api. </p>
  
  <p>Sample Query:  </p>
  
  <pre>http://localhost:7001/app/api/search/meta.type:typeA AND id:value?results=facet:id</pre>
  
  <p>Requirement is to correct query, based on values passed for attribute <strong><em>id</em></strong>.
  If passed value's length is less than 8 digits. i.e. if the  is less than 99999999, I have to do a regex search, otherwise normal matching search.<br>
  Ex:  </p>
  
  <blockquote>
    <p>1)<br>
    actual:       +meta.type:typeA +id<br>
    modified      +meta.type:typeA +id:8 +id:8*<br>
    2)<br>
    actual        +meta.type:typeA +id:4567<br>
    modified      +meta.type:typeA +id:4567 +id:4567*<br>
    3)<br>
    actual        +meta.type:typeA +id:12345678<br>
    modified      +meta.type:typeA +id:12345678 +id:12345678*<br>
    4)<br>
    actual        +meta.type:typeA +id:123456789<br>
    modified      +meta.type:typeA +id:123456789  </p>
  </blockquote>
  
  <p>Query type is BooleanQuery.</p>
  
  <p>I have tried following, but it has no effect on query value. (Adding another value to the query as the first one wouldn't return anything)</p>
  
  <pre><code>Query [] termArray = new Query [1];
  BooleanQuery bq = new BooleanQuery();
  bq.add(new TermQuery(new Term("id", queryKeyValue + "*")), BooleanClause.Occur.MUST);
  termArray[0] = Query.mergeBooleanQueries(bq);;
  query.combine(termArray);
  </code></pre>
  
  <p>I am using Lucene 3.6 libraries.<br>
  I have a doubt, this kind of updates on query are possible or not.<br>
  If this is valid scenario and can be achieved, can anyone help me with this?   </p>