src/db/search.js
function search(query, options = {}) {
  const {
    format = 'idCode',
    mode = 'substructure',
    flattenResult = true,
    keepMolecule = false,
    limit = Number.MAX_SAFE_INTEGER
  } = options;

  if (typeof query === 'string') {
    const getMoleculeCreators = require('./moleculeCreators');
    const moleculeCreators = getMoleculeCreators(this.OCL.Molecule);
    query = moleculeCreators.get(format.toLowerCase())(query);
  } else if (!(query instanceof this.OCL.Molecule)) {
    throw new TypeError('toSearch must be a Molecule or string');
  }

  let result;
  switch (mode.toLowerCase()) {
    case 'exact':
      result = exactSearch(this.moleculeDB.db, query, limit);
      break;
    case 'substructure':
      result = subStructureSearch(this.moleculeDB, query, limit);
      break;
    case 'similarity':
      result = similaritySearch(this.moleculeDB, this.OCL, query, limit);
      break;
    default:
      throw new Error(`unknown search mode: ${options.mode}`);
  }
  return processResult(result, { flattenResult, keepMolecule, limit });
}
function search(query, options = {}) {
  const {
    format = 'idCode',
    mode = 'substructure',
    flattenResult = true,
    keepMolecule = false,
    limit = Number.MAX_SAFE_INTEGER
  } = options;

  if (typeof query === 'string') {
    const getMoleculeCreators = require('./moleculeCreators');
    const moleculeCreators = getMoleculeCreators(this.OCL.Molecule);
    query = moleculeCreators.get(format.toLowerCase())(query);
  } else if (!(query instanceof this.OCL.Molecule)) {
    throw new TypeError('toSearch must be a Molecule or string');
  }

  let result;
  switch (mode.toLowerCase()) {
    case 'exact':
      result = exactSearch(this.moleculeDB.db, query, limit);
      break;
    case 'substructure':
      result = subStructureSearch(this.moleculeDB, query, limit);
      break;
    case 'similarity':
      result = similaritySearch(this.moleculeDB, this.OCL, query, limit);
      break;
    default:
      throw new Error(`unknown search mode: ${options.mode}`);
  }
  return processResult(result, { flattenResult, keepMolecule, limit });
}
function search ( query , options = { } ) { const { format = 'idCode' , mode = 'substructure' , flattenResult = true , keepMolecule = false , limit = Number . MAX_SAFE_INTEGER } = options ; if ( typeof query === 'string' ) { const getMoleculeCreators = require ( './moleculeCreators' ) ; const moleculeCreators = getMoleculeCreators ( this . OCL . Molecule ) ; query = moleculeCreators . get ( format . toLowerCase ( ) ) ( query ) ; } else if ( ! ( query instanceof this . OCL . Molecule ) ) { throw new TypeError ( 'toSearch must be a Molecule or string' ) ; } let result ; switch ( mode . toLowerCase ( ) ) { case 'exact' : result = exactSearch ( this . moleculeDB . db , query , limit ) ; break ; case 'substructure' : result = subStructureSearch ( this . moleculeDB , query , limit ) ; break ; case 'similarity' : result = similaritySearch ( this . moleculeDB , this . OCL , query , limit ) ; break ; default : throw new Error ( ` ${ options . mode } ` ) ; } return processResult ( result , { flattenResult , keepMolecule , limit } ) ; }
Search in a MoleculeDB
Inside the database all the same molecules are group together
@memberof DB
@instance
@param {string|OCL.Molecule} [query] smiles, molfile, oclCode or instance of Molecule to look for
@param {object} [options={}]
@param {string} [options.format='idCode'] - query is in the format 'smiles', 'oclid' or 'molfile'
@param {string} [options.mode='substructure'] - search by 'substructure', 'exact' or 'similarity'
@param {boolean} [options.flattenResult=true] - The database group the data for the same product. This allows to flatten the result
@param {boolean} [options.keepMolecule=false] - keep the OCL.Molecule object in the result
@param {number} [options.limit=Number.MAX_SAFE_INTEGER] - maximal number of result
@return {Array} array of object of the type {(molecule), idCode, data, properties}
Search in a MoleculeDB Inside the database all the same molecules are group together