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:39:26 UTC

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

kelvint     02/05/08 19:39:26

  Modified:    contributions/javascript/queryConstructor
                        luceneQueryConstructor.js
  Log:
  Merged the various add* methods into a single method. Added constants for AND, NOT and OR prefix modifiers.
  Added a default modifier.
  
  Revision  Changes    Path
  1.2       +22 -32    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- luceneQueryConstructor.js	9 May 2002 02:18:00 -0000	1.1
  +++ luceneQueryConstructor.js	9 May 2002 02:39:26 -0000	1.2
  @@ -1,7 +1,5 @@
   // 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"
  @@ -13,6 +11,18 @@
   // Do you wish the function to submit the form upon query construction?
   var submitOnConstruction = true;
   
  +// prefix modifier for boolean AND queries
  +var AND_MODIFIER = '+';
  +
  +// prefix modifier for boolean NOT queries
  +var NOT_MODIFIER = '-';
  +
  +// prefix modifier for boolean OR queries
  +var OR_MODIFIER  = '';
  +
  +// default prefix modifier for boolean queries
  +var DEFAULT_MODIFIER = OR_MODIFIER;
  +
   // Constructs the query
   // @param query Form field to represent the constructed query to be submitted
   function doMakeQuery( query )
  @@ -35,15 +45,19 @@
             var subElementValue = subElement.options[subElement.selectedIndex].value;
             if(subElementValue == 'And')
             {
  -            addAnd(query, elementName, elementValue);
  +            addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue);
             }     
             else if(subElementValue == 'Not')
             {
  -            addNot(query, elementName, elementValue);
  +            addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue);
             }
             else if(subElementValue == 'Or')
             {
  -            addOr(query, elementName, elementValue);
  +            addFieldWithModifier(query, OR_MODIFIER, elementName, elementValue);
  +          }
  +          else
  +          {
  +            addFieldWithModifier(query, DEFAULT_MODIFIER, elementName, elementValue);
             }
           }
         }
  @@ -61,38 +75,14 @@
     }
   }
   
  -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)
  +function addFieldWithModifier(query, modifier, field, fieldValue)
   {
     if(query.value.length == 0)
     {
  -    query.value = '-(' + field + ':(' + fieldValue + '))';
  +    query.value = modifier + '(' + field + ':(' + fieldValue + '))';
     }
     else
     {
  -    query.value = query.value + ' -(' + field + ':(' + fieldValue + '))';
  +    query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))';
     }  
   }
  
  
  

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