lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene-sandbox/contributions/javascript/queryConstructor luceneQueryConstructor.html luceneQueryConstructor.js
Date Fri, 23 Jan 2004 16:59:38 GMT
ehatcher    2004/01/23 08:59:38

  Modified:    contributions/javascript/queryConstructor
                        luceneQueryConstructor.html
                        luceneQueryConstructor.js
  Log:
  enhanced sample, but validator is acting up it seems.  kelvin - am i doing something wrong?
  
  Revision  Changes    Path
  1.2       +49 -9     jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html
  
  Index: luceneQueryConstructor.html
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- luceneQueryConstructor.html	9 May 2002 02:18:00 -0000	1.1
  +++ luceneQueryConstructor.html	23 Jan 2004 16:59:38 -0000	1.2
  @@ -2,27 +2,67 @@
     <head>
       <title>Demo Lucene Query Constructor</title>
       <script type="text/javascript" src="luceneQueryConstructor.js"></script>
  +    <script type="text/javascript" src="../queryValidator/luceneQueryValidator.js"></script>
     </head>
  -  
  +
     <body>
       <form>
  +      <p>
         <input type="hidden" name="query">
         Name:
         <input type="text" name="name">
         <select name="nameModifier">
  -        <option value="And" />And 
  -        <option value="Or" selected/>Or
  -        <option value="Not" />Not
  +        <option value="And">And</option>
  +        <option value="Or" selected="selected">Or</option>
  +        <option value="Not">Not</option>
         </select>
  +      </p>
  +
         <p>
         Description:
         <input type="text" name="description">
         <select name="descriptionModifier">
  -        <option value="And" />And 
  -        <option value="Or" selected/>Or
  -        <option value="Not" />Not
  -      </select>  
  -      <input type="button" name="Search" value="Search" onClick="doMakeQuery(this.form.query)"
/>
  +        <option value="And">And</option>
  +        <option value="Or" selected="selected">Or</option>
  +        <option value="Not">Not</option>
  +      </select>
  +      </p>
  +
  +      <p>
  +      Required Select:
  +      <select name="choice">
  +        <option value="one">One</option>
  +        <option value="two">Two</option>
  +      </select>
  +      <input type="hidden" name="choiceModifier" value="And"/>
  +      </p>
  +
  +      <p>
  +      Multi-select:
  +      <select name="multi" multiple="true" size="5">
  +        <option value="multi1">multi1</option>
  +        <option value="multi2">multi2</option>
  +        <option value="multi3">multi3</option>
  +        <option value="multi4">multi4</option>
  +      </select>
  +      <input type="hidden" name="multiModifier" value="Or"/>
  +      </p>
  +
  +      <p>
  +      Radio:
  +      <!-- TODO: something fishy happens if none selected -->
  +      <input type="radio" name="radio" value="wnrn" checked="checked" />WNRN
  +      <input type="radio" name="radio" value="klpx" />KLPX
  +      <input type="hidden" name="radioModifier" value="And"/>
  +      </p>
  +
  +      <p>
  +      Current Query:
  +      <pre id="curQuery"></pre>
  +      </p>
  +
  +      <input type="button" name="Update" value="Update Query" onClick="doMakeQuery(this.form.query);
curQuery.innerText = this.form.query.value" />
  +      <input type="button" name="Validate" value="Validate" onClick="doCheckLuceneQuery(this.form.query);"
/>
       </form>
     </body>
   </html>
  
  
  
  1.7       +18 -17    jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js
  
  Index: luceneQueryConstructor.js
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- luceneQueryConstructor.js	8 May 2003 06:00:02 -0000	1.6
  +++ luceneQueryConstructor.js	23 Jan 2004 16:59:38 -0000	1.7
  @@ -33,14 +33,14 @@
   {
     if(typeof(dbg) != "undefined")
       debug = dbg;
  -    
  +
     var frm = query.form;
     var formElements = frm.elements;
     query.value = '';
  -  
  +
     // keep track of the fields we've examined
     var dict = new Array();
  -  
  +
     for(var i=0; i<formElements.length; i++)
     {
       var element = formElements[i];
  @@ -48,10 +48,11 @@
       if(!contains(dict, elementName))
       {
         dict[dict.length] = elementName;
  -      
  +
         // ensure we get the whole group (of checkboxes, radio, etc), if applicable
  -      var elementValue = getFieldValue(frm[element.name]);
  -      if(elementValue.length > 0)
  +      var elementValue = trim(getFieldValue(frm[element.name]));
  +
  +      if(elementValue.length > 0 && elementValue != ' ')
         {
           var subElement = frm[elementName + modifierSuffix];
           if(typeof(subElement) != "undefined") // found a field/fieldModifier pair
  @@ -62,7 +63,7 @@
             if(logic == 'And')
             {
               addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue);
  -          }     
  +          }
             else if(logic == 'Not')
             {
               addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue);
  @@ -79,12 +80,12 @@
         }
       }
     }
  -  
  +
     if(debug)
     {
       alert('Query:' + query.value);
     }
  -  
  +
     if(submitOnConstruction)
     {
       frm.submit();
  @@ -107,9 +108,9 @@
       return getCheckedValues(field);
     if(typeof(field[0]) != "undefined" && field[0].type=="radio")
       return getRadioValue(field);
  -  if(field.type.match("select*")) 
  +  if(field.type.match("select*"))
       return getSelectedValues(field);
  -  
  +
     return field.value;
   }
   
  @@ -146,7 +147,7 @@
   function addFieldWithModifier(query, modifier, field, fieldValue)
   {
     fieldValue = trim(fieldValue);
  -  
  +
     if(query.value.length == 0)
     {
       query.value = modifier + '(' + field + ':(' + fieldValue + '))';
  @@ -154,19 +155,19 @@
     else
     {
       query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))';
  -  }  
  +  }
   }
   
   function trim(inputString) {
      if (typeof inputString != "string") { return inputString; }
  -   
  +
      var temp = inputString;
  -   
  +
      // Replace whitespace with a single space
      var pattern = /\s+/ig;
      temp = temp.replace(pattern, " ");
  -  
  -   // Trim 
  +
  +   // Trim
      pattern = /^(\s*)([\w\W]*)(\b\s*$)/;
      if (pattern.test(temp)) { temp = temp.replace(pattern, "$2"); }
      return temp; // Return the trimmed string back to the user
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message