~ben-hutchings/ensoft-sextant/autocomplete-fix

« back to all changes in this revision

Viewing changes to src/sextant/db_api.py

  • Committer: Ben Hutchings
  • Date: 2014-11-11 12:11:19 UTC
  • Revision ID: benh@ensoft.co.uk-20141111121119-yaswak5va04nrgz2
autocomplete now wildcard matches function names in the database - only displaying lists if there are 75 or fewer results.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# prior to copy over to the remote server.
35
35
TMP_DIR = '/tmp/sextant'
36
36
 
 
37
SEARCH_NAMES_LIMIT = 50
 
38
 
37
39
# A function is deemed 'common' if it has more than this
38
40
# many connections.
39
41
COMMON_CUTOFF = 10
832
834
        result = self._db.query(q, returns=neo4jrestclient.Node)
833
835
        return bool(result)
834
836
 
835
 
    def get_function_names(self, program_name):
 
837
    def get_function_names(self, program_name, search, max_funcs):
836
838
        """
837
839
        Execute query to retrieve a list of all functions in the program.
838
840
        Any of the output names can be used verbatim in any SextantConnection
845
847
        if not validate_query(program_name):
846
848
            return set()
847
849
 
848
 
        q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
849
 
             ' RETURN f.name').format(program_name)
 
850
        if not search:
 
851
            q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
 
852
                 ' RETURN f.name LIMIT {}').format(program_name, max_funcs)
 
853
        else:
 
854
            q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
 
855
                 ' WHERE f.name =~ ".*{}.*" RETURN f.name LIMIT {}'
 
856
                 .format(program_name, search, max_funcs))
850
857
        return {func[0] for func in self._db.query(q)}
851
858
 
852
859
    def get_all_functions_called(self, program_name, function_calling):