web/views/magicsearch.py
changeset 2567 961aa959f07a
parent 2476 1294a6bdf3bf
child 2650 18aec79ec3a3
equal deleted inserted replaced
2565:df34d3720ff5 2567:961aa959f07a
   168     """ parses through rql and translates into schema language entity names
   168     """ parses through rql and translates into schema language entity names
   169     and attributes
   169     and attributes
   170     """
   170     """
   171     priority = 2
   171     priority = 2
   172     def preprocess_query(self, uquery, req):
   172     def preprocess_query(self, uquery, req):
   173         try:
   173         rqlst = parse(uquery, print_errors=False)
   174             rqlst = parse(uquery, print_errors=False)
       
   175         except (RQLSyntaxError, BadRQLQuery), err:
       
   176             return uquery,
       
   177         schema = self.vreg.schema
   174         schema = self.vreg.schema
   178         # rql syntax tree will be modified in place if necessary
   175         # rql syntax tree will be modified in place if necessary
   179         translate_rql_tree(rqlst, trmap(self.config, schema, req.lang), schema)
   176         translate_rql_tree(rqlst, trmap(self.config, schema, req.lang), schema)
   180         return rqlst.as_string(),
   177         return rqlst.as_string(),
   181 
   178 
   202             elif len(words) == 2:
   199             elif len(words) == 2:
   203                 args = self._two_words_query(*words)
   200                 args = self._two_words_query(*words)
   204             elif len(words) == 3:
   201             elif len(words) == 3:
   205                 args = self._three_words_query(*words)
   202                 args = self._three_words_query(*words)
   206             else:
   203             else:
   207                 args = self._multiple_words_query(words)
   204                 raise
   208         return args
   205         return args
   209 
   206 
   210     def _get_entity_type(self, word):
   207     def _get_entity_type(self, word):
   211         """check if the given word is matching an entity type, return it if
   208         """check if the given word is matching an entity type, return it if
   212         it's the case or raise BadRQLQuery if not
   209         it's the case or raise BadRQLQuery if not
   288         else:
   285         else:
   289             searchop = ''
   286             searchop = ''
   290         rql = '%s %s WHERE %s' % (etype, etype[0],
   287         rql = '%s %s WHERE %s' % (etype, etype[0],
   291                                   self._complete_rql(word3, etype, searchattr=rtype))
   288                                   self._complete_rql(word3, etype, searchattr=rtype))
   292         return rql, {'text': word3}
   289         return rql, {'text': word3}
   293 
       
   294     def _multiple_words_query(self, words):
       
   295         """specific process for more than 3 words query"""
       
   296         return ' '.join(words),
       
   297 
       
   298 
   290 
   299     def _expand_shortcut(self, etype, rtype, searchstr):
   291     def _expand_shortcut(self, etype, rtype, searchstr):
   300         """Expands shortcut queries on a non final relation to use has_text or
   292         """Expands shortcut queries on a non final relation to use has_text or
   301         the main attribute (according to possible entity type) if '%' is used in the
   293         the main attribute (according to possible entity type) if '%' is used in the
   302         search word
   294         search word