Text content searching method and device, processor and storage medium
By performing segmented processing and parallel search of large text files, combined with index tree and thread pool technology, the problem of low search efficiency of large text files in the existing technology is solved, and the search efficiency is significantly improved.
Patent Information
- Application Number
- CN202411153775.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-13
AI Technical Summary
Existing text content search methods are less efficient when searching for specific content on large text files, especially when multiple large text files need to be searched.
By segmenting the target text file and using multithreading to search segmented text in parallel, an index tree is created to optimize the search process and make full use of thread pools to improve search efficiency.
It significantly improves the text content search efficiency of large text files, especially when searching for multiple large text files, reducing processing time.
Smart Images

Figure CN119128081A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a text content search method, a text content search device, a processor, and a storage medium. Background Art
[0002] In the related art, the method of searching for specific content in a text file is mainly that after a user opens the text file to be searched, the system performs the following steps: obtaining the specific content that the user wants to search for input in the search box, then reading the text data line by line, determining whether each line contains the specific content, and finally feeding back the search results to the user after the search is completed. After the system feeds back the search results corresponding to the text file, the user closes the text file.
[0003] The line-by-line search method uses less memory because it does not need to load the entire text file into memory. However, when searching for specific content in large text files, this method may result in low search efficiency, especially when multiple large text files need to be searched. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a text content search method, a text content search device, a processor and a storage medium to solve the problem of low search efficiency when using existing text content search methods to search for specific content in large text files.
[0005] In order to achieve the above-mentioned object, the first aspect of the present application provides a text content search method, which is applied to a terminal device, and the method includes: Get the content to be searched; Segment all text data in the target text file to obtain multiple segmented texts corresponding to the target text file; Based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file.
[0006] In the embodiment of the present application, before segmenting all text data in the target text file, the method further includes: Get the target file path; Traverse all text files under the target file path and determine the file type corresponding to each text file; A text file whose corresponding file type meets a preset text condition is determined as a target text file.
[0007] In the embodiment of the present application, before performing parallel searches on multiple segmented texts corresponding to the target text file based on the content to be searched, the method further includes: For each segmented text corresponding to the target text file, create an index node corresponding to the segmented text; According to each index node, build the index tree corresponding to the target text file.
[0008] In the embodiment of the present application, before performing parallel searches on multiple segmented texts corresponding to the target text file based on the content to be searched, the method further includes: Obtain the number of currently used threads of the terminal device; The number of available threads of the terminal device is determined according to a preset maximum number of threads of the terminal device and a currently used number of threads.
[0009] In the embodiment of the present application, based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file, including: According to the index tree corresponding to the target text file, determine the order of searching the segmented text corresponding to each index node for the content to be searched; Creating a thread pool according to the number of available threads of the terminal device; wherein the thread pool includes a plurality of threads, and the threads in the thread pool are used to perform the task of searching the segmented text for the content to be searched; According to the index nodes corresponding to the segmented texts of the target text file, all threads in the thread pool perform parallel searches on the segmented texts corresponding to the target text file to obtain search results corresponding to the segmented texts; According to the search results corresponding to the multiple segmented texts corresponding to the target text file, the search results corresponding to the target text file are obtained.
[0010] In an embodiment of the present application, the method further includes: When there is a segmented text corresponding to the search result among the multiple segmented texts corresponding to the target text file, the step of performing parallel search on the segmented texts corresponding to the target text file through all threads in the thread pool according to the index nodes corresponding to each segmented text corresponding to the target text file is terminated.
[0011] In the embodiment of the present application, based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel, and after the search results corresponding to the target text file are obtained, the method further includes: Determine the total number of target text files; If the total number of target text files is one, generate and display prompt information according to the search result corresponding to the target text file; If the total number of target text files is at least two, the corresponding search results are filtered out as existing target text files, and a target file list is generated and displayed.
[0012] A second aspect of the present application provides a text content search device, which is configured in a terminal device, and the device includes: A module for obtaining content to be searched, used for obtaining content to be searched; A text segmentation module is used to segment all text data in the target text file to obtain multiple segmented texts corresponding to the target text file; The to-be-searched content search module is used to perform parallel searches on multiple segmented texts corresponding to a target text file based on the to-be-searched content to obtain search results corresponding to the target text file.
[0013] A third aspect of the present application provides a processor configured to execute the above-mentioned text content search method.
[0014] A fourth aspect of the present application provides a machine-readable storage medium, on which instructions are stored. When the instructions are executed by a processor, the processor is configured to execute the above-mentioned text content search method.
[0015] The text content search method, device, processor and storage medium provided by the present application, after obtaining the text content (i.e., the content to be searched) that the user wants to search, when searching for the content to be searched for a single target text file, the target text file is first segmented to obtain multiple segmented texts, and then the segmented text corresponding to the target text file is searched for the content to be searched using multi-threading, and finally the search results corresponding to the target text file are obtained. When it is necessary to search for the content to be searched for multiple target text files, the aforementioned steps can be repeated for each target text file. Compared with the use of existing text content search methods to search for specific content in large text files, this embodiment obtains the search results corresponding to the target text file by segmenting the target text file and performing parallel searches on the multiple segmented texts corresponding to the target text file, which significantly improves the efficiency of text content search for large text files, especially when it is necessary to search for text content for multiple large text files.
[0016] It should be noted that, in the present application, searching text files for text content refers to searching whether the text files contain the text content that the user wants to search for.
[0017] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings: Figure 1 The flowchart of the text content search method according to the embodiment of the present application is schematically shown; Figure 2 A structural block diagram of a text content search device according to an embodiment of the present application is schematically shown; Figure 3 The internal structure diagram of the computer device according to the embodiment of the present application is schematically shown.
[0019] Description of Reference Numerals A01-processor; A02-network interface; A03-internal memory; A04-display screen; A05-input device; A06-non-volatile storage medium; B01-operating system; B02-computer program. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0021] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back, etc.), such directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0022] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0023] With the development of technology, the search function has covered various information forms such as text, images, audio and video. Among them, searching for a specific content (specified by the user) in a text file can be applied to multiple scenarios. For example, corporate personnel can search for specific keywords in a large number of corporate files for further processing and archiving; researchers can search for specific experimental results or data points in multiple experimental data files to analyze and verify research hypotheses; and individual users can search for files containing specific content on computers or other terminal devices to organize and manage personal data.
[0024] In view of the problem of low search efficiency in the related art of using existing text content search methods to search large text files for specific content, the present application provides a text content search method, device, processor and storage medium. The text content search method, device, processor and storage medium provided by the present application are described in detail below in conjunction with the accompanying drawings through specific examples and implementation methods.
[0025] Figure 1 The flowchart of the text content search method of the embodiment of the present application is schematically shown. Figure 1 As shown, in one embodiment of the present application, a text content search method is provided, and the method is applied to a terminal device, the terminal device includes a processor, a storage component, an input device (such as a keyboard for inputting text and commands), an output device (such as a display for displaying graphics, text and video) and other basic components, and each component works together to enable the terminal device to perform various functions. The text content search method provided in the embodiment of the present application may include the following steps.
[0026] Step 200, obtaining the content to be searched.
[0027] It can be understood that the content to be searched represents the text content that the user wants to search, and the text content may exist in a text file.
[0028] In one example, the user may use the input device to input the content to be searched in the search box of the current display interface of the output device, so that the terminal device can obtain the content to be searched.
[0029] Step 400, segmenting all text data in the target text file to obtain a plurality of segmented texts corresponding to the target text file.
[0030] In a specific implementation, step 400 may include: Step 410, segmenting all text data in the target text file according to a preset segmentation rule to obtain a plurality of segmented texts corresponding to the target text file.
[0031] In one example, the preset segmentation rule is selected as line break, that is, for the text data in the target text file, each time a line break (\n) is encountered, the text data will be segmented into a new paragraph, that is, a new segmented text is formed.
[0032] Step 600 , based on the content to be searched, a plurality of segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file.
[0033] In this embodiment, in order to obtain the search result corresponding to the target text file, before step 600, the method may further include: Step 510: For each segmented text corresponding to the target text file, create an index node corresponding to the segmented text.
[0034] In this embodiment, the purpose of creating index nodes corresponding to each segmented text is to establish an index tree, thereby improving the efficiency of text content search.
[0035] Step 520: construct an index tree corresponding to the target text file according to each index node.
[0036] Specifically, the index tree organizes the text data of the target text file into a hierarchical structure, so that the position of the content to be searched in the target text file can be quickly located. This structure greatly reduces the search time, especially when processing large-scale text data.
[0037] In this embodiment, an index tree corresponding to the target text file is constructed according to each index node, so as to optimize the subsequent search process for specific content (ie, search for content to be searched), thereby improving the overall search efficiency.
[0038] Step 530: Obtain the number of currently used threads of the terminal device.
[0039] Specifically, for the terminal device (such as a computer, a mobile device), the current number of used threads can be obtained according to its operating system and the programming language used. The method for obtaining the current number of used threads of the terminal device is a prior art and will not be described in detail here.
[0040] Step 540: Determine the number of available threads of the terminal device according to the preset maximum number of threads of the terminal device and the current number of used threads.
[0041] The number of available threads of the terminal device may be a difference between a preset maximum number of threads of the terminal device and a currently used number of threads, or may be smaller than the difference.
[0042] In this embodiment, the number of available threads of the terminal device is selected as the difference between the preset maximum number of threads of the terminal device and the current number of used threads thereof, so as to effectively utilize system resources and improve the efficiency of text content search.
[0043] In a specific implementation, step 600 may include: Step 610: Determine the order of searching the content to be searched for the segmented texts corresponding to the respective index nodes according to the index tree corresponding to the target text file.
[0044] Specifically, the index tree is a self-balancing tree structure, in which the text data corresponding to each index node is stored in the index tree in a specific order.
[0045] In this embodiment, searching for text content in the order of the index tree can significantly improve the efficiency of the search.
[0046] Step 620: Create a thread pool according to the number of available threads of the terminal device.
[0047] The thread pool includes a plurality of threads, and each thread in the thread pool is used to execute the task of searching the segmented text for the content to be searched.
[0048] Step 630 , based on the index nodes corresponding to the respective segmented texts corresponding to the target text file, all threads in the thread pool perform parallel searches on the segmented texts corresponding to the target text file to obtain search results corresponding to the respective segmented texts.
[0049] The search result corresponding to the segmented text is existence or non-existence.
[0050] In this embodiment, when the segmented text corresponding to the target text file is searched in parallel by all threads in the thread pool, that is, in the parallel operation of multiple threads, there is no need to wait for all threads to complete the current task (i.e., search for the content to be searched) before starting the next round of tasks, so as to make full use of the parallel processing capabilities of multiple threads, improve the processing efficiency of tasks, reduce the overall processing time, and thus improve the efficiency of text content search.
[0051] In one example, step 630 may use the indexOf() function of QString to search the segmented text for the content to be searched, that is, to determine whether the content to be searched exists in the segmented text (specifically, to find the position where the content to be searched first appears in the segmented text). Specifically, for any segmented text, when the indexOf() function does not find the content to be searched in the segmented text, the indexOf() function may return "-1" to indicate that the content to be searched does not exist in the segmented text, and the search result corresponding to the segmented text does not exist at this time; when the indexOf() function finds the content to be searched in the segmented text, the indexOf() function will return the specific position of the content to be searched in the segmented text, and the search result corresponding to the segmented text does exist at this time.
[0052] In this example, the method of searching for content to be searched in segmented text using the indexOf() function of QString is encapsulated into a class, and the class is made to inherit the QRunnable class. In this way, the Qt thread pool can be used for parallel search, thereby improving the efficiency of text content search.
[0053] Of course, it is understandable that, for a target text file, when it contains content to be searched, the indexOf() function can also be used to return the specific location of the content to be searched in the target text file.
[0054] Step 640, obtaining the search result corresponding to the target text file according to the search results corresponding to the multiple segmented texts corresponding to the target text file.
[0055] The search result corresponding to the target text file is whether it exists or not.
[0056] Specifically, for each target text file, when there is a segmented text whose corresponding search result is existing among the multiple segmented texts corresponding to the target text file, the search result corresponding to the target text file is existing; when the search results corresponding to the segmented texts corresponding to the target text file are all non-existent, the search result corresponding to the target text file is non-existent.
[0057] Optionally, in step 630, the method further includes: When there is a segmented text corresponding to the search result among the multiple segmented texts corresponding to the target text file, the step of performing parallel search on the segmented texts corresponding to the target text file through all threads in the thread pool according to the index nodes corresponding to each segmented text corresponding to the target text file is terminated.
[0058] It can be understood that in the process of searching the text content of a target text file, when it is determined that the search result corresponding to a corresponding segmented text exists, it means that there is content to be searched in the target text file. At this time, further searching of the target text file can be stopped immediately to improve search efficiency and reduce unnecessary processing time, especially when it is necessary to search the text content of multiple target text files.
[0059] Optionally, when the user wants to search the text content of all text files in a folder, before step 400, the method may further include: Step 310, obtaining the target file path.
[0060] In this embodiment, similar to the method of obtaining the content to be searched, the user can use the input device to input the target file path in another search box of the current display interface of the output device, so that the terminal device can obtain the target file path. Of course, it can be understood that this embodiment can also provide a path selection method for the user to provide the target file path, as long as it is guaranteed that the terminal device can obtain the target file path.
[0061] Step 320, traverse all text files under the target file path, and determine the file type corresponding to each text file.
[0062] The types of text files include various forms, each of which has its own specific extension and purpose, and the common extensions are ".txt", ".doc", ".pdf", and ".html". This embodiment determines the file type of each text file under the target file path to determine which text files need to be searched for text content later.
[0063] Step 330: determine a text file whose corresponding file type meets a preset text condition as a target text file.
[0064] In one example, the preset text condition is: the file type is ".doc" or ".docx". That is, for each text file under the target file path, if the text type of the text file is ".doc" or ".docx", the text file is the target text file.
[0065] In this embodiment, after all target text files are determined, for each target text file, based on the target text file, steps 400 to 600 are executed to obtain the search results of the target text file.
[0066] This embodiment determines all target text files by traversing all text files under the target file path, and sequentially executes step 400 to step 600 for each target text file, thereby achieving rapid search of multiple text files and significantly improving text content search efficiency.
[0067] Optionally, after step 600, the method may further include: Step 810, determining the total number of target text files.
[0068] It is understandable that the user can choose to search the text content of a single target text file, or can choose to search the text content of all target text files that meet the preset text conditions under a certain file path, so the total number of target text files may be one or more.
[0069] Step 820: If the total number of target text files is one, generate and display prompt information according to the search result corresponding to the target text file.
[0070] In this embodiment, the prompt information may be provided by a pop-up prompt box or the like to prompt the user of the search results of the text content search for the single target text file.
[0071] Step 830: If the total number of target text files is at least two, filter out the corresponding search results as existing target text files, generate and display a target file list.
[0072] In this embodiment, for the target file list, the search results of the text content search for the text files under the target file path can be displayed to the user in a table or other manner.
[0073] The text content search method provided in this embodiment, after obtaining the text content (i.e., the content to be searched) that the user wants to search, when searching for the content to be searched for a single target text file, first segment the target text file to obtain multiple segmented texts, then create index nodes corresponding to each segmented text to generate an index tree, and create a thread pool, and then based on the index nodes corresponding to each segmented text, perform the task of searching the content to be searched for the segmented text through each thread in the thread pool, that is, traverse multiple segmented texts in parallel, search for the content to be searched, and obtain the search results corresponding to each segmented text, thereby obtaining the search results corresponding to the target text file. When it is necessary to search for the content to be searched for multiple target text files, for each target text file, repeat the above steps. It is not difficult to see that compared with the use of existing text content search methods to search for specific content in large text files, this embodiment significantly improves the efficiency of text content search for large text files by segmenting the target text file and performing parallel searches on multiple segmented texts corresponding to the target text file to obtain the search results corresponding to the target text file.
[0074] Figure 1 FIG. 1 is a flow chart of a text content search method in one embodiment. It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0075] Figure 2 The structural block diagram of the text content search device of the embodiment of the present application is schematically shown. Figure 2 As shown, in one embodiment of the present application, a text content search device is provided, which is configured in a terminal device, and the device includes: The module for obtaining content to be searched is used to obtain content to be searched.
[0076] The text segmentation module is used to segment all text data in the target text file to obtain multiple segmented texts corresponding to the target text file.
[0077] The to-be-searched content search module is used to perform parallel searches on multiple segmented texts corresponding to a target text file based on the to-be-searched content to obtain search results corresponding to the target text file.
[0078] In this embodiment, the device further includes: The path acquisition module is used to obtain the target file path.
[0079] The text type determination module is used to traverse all text files under the target file path and determine the file type corresponding to each text file.
[0080] The text file determination module is used to determine a text file whose corresponding file type meets a preset text condition as a target text file.
[0081] In this embodiment, the device further includes: The node creation module is used to create an index node corresponding to each segmented text corresponding to the target text file.
[0082] The index tree building module is used to build the index tree corresponding to the target text file according to each index node.
[0083] In this embodiment, the device further includes: The first thread number determination module is used to obtain the current number of used threads of the terminal device.
[0084] The second thread number determination module is used to determine the number of available threads of the terminal device according to the preset maximum number of threads of the terminal device and the current number of used threads.
[0085] In this embodiment, the content search module includes: The search order determination unit is used to determine the order of searching the content to be searched for the segmented texts corresponding to each index node according to the index tree corresponding to the target text file.
[0086] The thread pool creation unit is used to create a thread pool according to the number of available threads of the terminal device; wherein the thread pool includes multiple threads, and each thread in the thread pool is used to execute the task of searching the segmented text for the content to be searched.
[0087] The text search result determination unit is used to perform parallel search on the segmented texts corresponding to the target text file through all threads in the thread pool according to the index nodes corresponding to each segmented text corresponding to the target text file, so as to obtain the search results corresponding to each segmented text.
[0088] The file search result determination unit is used to obtain the search result corresponding to the target text file according to the search results corresponding to the multiple segmented texts corresponding to the target text file.
[0089] In this embodiment, the text search result determination unit is further used to: when there is a segmented text whose corresponding search result exists in the multiple segmented texts corresponding to the target text file, end the execution of the text search result determination unit.
[0090] In this embodiment, the device further includes: The file quantity determination module is used to determine the total quantity of target text files.
[0091] The first search result display module is used to generate and display prompt information according to the search result corresponding to the target text file if the total number of the target text files is one.
[0092] The second search result display module is used to filter out target text files whose corresponding search results exist if the total number of target text files is at least two, and generate and display a target file list.
[0093] In this embodiment, the device includes a processor and a memory. The to-be-searched content acquisition module, the text segmentation module and the to-be-searched content search module are all stored in the memory as program units, and the processor executes the above program modules stored in the memory to implement corresponding functions.
[0094] The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and the above text content search method is implemented by adjusting kernel parameters.
[0095] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0096] An embodiment of the present application provides a processor configured to execute the above-mentioned text content search method.
[0097] An embodiment of the present application provides a machine-readable storage medium, on which instructions are stored. When the instructions are executed by a processor, the processor is configured to execute the above-mentioned text content search method.
[0098] Figure 3 The internal structure diagram of the computer device of the embodiment of the present application is schematically shown. Figure 3As shown, in one embodiment of the present application, a computer device is provided, which may be a terminal. The computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05 and a memory (not shown in the figure) connected via a system bus. Among them, the processor A01 of the computer device is used to provide computing and control capabilities. The memory of the computer device includes an internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 in the non-volatile storage medium A06. The network interface A02 of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor A01, a text content search method is implemented. The display screen A04 of the computer device may be a liquid crystal display or an electronic ink display, and the input device A05 of the computer device may be a touch layer covered on the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0099] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0100] In one embodiment, the text content search device provided by the present application can be implemented in the form of a computer program. The computer program can be Figure 3 The computer device is run on the computer device shown. The memory of the computer device can store various program modules that constitute the text content search device, such as: Figure 2 The to-be-searched content acquisition module, text segmentation module and to-be-searched content search module shown in the figure. The computer program composed of each program module enables the processor to execute the steps of the text content search method of each embodiment of the present application described in this specification.
[0101] Figure 3 The computer device shown can be Figure 2 In the text content search device shown, the to-be-searched content acquisition module executes step 200 , the text segmentation module executes step 400 , and the to-be-searched content search module executes step 600 .
[0102] The present application provides a device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: Get the content to be searched.
[0103] All text data in the target text file are segmented to obtain multiple segmented texts corresponding to the target text file.
[0104] Based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file.
[0105] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0106] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0107] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0108] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0109] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0110] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0111] Computer readable media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0112] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0113] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A text content search method, characterized in that: Applied to a terminal device, the method comprises: Get the content to be searched; Segment all text data in the target text file to obtain multiple segmented texts corresponding to the target text file; Based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file.
2. The method according to claim 1, characterized in that Before segmenting all text data in the target text file, the method further includes: Get the target file path; Traverse all text files under the target file path and determine the file type corresponding to each text file; A text file whose corresponding file type meets a preset text condition is determined as a target text file.
3. The method according to claim 1, characterized in that Before performing parallel searches on multiple segmented texts corresponding to the target text file based on the content to be searched, the method further includes: For each segmented text corresponding to the target text file, create an index node corresponding to the segmented text; According to each index node, build the index tree corresponding to the target text file.
4. The method according to claim 3, characterized in that Before performing parallel searches on multiple segmented texts corresponding to the target text file based on the content to be searched, the method further includes: Obtain the number of currently used threads of the terminal device; The number of available threads of the terminal device is determined according to a preset maximum number of threads of the terminal device and a currently used number of threads.
5. The method according to claim 4, characterized in that Based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel to obtain search results corresponding to the target text file, including: According to the index tree corresponding to the target text file, determine the order of searching the segmented text corresponding to each index node for the content to be searched; Creating a thread pool according to the number of available threads of the terminal device; wherein the thread pool includes a plurality of threads, and the threads in the thread pool are used to perform the task of searching the segmented text for the content to be searched; According to the index nodes corresponding to the segmented texts of the target text file, all threads in the thread pool perform parallel searches on the segmented texts corresponding to the target text file to obtain search results corresponding to the segmented texts; According to the search results corresponding to the multiple segmented texts corresponding to the target text file, the search results corresponding to the target text file are obtained.
6. The method according to claim 5, characterized in that The method further comprises: When there is a segmented text corresponding to the search result among the multiple segmented texts corresponding to the target text file, the step of performing parallel search on the segmented texts corresponding to the target text file through all threads in the thread pool according to the index nodes corresponding to each segmented text corresponding to the target text file is terminated.
7. The method according to claim 5, characterized in that Based on the content to be searched, multiple segmented texts corresponding to the target text file are searched in parallel, and after the search results corresponding to the target text file are obtained, the method further includes: Determine the total number of target text files; If the total number of target text files is one, generate and display prompt information according to the search result corresponding to the target text file; If the total number of target text files is at least two, the corresponding search results are filtered out as existing target text files, and a target file list is generated and displayed.
8. A text content search device, characterized in that: Configured in a terminal device, the device includes: A module for obtaining content to be searched, used for obtaining content to be searched; A text segmentation module is used to segment all text data in the target text file to obtain multiple segmented texts corresponding to the target text file; The to-be-searched content search module is used to perform parallel searches on multiple segmented texts corresponding to a target text file based on the to-be-searched content to obtain search results corresponding to the target text file.
9. A processor, characterized in that: The method is configured to execute the text content search method according to any one of claims 1 to 7.
10. A machine-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor is configured to execute the text content search method according to any one of claims 1 to 7.
Citation Information
Patent Citations
File processing method and device
CN108038188A
Big data processing method and system
CN110795626A
Data storage method and device, data query method and device and computing equipment
CN111400427A
