You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by ke...@apache.org on 2002/05/09 04:18:00 UTC

cvs commit: jakarta-lucene-sandbox/contributions/javascript/queryConstructor luceneQueryConstructor.js luceneQueryConstructor.html

kelvint     02/05/08 19:18:00

  Added:       contributions/javascript/queryConstructor
                        luceneQueryConstructor.js
                        luceneQueryConstructor.html
  Log:
  Initial commit of a javascript lib as a web-based GUI for boolean query construction.
  Based on the file posted at http://marc.theaimsgroup.com/?l=lucene-user&m=101366456309906&w=2.
  
  Revision  Changes    Path
  1.1                  jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js
  
  Index: luceneQueryConstructor.js
  ===================================================================
  // Lucene Search Query Constructor
  // Author:  Kelvin Tan  (kelvin@relevanz.com)
  // Date:    14/02/2002
  // Version: 1.1
  
  // Change this according to what you use to name the field modifiers in your form.
  // e.g. with the field "name", the modifier will be called "nameModifier"
  var modifierSuffix = 'Modifier';
  
  // Do you wish the query to be displayed as an alert box?
  var debug = true;
  
  // Do you wish the function to submit the form upon query construction?
  var submitOnConstruction = true;
  
  // Constructs the query
  // @param query Form field to represent the constructed query to be submitted
  function doMakeQuery( query )
  {
    var frm = query.form;
    var formElements = frm.elements;
    query.value = '';
    for(var i=0; i<formElements.length; i++)
    {
      var element = formElements[i];
      var elementName = element.name;
      var elementValue = element.value;
      if(elementValue.length > 0)
      {
        for(var j=0; j<formElements.length; j++)
        {
          var subElement = formElements[j];
          if(subElement.name == (elementName + modifierSuffix))
          {
            var subElementValue = subElement.options[subElement.selectedIndex].value;
            if(subElementValue == 'And')
            {
              addAnd(query, elementName, elementValue);
            }     
            else if(subElementValue == 'Not')
            {
              addNot(query, elementName, elementValue);
            }
            else if(subElementValue == 'Or')
            {
              addOr(query, elementName, elementValue);
            }
          }
        }
      }
    }
    
    if(debug)
    {
      alert('Query:' + query.value);
    }
    
    if(submitOnConstruction)
    {
      frm.submit();
    }
  }
  
  function addOr(query, field, fieldValue)
  {
    if(query.value.length == 0)
    {
      query.value = '(' + field + ':(' + fieldValue + '))';
    }
    else
    {
      query.value = query.value + ' (' + field + ':(' + fieldValue + '))';
    }  
  }
  
  function addAnd(query, field, fieldValue)
  {
    if(query.value.length == 0)
    {
      query.value = '+(' + field + ':(' + fieldValue + '))';
    }
    else
    {
      query.value = query.value + ' +(' + field + ':(' + fieldValue + '))';
    }  
  }
  
  function addNot(query, field, fieldValue)
  {
    if(query.value.length == 0)
    {
      query.value = '-(' + field + ':(' + fieldValue + '))';
    }
    else
    {
      query.value = query.value + ' -(' + field + ':(' + fieldValue + '))';
    }  
  }
  
  
  1.1                  jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html
  
  Index: luceneQueryConstructor.html
  ===================================================================
  <html>
    <head>
      <title>Demo Lucene Query Constructor</title>
      <script type="text/javascript" src="luceneQueryConstructor.js"></script>
    </head>
    
    <body>
      <form>
        <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
        </select>
        <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)" />
      </form>
    </body>
  </html>
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>