contributions/mobl/www/js/persistence.search.js
/**
   * Parses a search query and returns it as list SQL parts later to be OR'ed or AND'ed.
   */
Parses a search query and returns it as list SQL parts later to be OR'ed or AND'ed.
Parses a search query and returns it as list SQL parts later to be OR ' ed or AND ' ed .
function searchPhraseParser(query, indexTbl, prefixByDefault) {
    query = query.toLowerCase().replace(/['"]/, '').replace(/(^\s+|\s+$)/g, '');
    var words = query.split(/\s+/);
    var sqlParts = [];
    var restrictedToColumn = null;
    for(var i = 0; i < words.length; i++) {
      var word = normalizeWord(words[i], !prefixByDefault);
      if(!word) {
        continue;
      }
      if(word.search(/:$/) !== -1) {
        restrictedToColumn = word.substring(0, word.length-1);
        continue;
      } 
      var sql = '(';
      if(word.search(/\*/) !== -1) {
        sql += "`" + indexTbl + "`.`word` LIKE '" + word.replace(/\*/g, '%') + "'";
      } else if(prefixByDefault) {
        sql += "`" + indexTbl + "`.`word` LIKE '" + word + "%'";
      } else {
        sql += "`" + indexTbl + "`.`word` = '" + word + "'";
      }
      if(restrictedToColumn) {
        sql += ' AND `' + indexTbl + "`.`prop` = '" + restrictedToColumn + "'";
      }
      sql += ')';
      sqlParts.push(sql);
    }
    return sqlParts;
  }
function searchPhraseParser ( query , indexTbl , prefixByDefault ) { query = query . toLowerCase ( ) . replace ( / ['"] / , '' ) . replace ( / (^\s+|\s+$) / g , '' ) ; var words = query . split ( / \s+ / ) ; var sqlParts = [ ] ; var restrictedToColumn = null ; for ( var i = 0 ; i < words . length ; i ++ ) { var word = normalizeWord ( words [ i ] , ! prefixByDefault ) ; if ( ! word ) { continue ; } if ( word . search ( / :$ / ) !== - 1 ) { restrictedToColumn = word . substring ( 0 , word . length - 1 ) ; continue ; } var sql = '(' ; if ( word . search ( / \* / ) !== - 1 ) { sql += "`" + indexTbl + "`.`word` LIKE '" + word . replace ( / \* / g , '%' ) + "'" ; } else if ( prefixByDefault ) { sql += "`" + indexTbl + "`.`word` LIKE '" + word + "%'" ; } else { sql += "`" + indexTbl + "`.`word` = '" + word + "'" ; } if ( restrictedToColumn ) { sql += ' AND `' + indexTbl + "`.`prop` = '" + restrictedToColumn + "'" ; } sql += ')' ; sqlParts . push ( sql ) ; } return sqlParts ; }
Parses a search query and returns it as list SQL parts later to be OR'ed or AND'ed.
Parses a search query and returns it as list SQL parts later to be OR ' ed or AND ' ed .