Bayesian networks can deal with uncertainty and polymorphism and are widely used in the field of fault diagnosis. However, the directed acyclic graph (DAG) space is large, and it is an NP-hard problem to get the optimal BN structure from the data. The current research combines constraint-based and search-based methods to search for the optimal BN structure in the DAG to solve this problem. However, when the constraint space is constant and imprecise, the optimal solution is most likely to be lost, resulting in low model accuracy. In addition, the search space expands with the increase of the number of nodes, which leads to the structure quickly falling into local optimum and low learning efficiency. Therefore, this paper proposes a Bayesian Network Modeling for Ranking Search under Constrained Conditions (BNMRSCC) method to find a BN structure that fits the data set in the constrained search space. Firstly, in the constraint phase, the MIC algorithm and CI test are used as double constraints to limit the search space and two estimatorsB anda are introduced in the original MIC algorithm to change the search space during the operation to reduce the computation time and improve the learning efficiency. Secondly, in the search phase, the XGboost algorithm is used to calculate the feature importance scores and rank them, and the search space is further determined based on the ranking under the double constraint. Finally, the feature ranking is used as the input of the K2 algorithm to improve the accuracy of network inference. The experimental results show that the model built by this algorithm is better and more effective for learning BN structures.