Example #1
0
    def run(self):
        from zim.search import SearchSelection, Query

        notebook, p = self.build_notebook()
        n, query = self.get_arguments()

        if query and not query.isspace():
            logger.info('Searching for: %s', query)
            query = Query(query)
        else:
            raise ValueError('Empty query')

        selection = SearchSelection(notebook)
        selection.search(query)
        for path in sorted(selection, key=lambda p: p.name):
            print path.name
Example #2
0
 def _get_search_results(self, terms):
     try:
         notebook_terms, normal_terms = self._process_terms(terms)
         notebooks = list(self._get_search_notebooks(notebook_terms))
         results = []
         query_str = u" ".join(normal_terms)
         if not query_str.isspace():
             query = Query(query_str)
             for notebook in notebooks:
                 logger.debug('Searching %r for %r', notebook, query)
                 selection = SearchSelection(notebook)
                 selection.search(query)
                 for path in selection:
                     rid = self._to_result_id(notebook.name, path.name)
                     results.append(rid)
         self._process_results(results, notebook_terms, normal_terms)
         return results
     except:
         logger.exception("_get_search_results() failed")