Preferential ranking of code search results
AssigneeGoogle Inc.
InventorsPiaw Na, Phil Sung
Life of this patent
Estimating the term…
Abstract
TAG files are generated on a client and communicated to a server. The TAGS files are indexed and loaded into memory on the server. Search requests are run against the index and files that contain tags that satisfy the search request are ranked. The ranking is based on an include-tree of the file that contains the tag, the relative directory distance of the file containing the tag from the current context, or by using the numbers of levels of inclusion needed to reach a tag that satisfies the query. In some implementations, an extensible protocol is used to communicate the search queries and files that contain tags that satisfy the search query.
Claims21
A computer-implemented method, comprising:
- building and storing an index of source code files in one or more memory devices, the index incorporating one or more tags and, for each tag, a name of a respective source code file in which the tag is defined, a path to the respective source code file relative to a root directory, and a representation of an include-tree of the respective source code file, where the include-tree is a sequence of files that are included by or imported by the respective source code file;
- receiving from a client device a search query and a current context, wherein the current context is a file being edited, the current context is in a directory in a path relative to the root directory, and the current context has an associated include-tree;
- searching the index and identifying a plurality of source code files that define tags that satisfy the search query, the plurality of source code files including a plurality of source code files that are in the include-tree of the current context and at least one file that is not in the include-tree of the current context;
- ranking each of the plurality of source code files by applying multiple levels of sorting, including a first level of sorting where all source code files that are in the include-tree of the current context are ranked higher than all source code files that are not in the include-tree of the current context, and a second level of sorting where all source code files in the include-tree of the current context are ranked by the relative directory distance from the current context to each source code file;
- and
- communicating the ranking of the plurality of source code files to the client device as a response to the search query.
A computer-implemented system, comprising:
- an indexing engine that creates an index of source code files, the index incorporating one or more tags and, for each tag, a name of a respective source code file in which the tag is defined, a path to the respective source code file relative to a root directory, and a representation of an include-tree of the respective source code file, where the include-tree is a sequence of files that are included by or imported by the respective source code file;
- an interface to receive a search query and a current context, where the current context is a file being edited, the current context is in a directory in a path relative to the root directory, and the current context has an associated include-tree;
- and
- a ranking engine that ranks a plurality of source code files that each define a tag that satisfies the search query, where the plurality of source code files includes a plurality of source code files that are in the include-tree of the current context and at least one file that is not in the include-tree of the current context, where the ranking includes applying multiple levels of sorting, including a first level of sorting where all source code files that are in the include-tree of the current context are ranked higher than all source code files that are not in the include-tree of the current context, and a second level of sorting where all source code files in the include-tree of the current context are ranked by the relative directory distance from the current context to each source code file.
A computer program product, encoded on a machine-readable storage device or a machine-readable storage substrate, configured to cause a data processing apparatus to perform operations comprising:
- building an index of source code files, the index incorporating one or more tags and, for each tag, a name of a respective source code file in which the tag is defined, a path to the respective source code file relative to a root directory, and a representation of an include-tree of the respective source code file, where the include-tree is a sequence of files that are included by or imported by the respective source code file;
- receiving a search query and a current context, where the current context is a file being edited, the current context is in a directory in a path relative to the root directory, and the current context has an associated include-tree;
- searching the index and identifying a plurality of source code files that define tags that satisfy the search query, the plurality of source code files including a plurality of source code files that are in the include-tree of the current context and at least one file that is not in the include-tree of the current context;
- ranking each of the plurality of source code files that define tags that satisfy the search query by applying a multiple levels of sorting, including a first level of sorting where all source code files that are in the include-tree of the current context are ranked higher than all source code files that are not in the include-tree of the current context, and a second level of sorting where all source code files in the include-tree of the current context are ranked by the relative directory distance from the current context to each source code file;
- and
- communicating an indicator of the plurality of source code files that define tags that satisfy the search query as a response to the search query.
A system comprising:
- a computer having software stored on a memory of the computer, the software causing the computer to perform operations comprising:
- processing a set of one or more source code files, where each source code file is stored in a directory under a root directory;
- identifying one or more source code files from the set of one or more source code files, each identified source code file defining one or more tags;
- creating an s-expression TAGS file containing, for each identified source code file, a name of the identified source code file, a path of the identified source code file relative to the root directory of the identified source code file, a programming language of the identified source code file, a location of a tag definition within the identified source code file, and an item descriptor of the tag defined within the identified source code file;
- communicating to a server a search query and a current context, formatted according to an s-expression protocol, where the current context is a file being edited and the current context is in a directory corresponding to a path relative to the root directory;
- and
- receiving from a server, in response to the search query, information about one or more source code files that contain tags that satisfy the search query, the information formatted as an s-expression list, the s-expression list including one or more tags that satisfy the search query and including, for each tag, a snippet of a line within a source code file that includes a definition of the tag, a path to the source code file, a line number of the tag definition, and an offset into the source code file corresponding to the tag definition.
A computer program product, encoded on a machine-readable storage device or a machine-readable storage substrate, configured to cause a data processing apparatus to perform operations comprising:
- processing a set of one or more source code files, where each source code file is stored in a directory under a root directory;
- identifying one or more source code files from the set of one or more source code files, each identified source code file defining one or more tags;
- creating an s-expression TAGS file containing, for each identified source code file, a name of the identified source code file, a path of the identified source code file relative to the root directory of the identified source code file, a programming language of the identified source code file, a location of a tag definition within the identified source code file, and an item descriptor of the tag defined within the identified source code file;
- communicating a search query and a current context, formatted according to an s-expression protocol, where the current context is a file being edited and the current context is in a directory corresponding to a path relative to the root directory;
- and
- receiving, in response to the search query, information about one or more source code files that contain tags that satisfy the search query, the information formatted as an s-expression list, the s-expression list including one or more tags that satisfy the search query and including, for each tag, a snippet of a line within a source code file that includes a definition of the tag, a path to the source code file, a line number of the tag definition, and an offset into the source code file corresponding to the tag definition.
Dependencies are inferred from the claim text.