Enhancing Code Search Intent with Programming Context Exploration
Yanmin Dong, Zhenya Huang, Zheng Zhang, Guanhao Zhao, Likang Wu, Hongke Zhao, Binbin Jin, Qi Liu · 2025
An intelligent code search engine tries to find and suggest a code piece given a developer's query quickly from a large-scale program database, which can significantly promote software development efficiency. Existing solutions can search the relevant codes to some extent. However, most of them fail to precisely understand the search intent of developers since they only mine their natural language queries, while ignoring the valuable programming context (e.g., the code written by the developer). In this paper, we study the novel problem of context-aware code search. To promote a step forward, we first provide the CodeSearchNet-C dataset with constructing sufficient programming context from the GitHub website for each query-code instance. The dataset is supplemented on the CodeSearchNet benchmark, ensuring both generality and comparability for relevant research. Then, by analyzing the characteristics of programming context, we propose a novel two-stage Context-aware Code Retrieval (ConCR) framework. In the first stage, we propose a Context Walking algorithm, which simulates the programming habits of different developers. The generated programming context could ensure the diversity of search intent among developers. In the second stage, imitating the reading habits of developers, we introduce a novel Context Hierarchical Encoder, to understand the search intent with contextual information from local to global. Our ConCR framework is general, and we give three implementations on the basis of typical code search models as backbones. Extensive experimental results clearly prove that our ConCR significantly enhances the code search performance, effectively fulfilling developers' needs for efficient code resource searching on the web. These results also verify the necessity of introducing programming context to understand developers' intent.