File retrieval method and apparatus
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-26
- Publication Date
- 2026-08-11
AI Technical Summary
[0002]文件存储在实际使用中,由于目录层结构的限制以及文件的数量的限制,很难提供一种合理有效的检索手段,现有的业内针对此场景,往往会采用ES(Elasticsearch)数据库进行辅助检索
[0014]本发明还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如上述任一种文件检索方法。
Smart Images

Figure CN118312483B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a document retrieval method and apparatus. Background Technology
[0002] In practical use, due to limitations in directory structure and the number of files, it is difficult to provide a reasonable and effective retrieval method. In this scenario, the industry often uses the Elasticsearch database for auxiliary retrieval.
[0003] Existing methods for assisted retrieval based on the Elasticsearch (ES) database consume a large amount of memory due to the advanced retrieval capabilities of ES. However, in most scenarios, the file size is not large enough, resulting in high memory consumption and low retrieval efficiency for file retrieval. Summary of the Invention
[0004] This invention provides a document retrieval method and apparatus to improve document retrieval efficiency.
[0005] This invention provides a document retrieval method, comprising: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Based on the path array in the matching nodes, the path information of the object to be retrieved is determined.
[0006] According to a document retrieval method provided by the present invention, the process of constructing an index tree includes: Traverse the file system to obtain all file system objects contained in the file system; Based on the directory hierarchy, all file system objects are split to obtain multiple data units of the file system; Obtain the target data unit from the plurality of data units, and construct each node in the initial index tree based on the character arrangement order in the target data unit. The target data unit can be any data unit from the plurality of data units. Obtain the remaining data units from the plurality of data units, and add them to the initial index tree based on the character arrangement order in the remaining data units, so that no duplicate strings are contained in the nodes at each level of the index tree. The remaining data units are the data units other than the target data unit from the plurality of data units. Add the remaining data units from the plurality of data units one by one to the initial index tree until all the plurality of data units are added to the initial index tree to obtain the index tree, and add a path array to each node of the index tree.
[0007] According to a document retrieval method provided by the present invention, the method adds data to the initial index tree based on the character arrangement order in the remaining data units, including: If a target node exists in the initial index tree that has the same first character as the remaining data unit, then add nodes corresponding to each character of the remaining data unit after the target node in the initial index tree. If there is no node in the initial index tree that has the same first character as the remaining data units, a new node corresponding to each character of the remaining data units is added to the initial index tree.
[0008] According to a file retrieval method provided by the present invention, based on directory hierarchy, all file system objects are split, further comprising: If the file system object is a file system object that includes a suffix, the suffix is truncated to obtain a suffix data unit and a file name data unit.
[0009] According to a document retrieval method provided by the present invention, the path index information is determined based on the spatial index pointer of the data unit.
[0010] According to a document retrieval method provided by the present invention, searching in an index tree and determining a matching node in the index tree that matches the plurality of characters includes: Based on the method of performing full-word matching on each node of the index tree for the multiple characters, the matching node in the index tree that matches the multiple characters is determined.
[0011] The document retrieval method provided by the present invention further includes: Receive file system object change messages from the index tree; Based on the file system object change message, determine the changed system object in the index tree, and determine the change node that matches multiple characters of the changed system object from the index tree; The changed node is updated based on the file system object change message.
[0012] The present invention also provides a document retrieval device, comprising: The matching module is used to obtain the name string of the object to be retrieved, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be retrieved is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. The retrieval module is used to determine the path information of the object to be retrieved based on the path array in the matching nodes.
[0013] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the file retrieval methods described above.
[0014] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements any of the file retrieval methods described above.
[0015] The file retrieval method and apparatus provided by this invention constructs multiple nodes of an index tree using characters from all data units in the file system, and inserts a path array determined by the path index information of the corresponding data unit into each node of the index tree, thus realizing the construction process of the index tree. Because character nodes are reusable, file retrieval based on the index tree achieves a retrieval process in file storage scenarios while consuming less space, thereby improving file retrieval efficiency while maintaining low space usage. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in this invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly described below. Obviously, the accompanying drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating the document retrieval method provided by the present invention; Figure 2 This is a schematic diagram of a single directory index tree structure provided by the present invention; Figure 3 This is a schematic diagram of the index tree structure containing files provided by the present invention; Figure 4This is a schematic diagram of multiple directory index tree structures provided by the present invention; Figure 5 This is a schematic diagram of suffix truncation provided by the present invention; Figure 6 This is a schematic diagram of time truncation provided by the present invention; Figure 7 This is a schematic diagram of the document retrieval device provided by the present invention; Figure 8 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0019] This invention proposes a document retrieval method. Figure 1 This is a flowchart illustrating the document retrieval method provided by the present invention. (Refer to...) Figure 1 The document retrieval method provided by this invention may include: Step 110: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Step 120: Determine the path information of the object to be retrieved based on the path array in the matching nodes.
[0020] The file retrieval method provided by this invention can be executed by an electronic device, a component within an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), or personal computer (PC), etc. This invention does not impose specific limitations.
[0021] The technical solution of this invention will be described in detail below using the example of a computer executing the file retrieval method provided by this invention.
[0022] In step 110, the name string of the object to be retrieved is obtained, and based on multiple characters in the name string, the index tree is searched to determine the matching node in the index tree that matches the multiple characters. The object to be retrieved is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node.
[0023] The object to be searched can be any file or directory whose path information needs to be determined. It's understood that any object to be searched is a name based on a string. After obtaining the name string of the object to be searched, a search is performed in a pre-built index tree based on multiple characters in the name string.
[0024] The index tree is pre-built and contains path information for each file system object in the file system. A file system object is an entity in a computer's file system; it can be a file, folder (directory), or link, etc. In the operating system, a file system object is the basic unit used to organize and store data, and it typically has some attributes and operations.
[0025] Optionally, assuming there are two file system objects / root / test / test.jpg and / test / test.jpg, the process of building an index tree for these two file system objects is as follows: Step 111, file system object splitting.
[0026] Before a file system object is written into the tree, it is split. The most basic split is splitting according to the directory hierarchy. The first file mentioned above will be split into three parts: root, test, and test.jpg. Each part is called a data unit. The first two data units are directories, and the last one is the actual file.
[0027] Step 112: Create the tree nodes for the root directory.
[0028] Since the index tree is empty at this point, it is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is built based on the characters of data units in the file system. According to the index tree construction rules, when the data unit root is indexed, four nodes are created: r, o, o, and t. The data unit ultimately terminates at node t. When reading actual content, each node should start from the root node. For example, the actual text content represented by node t is / (root node) + r + o + o + t, ultimately forming / root representing the basic text content of the current node.
[0029] After each node is created, an internal path array is created to populate the data unit content.
[0030] Each individual path within the path array is still an array. The first element of this array is a fixed character, recording type information. For example, root is a directory, so the first character is 'd'. Starting from the second element, it records the space pointers of all data unit nodes traversed by the current directory. The second element is the space pointer of the root node 0, and the next element is the space pointer of the current node 4. Therefore, the contents of the array paths corresponding to the / root directory are [d, 0, 4]. The constructed index tree is as follows: Figure 2 The schematic diagram of a single directory index tree structure provided by this invention is shown.
[0031] Step 113: Create the tree nodes for the test directory and the test.jpg file.
[0032] When the test data unit is inserted into the database, 4 nodes are also created. Since there is a preceding directory, the array of the endpoint, i.e., node 8, is [d, 0, 4, 8], where d represents that the data unit is a directory, 0 and 4 represent the preceding directory node of the data unit, and 8 represents the current node.
[0033] When the file test.jpg is inserted into the database, tracing the root node, it is found that the first four characters "test" already exist, so no corresponding node is created. Starting from ".jpg", four new nodes are created, until the final node, number 12. The array is [f, 0, 4, 8, 12], where f represents the current data unit as a file, and the following are the nodes of the preceding directory and the current node. The resulting index tree is as follows. Figure 3 The schematic diagram of the index tree structure containing files provided by this invention is shown.
[0034] Step 114: Create the tree nodes for the file / test / test.jpg.
[0035] The file ` / test / test.jpg` still needs to be split into ` / test` and ` / test.jpg` before being inserted into the database. When the ` / test` directory is added to the tree, since the relevant nodes already exist, an array `[d,0,8]` is added at the endpoint. The path array is internally sorted according to its length, and files of the same length are sorted by their insertion time. Inserting ` / test.jpg` is similar to ` / test`, with `[f,0,8,12]` added to the path array of node 12 to identify the current file. The resulting index tree is as follows: Figure 4 The schematic diagram of multiple directory index tree structures provided by this invention is shown.
[0036] The logical structure of the index tree is as follows: Except for the root node, each node contains one character; No duplicate character content is allowed in the child nodes of each node; In addition to the basic characters, each node also stores a path array; A single path within a path array is also an array, recording the path information of a single data unit.
[0037] The first element of the path array is a fixed character used to identify the type of the current data unit: d: directory, f: file, dc: directory fragment, fc: file fragment. From the second element onwards, the path array consists of pointers to other nodes, representing the full path containing the data unit.
[0038] After constructing the index tree, based on multiple characters in the name string, a search is performed within the index tree to determine the matching nodes that match these multiple characters. Specifically, this can be done using either full-word matching or wildcard matching, matching multiple characters in the name string against the corresponding characters in each node of the index tree to determine the matching nodes that match these multiple characters.
[0039] In step 120, the path information of the object to be retrieved is determined based on the path array in the matching nodes.
[0040] After the matching node is determined, since the path array of the matching node contains the path index information of the corresponding data unit, the index can be obtained from the path index information in the path array and searched in the index tree to determine the path information of the object to be retrieved.
[0041] Understandably, based on the characteristics of index trees, they have significant advantages in insertion and space compression, making them more suitable for business scenarios with frequent insertions, such as log files, archived information, cold backup data, etc.
[0042] The file retrieval method provided in this invention constructs an index tree with multiple nodes based on the characters of all data units in the file system. A path array, determined by the path index information of the corresponding data unit, is inserted into each node of the index tree, thus realizing the index tree construction process. Because character nodes are reusable, file retrieval based on the index tree achieves a retrieval process in file storage scenarios while consuming relatively little space, thereby improving file retrieval efficiency while maintaining low space usage.
[0043] In one embodiment, the index tree construction process includes: traversing the file system to obtain all file system objects contained in the file system; splitting all file system objects based on directory hierarchy to obtain multiple data units of the file system; obtaining a target data unit among the multiple data units, and constructing each node in the initial index tree based on the character arrangement order of the target data unit, wherein the target data unit is any data unit among the multiple data units; obtaining the remaining data units among the multiple data units, and adding them to the initial index tree based on the character arrangement order of the remaining data units, such that no duplicate strings are contained in the nodes of each level of the index tree, wherein the remaining data units are data units other than the target data unit among the multiple data units; adding the remaining data units among the multiple data units to the initial index tree one by one until all the multiple data units are added to the initial index tree to obtain the index tree, and adding a path array to each node of the index tree.
[0044] The process of building an index tree can specifically include: Splitting file system objects: Traverse the file system to retrieve all file system objects contained within it. Splitting is done according to directory hierarchy. For example, the file system object / root / test / test.jpg will be split into three parts: root, test, and test.jpg. Each part is called a data unit; the first two data units are directories, and the last one is the actual file.
[0045] The index tree construction process is implemented by adding elements one by one. For example, for two file system objects / root / test / test.jpg and / test / test.jpg, a target data unit / root / test / test.jpg is first constructed to generate the initial index tree, and then the remaining data units / test / test.jpg are added to the initial index tree.
[0046] The process of building the index tree from these two file system objects is as follows: Before construction, the index tree is empty. It is built upon multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of data units in the file system. According to the index tree construction rules, the data unit root creates four nodes during indexing: r, o, o, and t. The data unit ultimately terminates at node t. When reading actual content, each node should start from the root node. For example, node t actually represents the text content of / (root node) + r + o + o + t, ultimately forming / root representing the basic text content of the current node.
[0047] After each node is created, an internal path array is created to populate the data unit content.
[0048] Each path within the path array is still an array. The first element of this array is a fixed character that records type information. For example, root is a directory, so the first character is d. Starting from the second element, the array records the space pointers of all data unit nodes traversed by the current directory. The second element is the space pointer of the root node 0, and the next element is the space pointer of the current node 4. Therefore, the array content corresponding to the / root directory is [d, 0, 4].
[0049] When the test data unit is inserted into the database, 4 nodes are also created. Since there is a preceding directory, the array of the endpoint, i.e., node 8, is [d, 0, 4, 8], where d represents that the data unit is a directory, 0 and 4 represent the preceding directory node of the data unit, and 8 represents the current node.
[0050] When the file test.jpg is added to the database, the system traces along the root node and finds that the first four characters "test" already exist. Therefore, no new node is created for the first four characters. Starting from ".jpg", four new nodes are created. When the system reaches node 12, the array is [f,0,4,8,12], where f represents the current data unit as a file, and the following nodes are the nodes of the preceding directory and the current node.
[0051] Before being inserted into the database, the file / test / test.jpg still needs to be split into two parts: / test and / test.jpg. When the / test directory is inserted into the tree, since the relevant nodes already exist, an array [d,0,8] will be added at the endpoint. The path array will be sorted according to its length, and those of the same length will be sorted according to their insertion time. The insertion of / test.jpg is similar to that of / test, with [f,0,8,12] added to the path array of node 12 to identify the current file.
[0052] The logical structure of the constructed index tree is as follows: Except for the root node, each node contains one character; No duplicate character content is allowed in the child nodes of each node; In addition to the basic characters, each node also stores a path array; A single path within a path array is also an array, recording the path information of a single data unit.
[0053] The first element of the path array is a fixed character used to identify the type of the current data unit: d: directory, f: file, dc: directory fragment, fc: file fragment. From the second element onwards, the path array consists of pointers to other nodes, representing the full path containing the data unit.
[0054] The file retrieval method provided in this invention realizes the index tree construction process by adding data units one by one, which lays the foundation for subsequent efficient file retrieval.
[0055] In one embodiment, adding to the initial index tree based on the character arrangement order in the remaining data units includes: if there is a target node in the initial index tree that has the same first character as the remaining data unit, adding a node corresponding to each character of the remaining data unit after the target node in the initial index tree; if there is no node in the initial index tree that has the same first character as the remaining data unit, adding a node corresponding to each character of the remaining data unit in the initial index tree.
[0056] The process of adding other data units may include: If a target node exists in the initial index tree that has the same first character as the other data units, add nodes corresponding to each character of the other data units after the target node in the initial index tree; if no node exists in the initial index tree that has the same first character as the other data units, add nodes corresponding to each character of the other data units in the initial index tree, so that the logical structure of the constructed index tree is such that, except for the root node, each node contains one character, and the child nodes of each node do not have duplicate character content.
[0057] In one embodiment, splitting all file system objects based on directory hierarchy further includes: if the file system object is a file system object containing a suffix, truncating the suffix to obtain suffix data units and file name data units.
[0058] The core idea of truncation is to perform a secondary split on directories or filenames. Essentially, it's a string processing rule that aims to further split characters already divided by the directory structure, improving utilization while reducing the tree hierarchy. The following example uses a file extension truncation tool to illustrate the actual processing logic of the truncation tool.
[0059] The file extension truncation tool only applies to file types, splitting a file into a filename + file extension format. Using the example above, the truncation tool will split test.jpg into two parts: test and .jpg. Their related tree structure will then become as follows: Figure 5 The index tree in the suffix truncation diagram provided by this invention.
[0060] Compared to a standard file entry tree, a truncation character will have an additional truncation node. This node is a special node that does not contain any string content (but is different from the space character). The corresponding path array will have truncation identifiers dc (directory truncation) and fc (file truncation), and will also mark the current truncation node and its corresponding next node, thereby establishing a connection relationship.
[0061] For example, for Figure 5 Both the files / root / test / test.jpg and / test / test.jpg trigger the truncation logic, resulting in a truncation node (node 13) at node 8, and marking node 12 as a subordinate truncation node. The .jpg file is directly connected to the root node, with node 12 serving as the termination point for normal path filling.
[0062] If node 12 is not the endpoint at this point, it should mimic node 13, creating a truncated node after node 12, then connecting to the next level truncated node, and updating the connection information of the parent truncated node. For example, if node 12 truncates node m and connects to a new node n, then the truncated node content of node m should be [fc,0,8,13,m,n]. At the same time, the path of the 13th stage node should be updated to be consistent with m. This logic continues until the endpoint appears.
[0063] When a node has a truncated node, all data units corresponding to the truncated node's path are considered its subtrees. Therefore, during retrieval, in addition to normal child node retrieval, nodes within the truncated tree are also included in the standard retrieval process.
[0064] Searching for test During the process, besides the directories / root / test / and / test in node 8, there is also a truncated node 13. Therefore, it is necessary to traverse the path of the truncated node, which is responsible for character concatenation during the reading process. Taking the reading of [fc,0,8,13,12] as an example, 0- / , 8- / test, 13 / test, 12- / .jpg, since node 13 has a truncator identifier, node 12 needs to remove the directory concatenation character and directly concatenate with the content of node 13 to obtain / test / test.jpg.
[0065] Optionally, truncation can also be performed based on a time string. Timestamps and time strings are also commonly used information for directory or filenames. Taking the file / test / test_202312201808.jpg as an example, we will further illustrate the processing logic of the truncation tool.
[0066] When the truncation checks test_202312201808.jpg, it simultaneously triggers file extension searches and time string searches. The filename is split into four parts: test_, 20231220, 1808, and .jpg. Based on the aforementioned index tree, the result after this file is entered into the tree is as follows: Figure 6 The index tree is shown in the time truncation diagram provided by this invention.
[0067] After the above is entered into the tree, three truncation nodes will be created in sequence. It should be noted that the actual paths of the three truncation nodes and the terminal node are the same, so that the entire directory name or file name can be quickly accessed within any truncation node.
[0068] In one embodiment, the path index information is determined based on the spatial index pointer of the data unit.
[0069] For example, for a directory whose data unit is root, when constructing the path array, the first character reflects the data unit type, which can be d (directory type). Starting from the second element, the spatial index pointers of all data unit nodes traversed by the current directory are recorded. The second element is the spatial index pointer of the root node 0, and the next element is the spatial index pointer of the current node 4. Therefore, the path index information corresponding to the / root directory is [d,0,4].
[0070] Understandably, using pointer references results in less space consumption during the subsequent path information determination process, thus saving space.
[0071] In one embodiment, retrieving and determining matching nodes in the index tree that match the plurality of characters includes: retrieving and determining matching nodes in the index tree that match the plurality of characters based on a method of performing full-word matching on each node of the index tree.
[0072] Due to the characteristics of the index tree, full-word matching has extremely high efficiency. Figure 4 Taking the index tree in the example, if you want to search for the keyword "test", you can start from the root node and directly find node 8. At this time, the paths in node 8 is the final search result. By addressing [[d,0,8],[d,0,4,8]], you can obtain the directory information of / test and / root / test.
[0073] Optionally, the matching process can also be implemented based on wildcard matching.
[0074] Wildcard matching is less efficient than full-character matching. The wildcard matching process involves: locating the starting node, traversing child nodes, and returning the matching results. test For example.
[0075] Locate the starting node: Using level-order traversal, the node information of each level of the tree is traversed in turn, and it is determined whether it matches the starting character node, and all node information that matches the starting character is found.
[0076] exist Figure 4 In the index tree, nodes 4, 5, and 8 can be retrieved at this point.
[0077] Traverse child nodes: Loop through all starting nodes and iterate through their child nodes to match subsequent characters. Record all key nodes that match the ending node.
[0078] Nodes 4 and 8 were unable to obtain the required child node information.
[0079] After looping through node 5, we can obtain child node 8, which meets the requirements.
[0080] Because of the presence of a suffix wildcard, node 8 and all its child nodes satisfy the search results. Therefore, it is necessary to return all path index information of node 8 and its child node 12 as the final search result. (If nodes 9-11 also have path index information in reality, then they also satisfy the search results).
[0081] Return matching results: The actual content retrieved using wildcards can be very large. In practice, it is advisable to consider batch processing and returning the results in conjunction with upper-layer applications.
[0082] In one embodiment, the method further includes: receiving a file system object change message from the index tree; determining a changed system object in the index tree based on the file system object change message, and determining a change node from the index tree that matches multiple characters of the changed system object; and updating the change node based on the file system object change message.
[0083] After the index tree is built, there may be changes to the file system objects in the index tree. These changes include adding, modifying, and deleting objects to ensure the integrity and consistency of the index tree.
[0084] Based on the received file system object change message, the changed system object is determined, and the change node that matches multiple characters of the changed system object is identified from the index tree. Based on the file system object change message, the update process of the change node is implemented.
[0085] Understandably, it's necessary to ensure the balance and consistency of the index tree during the insertion process. If the insertion of a new object causes the index tree to become unbalanced, appropriate balancing operations may need to be performed.
[0086] If modifications involve changes to the path or name of an object, the corresponding node in the index tree may need to be updated. Additionally, it's necessary to ensure that the metadata of the index tree remains consistent with the current state of the file system objects.
[0087] After deleting a node, ensure the balance and consistency of the index tree. If the deletion operation causes the index tree to become unbalanced, perform the necessary balancing operations.
[0088] It is understandable that during the process of indexing a directory or file into the index tree, the insertion process is the index tree addressing process. This process is not affected by the size of the tree, and theoretically the insertion efficiency is a fixed value of O(n).
[0089] When performing a search, this algorithm has the highest search efficiency if it is a full field matching search. After searching from the root node to the prefix character, the path array of its endpoint is the final search result, and its efficiency is a fixed value of O(n).
[0090] If it is a prefix character matching, the algorithm still has high retrieval efficiency. After retrieving the prefix character starting from the root node, the path array information of its terminal node and all child nodes are the required search content.
[0091] If it is a fully fuzzy character matching algorithm, the efficiency of this algorithm is affected by the size of the entire tree. It is necessary to pre-build secondary hash indexes for nodes at each level of the tree, thereby improving the retrieval efficiency to a certain extent.
[0092] If it's a single file deletion, it's essentially a full field match, and then the path index information of the corresponding file is deleted.
[0093] If a directory is being deleted, then all its subdirectories and subfiles should also be removed from the index tree. In this case, the index tree first needs to delete the path index information of that directory, then loop through the path arrays of all nodes in the tree to check if they contain a prefix of the path index information of the corresponding directory. If so, these prefixes also need to be deleted. Furthermore, no new directories with the same path are allowed to be inserted before the deletion is complete.
[0094] If a search is performed during directory deletion, because the directory node has been removed, even if subdirectories or files have not yet been removed, the parent node will no longer exist when the corresponding directory is accessed, and the relevant information cannot be retrieved normally. In other words, deleting a directory does not affect normal file retrieval.
[0095] Modification means deleting first and then adding. If it's a modification to a single file, you only need to delete the corresponding path index information and then add it again.
[0096] If the modification involves a directory, after deleting the original path index information and adding new path index information, the path array of all nodes in the tree is looped through to check if it contains the corresponding directory path index information prefix. If so, it needs to be modified to the new path index information. Furthermore, no new directories with the same path are allowed to be inserted before the modification is completed.
[0097] Similar to deletion, during modification, the corresponding information cannot be retrieved normally. Unlike deletion, the subdirectories and files still exist in the file system at this time, but they cannot be retrieved. In other words, modifying a directory will affect the normal retrieval of its corresponding subdirectories and files.
[0098] Figure 7 This is a schematic diagram of the structure of the document retrieval device provided by the present invention, as shown below. Figure 7 As shown, the device includes: The matching module 710 is used to obtain the name string of the object to be retrieved, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be retrieved is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. The retrieval module 720 is used to determine the path information of the object to be retrieved based on the path array in the matching nodes.
[0099] The file retrieval device provided by this invention constructs multiple nodes of an index tree using characters from all data units in the file system, and inserts a path array determined by the path index information of the corresponding data unit into each node of the index tree, thus realizing the construction process of the index tree. Because character nodes are reusable, file retrieval based on the index tree achieves a retrieval process in file storage scenarios while consuming less space, thereby improving file retrieval efficiency while maintaining low space usage.
[0100] In one embodiment, the matching module 710 is specifically used for: The process of building an index tree includes: Traverse the file system to obtain all file system objects contained in the file system; Based on the directory hierarchy, all file system objects are split to obtain multiple data units of the file system; Obtain the target data unit from the plurality of data units, and construct each node in the initial index tree based on the character arrangement order in the target data unit. The target data unit can be any data unit from the plurality of data units. Obtain the remaining data units from the plurality of data units, and add them to the initial index tree based on the character arrangement order in the remaining data units, so that no duplicate strings are contained in the nodes at each level of the index tree. The remaining data units are the data units other than the target data unit from the plurality of data units. Add the remaining data units from the plurality of data units one by one to the initial index tree until all the plurality of data units are added to the initial index tree to obtain the index tree, and add a path array to each node of the index tree.
[0101] In one embodiment, the matching module 710 is further configured to: Based on the character arrangement order in the remaining data units, they are added to the initial index tree, including: If a target node exists in the initial index tree that has the same first character as the remaining data unit, then add nodes corresponding to each character of the remaining data unit after the target node in the initial index tree. If there is no node in the initial index tree that has the same first character as the remaining data units, a new node corresponding to each character of the remaining data units is added to the initial index tree.
[0102] In one embodiment, the matching module 710 is further configured to: Based on the directory hierarchy, all file system objects are further split, including: If the file system object is a file system object that includes a suffix, the suffix is truncated to obtain a suffix data unit and a file name data unit.
[0103] In one embodiment, the matching module 710 is further configured to: The path index information is determined based on the spatial index pointers of the data units. In one embodiment, the matching module 710 is further configured to: Searching the index tree to determine the matching nodes in the index tree that match the plurality of characters includes: Based on the method of performing full-word matching on each node of the index tree for the multiple characters, the matching node in the index tree that matches the multiple characters is determined.
[0104] In one embodiment, the retrieval module 720 is specifically used for: Receive file system object change messages from the index tree; Based on the file system object change message, determine the changed system object in the index tree, and determine the change node that matches multiple characters of the changed system object from the index tree; The changed node is updated based on the file system object change message.
[0105] Figure 8 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 can call logical instructions in the memory 830 to execute a file retrieval method, which includes: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Based on the path array in the matching nodes, the path information of the object to be retrieved is determined.
[0106] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0107] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, wherein when the program instructions are executed by a computer, the computer is able to execute the file retrieval method provided by the above methods, the method comprising: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Based on the path array in the matching nodes, the path information of the object to be retrieved is determined.
[0108] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the file retrieval methods provided by the methods described above, the method comprising: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Based on the path array in the matching nodes, the path information of the object to be retrieved is determined.
[0109] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0110] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A document retrieval method, characterized in that, The method includes: Obtain the name string of the object to be searched, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be searched is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. Based on the path array in the matching nodes, the path information of the object to be retrieved is determined; the nodes in the index tree are reusable. The process of constructing the index tree includes: Traverse the file system to obtain all file system objects contained in the file system; Based on the directory hierarchy, all file system objects are split to obtain multiple data units of the file system; Obtain the target data unit from the plurality of data units, and construct each node in the initial index tree based on the character arrangement order in the target data unit. The target data unit can be any data unit from the plurality of data units. Obtain the remaining data units from the plurality of data units, and add them to the initial index tree based on the character arrangement order in the remaining data units, so that no duplicate strings are contained in the nodes at each level of the index tree. The remaining data units are the data units other than the target data unit from the plurality of data units. Add the remaining data units from the plurality of data units one by one to the initial index tree until all the plurality of data units are added to the initial index tree to obtain the index tree, and add a path array to each node of the index tree.
2. The document retrieval method according to claim 1, characterized in that, The step of adding data to the initial index tree based on the character arrangement order in the remaining data units includes: If a target node exists in the initial index tree that has the same first character as the remaining data unit, then add nodes corresponding to each character of the remaining data unit after the target node in the initial index tree. If there is no node in the initial index tree that has the same first character as the remaining data units, a new node corresponding to each character of the remaining data units is added to the initial index tree.
3. The document retrieval method according to claim 1, characterized in that, The step of splitting all file system objects based on directory hierarchy further includes: If the file system object is a file system object that includes a suffix, the suffix is truncated to obtain a suffix data unit and a file name data unit.
4. The document retrieval method according to any one of claims 1-3, characterized in that, The path index information is determined based on the spatial index pointer of the data unit.
5. The document retrieval method according to claim 1, characterized in that, The step of searching in the index tree and determining the matching node in the index tree that matches the plurality of characters includes: Based on the method of performing full-word matching on each node of the index tree for the multiple characters, the matching node in the index tree that matches the multiple characters is determined.
6. The document retrieval method according to claim 1, characterized in that, Also includes: Receive file system object change messages from the index tree; Based on the file system object change message, determine the changed system object in the index tree, and determine the change node that matches multiple characters of the changed system object from the index tree; The changed node is updated based on the file system object change message.
7. A document retrieval device, characterized in that, include: The matching module is used to obtain the name string of the object to be retrieved, and search in the index tree based on multiple characters in the name string to determine the matching node in the index tree that matches the multiple characters. The object to be retrieved is a file system object. The index tree is constructed based on multiple nodes and their corresponding path arrays. Each node in the index tree is constructed based on the characters of all data units in the file system. The path array is determined based on the path index information of the data unit corresponding to the node. The retrieval module is used to determine the path information of the object to be retrieved based on the path array in the matching nodes; The nodes in the index tree are reusable; The process of constructing the index tree includes: Traverse the file system to obtain all file system objects contained in the file system; Based on the directory hierarchy, all file system objects are split to obtain multiple data units of the file system; Obtain the target data unit from the plurality of data units, and construct each node in the initial index tree based on the character arrangement order in the target data unit. The target data unit can be any data unit from the plurality of data units. Obtain the remaining data units from the plurality of data units, and add them to the initial index tree based on the character arrangement order in the remaining data units, so that no duplicate strings are contained in the nodes at each level of the index tree. The remaining data units are the data units other than the target data unit from the plurality of data units. Add the remaining data units from the plurality of data units one by one to the initial index tree until all the plurality of data units are added to the initial index tree to obtain the index tree, and add a path array to each node of the index tree.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the file retrieval method as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the file retrieval method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
A method for efficiently supporting interactive, fuzzy search on structured data
CN102084363A
Character string data retrieval method and device, computer equipment and storage medium
CN111339382A