WO2017113230A1 - String search method and device - Google Patents

String search method and device Download PDF

Info

Publication number
WO2017113230A1
WO2017113230A1 PCT/CN2015/099960 CN2015099960W WO2017113230A1 WO 2017113230 A1 WO2017113230 A1 WO 2017113230A1 CN 2015099960 W CN2015099960 W CN 2015099960W WO 2017113230 A1 WO2017113230 A1 WO 2017113230A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
retrieved
character string
string
file block
Prior art date
Application number
PCT/CN2015/099960
Other languages
French (fr)
Chinese (zh)
Inventor
裴廷斌
Original Assignee
深圳配天智能技术研究院有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳配天智能技术研究院有限公司 filed Critical 深圳配天智能技术研究院有限公司
Priority to CN201580079772.1A priority Critical patent/CN107615271A/en
Priority to PCT/CN2015/099960 priority patent/WO2017113230A1/en
Publication of WO2017113230A1 publication Critical patent/WO2017113230A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present invention relates to the field of file processing technologies, and in particular, to a string retrieval method and apparatus.
  • the technical problem to be solved by the present invention is to provide a string retrieval method and device, which can realize a full-text string retrieval function that is completely consistent with the user experience of the traditional method without occupying a large amount of memory.
  • a technical solution adopted by the present invention is to provide a string retrieval method for performing string retrieval in a file divided into a plurality of file blocks, the retrieval method comprising: receiving characters a string retrieval request, the retrieval request including the first character string to be retrieved; retrieving the first character string in the first file block loaded into the memory; if the first character string is not retrieved in the first file block, the other file is The block is loaded into memory separately and retrieves the first string until the first string is retrieved or the entire file is traversed.
  • the method further includes: if the first character string is retrieved, moving the cursor to the retrieved first character string and terminating the retrieval.
  • the string retrieval order is from front to back retrieval; retrieving the first character string in the first file block that has been loaded into the memory includes: recording the current cursor position; searching backward from the current cursor position until the first search is performed The string is either retrieved to the end of the first file block.
  • the other file blocks are sequentially loaded into the memory and the first string is retrieved until the first string is retrieved or the entire file is traversed:
  • the first string is not retrieved in a file block, and the other file blocks arranged after the first file block are separately loaded into the memory and the first string is retrieved until the first character string is retrieved; if ranked first If the first string is not retrieved by other file blocks after the file block, the first file block from the first file block of the file to the previous file block of the first file block is sequentially loaded into the memory and the first string is retrieved until the search Until the first character string; if the first file block of the file does not retrieve the first character string from the previous file block of the first file block, the search is performed from the first position of the first file block to the current cursor position. A string until the first string is retrieved.
  • the string retrieval order is retrieved from the back to the front; the first character string retrieved in the first file block that has been loaded into the memory includes: recording the current cursor position; searching forward from the current cursor position until the first search is performed A string or retrieved to the first position of the first file block.
  • the other file blocks are sequentially loaded into the memory and the first string is retrieved until the first string is retrieved or the entire file is traversed:
  • the first string is not retrieved in a file block, and the other file blocks arranged before the first file block are separately loaded into the memory and the first string is retrieved until the first character string is retrieved; if ranked first If the first file string is not retrieved by other file blocks before the file block, the file block from the last file block to the next file block of the first file block is sequentially loaded into the memory and the first string is retrieved until the first string is retrieved.
  • the first character is retrieved from the end position of the first file block to the current cursor position String until the first string is retrieved.
  • a technical solution adopted by the present invention is to provide a character string retrieving device for performing character string retrieval in a file divided into a plurality of file blocks, the retrieving device comprising: a receiving module, For receiving a string retrieval request, the retrieval request includes a first character string to be retrieved; the first retrieval module is coupled to the receiving module, and configured to retrieve the first character string in the first file block that has been loaded into the memory; a retrieval module, connected to the first retrieval module, configured to: if the first character string is not retrieved in the first file block, load the other file blocks into the memory separately and retrieve the first character string until the first string is retrieved Or traverse the entire file.
  • the retrieval device further includes a jump module, and the jump module is configured to: when the first character string is retrieved, move the cursor to the retrieved first character string and terminate the retrieval.
  • the string retrieval order is from front to back retrieval;
  • the first retrieval module is configured to: record the current cursor position; start backward retrieval from the current cursor position until the first character string is retrieved or retrieved to the end of the first file block position.
  • the second retrieval module is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string in sequence, until the retrieval Until the first string; if the first string is not retrieved by other file blocks after the first file block, then from the first file block of the file to the previous file block of the first file block, respectively Loading the memory and retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then from the first The first character string is searched from the first position of the file block to the current cursor position until the first character string is retrieved.
  • the string retrieval order is retrieved from the back to the front; the first retrieval module is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first file block. First position.
  • the second retrieval module is configured to: if the first character string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first character string in sequence, until the retrieval Until the first string; if the first string is not retrieved by other file blocks before the first file block, then the last file block from the file to the next file block of the first file block, respectively Into the memory and retrieve the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the next file block of the first file block, then from the first file block The last position to the current cursor position retrieves the first character string until the first character string is retrieved.
  • a technical solution adopted by the present invention is to provide a character string retrieval device for performing character string retrieval in a file divided into a plurality of file blocks, the retrieval device comprising: a transceiver, a memory, a processor, and a data bus, the transceiver, the memory, and the processor are connected by a data bus for communicating with each other; the transceiver is configured to receive a string retrieval request, the retrieval request includes a first character string to be retrieved; and the memory is configured to store the file The processor is configured to retrieve the first string in the first file block that has been loaded into the memory; if the first string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and retrieve the first character String until the first string is retrieved or the entire file is traversed.
  • the processor is further configured to: when the first string is retrieved, move the cursor to the retrieved first string and terminate the retrieval.
  • the string retrieval order is from front to back retrieval; the processor is configured to: record the current cursor position; and search backward from the current cursor position until the first character string is retrieved or retrieved to the end position of the first file block.
  • the processor is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string until the first string is retrieved. Until the string is up; if the first string is not retrieved by other file blocks after the first file block, the memory file is loaded separately from the first file block of the file to the previous file block of the first file block. And retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then from the first file block The first character string is retrieved from the first position to the current cursor position until the first character string is retrieved.
  • the string retrieval order is retrieved from the back to the front; the processor is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block.
  • the processor is configured to: if the first string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first string until the first string is retrieved. Until the string is up; if the first string is not retrieved by other file blocks before the first file block, the memory file is loaded separately from the last file block of the file to the next file block of the first file block. Retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the next file block of the first file block, then from the end of the first file block The first character string is retrieved to the current cursor position until the first character string is retrieved.
  • the beneficial effect of the present invention is: when the first character string is retrieved in the file, the first character string is first retrieved in the first file block loaded into the memory, if the first file block is not retrieved in the first file block a string that loads the other file blocks into memory separately and retrieves the first string until the first string is retrieved or the entire file is traversed, so that at the same time, except for the file block presented to the user in the text editor There is only one file block in the memory, which can realize the full-text string retrieval function that is completely consistent with the traditional method user experience without occupying a large amount of memory.
  • FIG. 1 is a schematic diagram of a method for loading a file into a memory in the prior art
  • FIG. 2 is a schematic flow chart of a character string retrieval method according to an embodiment of the present invention.
  • FIG. 3 is a schematic diagram of a method for loading a file into a memory according to an embodiment of the present invention
  • step S12 is a schematic flow chart of the method of step S12 when searching from front to back in FIG. 2;
  • FIG. 5 is a schematic diagram of a method for retrieving from front to back according to an embodiment of the present invention.
  • FIG. 6 is a schematic diagram of a specific process of the string retrieval method in FIG. 5;
  • Figure 7 is a flow chart showing the method of step S12 when searching from back to front in Figure 2;
  • FIG. 8 is a schematic diagram of a method for retrieving from the back to the front according to an embodiment of the present invention.
  • FIG. 9 is a schematic structural diagram of a character string retrieving apparatus according to a first embodiment of the present invention.
  • FIG. 10 is a schematic structural diagram of a character string retrieving apparatus according to a second embodiment of the present invention.
  • Figure 11 is a block diagram showing the structure of a character string retrieving apparatus according to a third embodiment of the present invention.
  • the string retrieval method includes:
  • Step S10 Receive a string retrieval request, where the retrieval request includes the first character string to be retrieved.
  • the retrieval method of the embodiment of the present invention is for performing character string retrieval in a file divided into a plurality of file blocks.
  • the file is divided as shown in Figure 3. Taking a text file as an example, the file is divided into n blocks of the same size, and n is a positive integer. Only one file block is loaded into memory at the same time, as in file block 2 in the figure.
  • Step S11 retrieve the first character string in the first file block that has been loaded into the memory.
  • the first file block is searched first, wherein the first file block is the current file block loaded into the memory, and the current file block is partially or completely loaded into the file editor. If the first character string is retrieved in the first file block, the cursor is jumped to the position of the matching character string, and the retrieval is terminated.
  • Step S12 If the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately and the first character string is retrieved until the first character string is retrieved or the entire file is traversed.
  • step S12 when searching for other file blocks, only one file block to be retrieved in other file blocks is loaded into the memory and the first character string is retrieved at the same time. After the file block is retrieved, if the first string is not retrieved, the retrieved file block is removed from the memory, and the next file block of the file block is sequentially loaded into the memory and the first character is continuously retrieved. String until the first string is retrieved or the entire file is traversed. If the first string is retrieved, the cursor is moved to the retrieved first string and the retrieval is terminated, and the file block in which the first string is located is loaded into the text editor for presentation to the user.
  • the string retrieval order may be retrieved from front to back or from back to front. The following two methods are described separately.
  • the string retrieval order may be to retrieve the current cursor position to the end of the first file block when searching from front to back, and then search the end of the first file block to the file portion at the end of the file, and then retrieve the file to the beginning The file portion of the first position of the first file block, and finally the first portion of the first file block is retrieved to the portion of the file at the current cursor position.
  • the first position is the position where the starting point of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the beginning of the first file block.
  • the last position is the position where the end of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the end of the first file block.
  • the string retrieval order may be from the front to the back retrieval, in step S11, the current cursor position is recorded; the current cursor position is searched backward until the first character string is retrieved or the last position of the first file block is retrieved. That is, the file block portion between the current cursor position and the end position of the first file block is retrieved.
  • searching the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the end of the first file block is retrieved. position. The closer the string is to the current cursor position, the more preferential it is retrieved. If the first string is retrieved, the cursor is jumped to the position of the first string and the first string is selected.
  • the subsequent retrieval is continued.
  • the current cursor position is the current position of the cursor in the first file block.
  • step S12 the method includes:
  • Step S120 If the first character string is not retrieved in the first file block, the other file blocks arranged after the first file block are sequentially loaded into the memory and the first character string is retrieved until the first character string is retrieved. .
  • the other file blocks ranked after the first file block represent the portion of the file between the end position of the first file block and the end of the file.
  • the file blocks of the portion are sequentially loaded into the memory in units of file blocks and the first character string is retrieved line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until retrieve the first string or traverse the portion of the file.
  • this retrieval process at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range.
  • Step S121 If the first character string is not retrieved from other file blocks that are arranged after the first file block, the first file block from the file to the previous file block of the first file block are sequentially loaded into the memory. The first string is retrieved until the first string is retrieved.
  • the first file block from the file to the previous file block of the first file block represents the file portion at the beginning of the file to the first position of the first file block.
  • the retrieval method in step S121 is similar to the method in step S120, starting from the beginning of the file to the first position of the first file block, in the file block unit, sequentially loading the partial file block into the memory and searching the first line by line. String. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file.
  • the portion of the file retrieved in step S120 and step S121 is not in memory before the retrieval, and is only loaded into the memory at the time of retrieval, and the memory is immediately removed after the retrieval is completed and the first character string is not retrieved. If the retrieval is terminated after the first string is retrieved during the retrieval process, the file block in which the first character string is located is loaded into the text editor and presented to the user, and the cursor is jumped to the position of the first character string and the first is selected. String.
  • Step S122 If the first file string of the file does not retrieve the first character string from the first file block of the first file block, the first character string is retrieved from the first position of the first file block to the current cursor position. Until the first string is retrieved.
  • step S122 the current cursor position is retrieved line by line as the end point for retrieving the first character string until the portion of the file from the first position of the first file block to the current cursor position is traversed.
  • the retrieval method of the embodiment of the present invention can achieve the same retrieval effect as the traditional method, so that the full-text string retrieval function consistent with the user experience of the traditional method can be realized without occupying a large amount of memory.
  • FIG. 5 is a schematic diagram of a method for retrieving from front to back according to an embodiment of the present invention.
  • the first file block in the file is already loaded into memory and partially or fully loaded into the file compiler.
  • the remaining file blocks in the file except the first file block are not loaded into memory.
  • the first position is the position where the starting point of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the beginning of the first file block.
  • the last position is the position of the end of the first file block in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the end of the first file block.
  • the arrow in the figure indicates the direction of the search, that is, the search from the current cursor position, including:
  • Step 1 retrieve the portion of the file between the current cursor position and the end position of the first file block.
  • Step 2 retrieve the portion of the file between the end of the first file block and the end of the file.
  • Step 3 retrieve the portion of the file between the beginning of the file and the first position of the first file block.
  • Step 4 retrieve the portion of the file between the first file block head position and the current cursor position.
  • the file-based retrieval method includes:
  • Step S100 Searching for a portion of the file behind the cursor in the first file block. That is, the portion of the file between the current cursor position and the last position of the first file block in the file is retrieved.
  • this retrieval process only the first file block presented to the user in the text editor at the same time ensures that the occupation of system resources in the retrieval process is controlled within a limited range.
  • Step S101 It is determined whether the first character string is retrieved. If the character string is not retrieved in the file portion behind the cursor in the first file block, step S102 is performed, and if the character string is retrieved in the file portion following the cursor in the first file block, step S108 is performed.
  • Step S102 Searching for a portion of the file between the end position of the first file block and the end of the file. That is, the file portion of the first file block between the end of the file and the end of the file is retrieved.
  • step S102 the file block to be retrieved is sequentially loaded into the memory and the first character string is sequentially searched in units of file blocks in the file block as the starting point of the first file block, and the file block is retrieved after the retrieval is completed.
  • the memory is removed and the next file block of the file block is loaded into memory to continue to retrieve the first string until the first string is retrieved, or the retrieval of the portion of the file between the end position and the end of the file is completed.
  • this retrieval process it can be ensured that at the same time, except for the first file block presented to the user in the text editor, and only one file block exists in the memory, thereby ensuring that the occupation of system resources during the retrieval process is controlled. Within a limited range.
  • Step S103 It is judged whether the first character string is retrieved. If the character string is not retrieved in the file portion between the last position and the end of the file, step S104 is performed, and if the character string is retrieved in the file portion between the last position and the end of the file, step S108 is performed.
  • Step S104 Searching for a portion of the file between the beginning and the first position of the file. That is, the portion of the file between the beginning of the file and the first position of the first file block in the file is retrieved.
  • step S104 starting from the beginning of the file, the first file block is the end point in the file, and in the file block unit, the file block to be retrieved is sequentially loaded into the memory and the first character string is retrieved.
  • the file block is removed from the memory and the next file block of the file block is loaded into the memory to continue to retrieve the first string until the first string is retrieved, or between the beginning and the beginning of the file. Retrieval of the file part. In this retrieval process, it can be ensured that at the same time, except for the first file block presented to the user in the text editor, and only one file block exists in the memory, thereby ensuring that the occupation of system resources during the retrieval process is controlled. Within a limited range.
  • Step S105 It is judged whether the first character string is retrieved. If the first character string is not retrieved in the file portion between the beginning of the file and the first position, step S106 is performed, and if the character string is retrieved in the file portion between the beginning and the beginning of the file, step S108 is performed.
  • Step S106 retrieve the first character string for the portion of the file preceding the current cursor position in the first file block. That is, the first file block is retrieved from the first position in the file to the file portion before the current cursor position, and the first file block is used as the starting point in the first position of the file, and the current cursor position is the end point to retrieve the first character string.
  • the first file block presented to the user in the text editor at the same time ensures that the occupation of system resources in the retrieval process is controlled within a limited range.
  • Step S107 It is judged whether the first character string is retrieved. If the first character string is not retrieved in the file portion preceding the current cursor position in the first file block, step S106 is performed, if the first character string is retrieved in the file portion of the current cursor position in the first file block, Step S108 is performed.
  • Step S108 The retrieval is successful, and the position where the first character string of the word is located is returned. That is, the first character string is retrieved, the cursor is jumped to the position of the first character string, and the first character string is selected. If the file block in which the retrieved first string is located is a file block other than the first file block, the file block is simultaneously loaded into the file editor and presented to the user.
  • Step S109 The retrieval fails. Indicates that there is no matching string in the entire file.
  • the string retrieval order may be, when searching from the back to the front, first retrieving the current cursor position to the file portion of the first position of the first file block, and then retrieving the first position of the first file block to the file portion at the beginning of the file, and then retrieving the end of the file. To the portion of the file at the end of the first file block, the last portion of the first file block is finally retrieved to the portion of the file at the current cursor position.
  • step S11 the current cursor position is recorded; the forward search is started from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block. That is, the file block portion between the current cursor position and the first file block position is retrieved, and when the search is performed, the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the first file block is retrieved. position. The closer the string is to the current cursor position, the more preferential it is retrieved. If the first string is retrieved, the cursor is jumped to the position of the first string and the first string is selected.
  • the current cursor position is the current position of the cursor in the first file block.
  • step S12 the method includes:
  • Step S123 If the first character string is not retrieved in the first file block, the other file blocks arranged before the first file block are separately loaded into the memory and the first character string is retrieved until the first character string is retrieved. .
  • step S123 the file blocks of the portion are sequentially loaded into the memory in units of file blocks and the first character string is retrieved line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until retrieve the first string or traverse the portion of the file.
  • this retrieval process at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range.
  • Step S124 If the first character string is not retrieved from other file blocks before the first file block, the last file block from the file to the next file block of the first file block are sequentially loaded into the memory and retrieved. The first string until the first string is retrieved.
  • the last file block of the file to the next file block of the first file block represents the file portion at the end of the file to the end of the first file block.
  • the retrieval method in step S124 is similar to the method in step S123, starting from the end of the file to the end of the first file block, in the file block unit, sequentially loading the partial file block into the memory and searching the first line by line. String. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file.
  • the file portion retrieved in step S123 and step S124 is not in memory before the retrieval, and is only loaded into the memory at the time of retrieval, and the memory is immediately removed after the retrieval is completed and the first character string is not retrieved. If the retrieval is terminated after the first string is retrieved during the retrieval process, the file block in which the first character string is located is loaded into the text editor and presented to the user, and the cursor is jumped to the position of the first character string and the first is selected. String.
  • Step S125 If the first file string is not retrieved from the last file block of the file to the next file block of the first file block, the first character string is retrieved from the end position of the first file block to the current cursor position until retrieve the first string.
  • step S125 the current cursor position is retrieved line by line as the end point of the first character string, until the file portion from the last position of the first file block to the current cursor position is traversed.
  • FIG. 8 is a schematic diagram of a method for retrieving from the back to the front according to an embodiment of the present invention. Compared with FIG. 5, the only difference is that the direction of the search indicated by the arrow is just the opposite, that is, the forward search from the current cursor position, specifically including:
  • Step 10 retrieve the portion of the file between the current cursor position and the first file block head position.
  • Step 20 retrieve the portion of the file between the first file block header and the beginning of the file.
  • Step 30 retrieve the portion of the file between the end of the file and the end of the first file block.
  • Step 40 retrieve the portion of the file between the end position of the first file block and the current cursor position.
  • a more specific process is similar to retrieving backwards from the current cursor position, except that the direction of the search is different.
  • the first file block starts from the first position in the file, the file starts as the end point, and the file block to be retrieved is sequentially loaded into the memory and the first character string is retrieved in units of file blocks.
  • the file block is removed from the memory and the next file block of the file block is loaded into the memory to continue to retrieve the first file block until the first string is retrieved, or between the beginning and the beginning of the file. Retrieval of the file part.
  • Fig. 9 is a block diagram showing the structure of a character string retrieving apparatus according to a first embodiment of the present invention.
  • the character string retrieval device 10 includes a receiving module 11, a first retrieval module 12, and a second retrieval module 13.
  • the retrieval device 10 performs a character string search for a file divided into a plurality of file blocks.
  • the receiving module 11 is configured to receive a string retrieval request, where the retrieval request includes a first character string to be retrieved.
  • the first retrieval module 12 is coupled to the receiving module 11 for retrieving the first character string in the first file block that has been loaded into the memory.
  • the second retrieval module 13 is connected to the first retrieval module 12, and if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and the first character string is retrieved until the first character string is retrieved. A string or traversing the entire file.
  • the retrieval device 10 further includes a jump module 14.
  • the jump module 14 is configured to move the cursor to the retrieved first character string and terminate the retrieval when the first character string is retrieved. If the second retrieval module 13 retrieves the first character string in other file blocks, the jump module 14 also presents the file block in which the first character string is located to the text editor for presentation to the user.
  • the string retrieval order can be retrieved from front to back or from back to front. The following two methods are described separately.
  • the first retrieval module 12 When the string retrieval order is from front to back retrieval, the first retrieval module 12 is configured to: record the current cursor position; start backward retrieval from the current cursor position until the first character string is retrieved or retrieved to the end of the first file block position. That is, the first search module 12 retrieves the file block portion between the current cursor position and the end position of the first file block.
  • searching the current cursor position is used as the starting point for searching the first character string, and the search is performed line by line until the first search is performed.
  • the end position of a file block The closer the character string is to the current cursor position, the more preferentially it is retrieved by the first retrieval module 12.
  • the current cursor position is the current position of the cursor in the first file block.
  • the second retrieval module 13 is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string, respectively, until Retrieving the first character string; if the first file string is not retrieved by other file blocks after the first file block, then from the first file block of the file to the previous file block of the first file block, in turn Loading the memory separately and retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then The first character string of the first block to the current cursor position is retrieved until the first character string is retrieved.
  • the second retrieval module 13 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the next file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
  • the first retrieval module 12 When the string retrieval order is retrieved from the back to the front, the first retrieval module 12 is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first file block. First position. That is, the first retrieval module 12 retrieves the current block position to the file block portion between the first file block head position. When searching, the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the first search is performed. The first position of a file block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the first retrieval module 12. The current cursor position is the current position of the cursor in the first file block.
  • the second retrieval module 13 is configured to: if the first character string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first character string, respectively, until Retrieving the first character string; if the first file string is not retrieved by other file blocks before the first file block, then from the last file block of the file to the next file block of the first file block, respectively Loading the memory and retrieving the first string until the first string is retrieved; if the first file from the last file block of the file to the next file block of the first file block does not retrieve the first string, then from the first file The first character string is retrieved from the end position of the block to the current cursor position until the first character string is retrieved.
  • the second retrieval module 13 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
  • the file does not indicate There is a matching string and the search failed.
  • Figure 11 is a block diagram showing the structure of a character string retrieving apparatus according to a first embodiment of the present invention.
  • the character string retrieval device 20 includes a transceiver 21, a memory 22, a processor 23, and a data bus 24.
  • the transceiver 21, the memory 22, and the processor 23 are connected via a data bus 24 to communicate with each other.
  • the transceiver 21 is configured to receive a string retrieval request, the retrieval request including a first character string to be retrieved.
  • the memory 22 is used to store files.
  • the processor 23 is configured to retrieve the first character string in the first file block that has been loaded into the memory; if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and retrieved first A string until the first string is retrieved or the entire file is traversed.
  • the processor 23 is further configured to: when the first character string is retrieved, move the cursor to the retrieved first character string and terminate the retrieval. If the processor 23 retrieves the first character string in other file blocks, the processor 23 also presents the file block in which the first character string is located to the text editor for presentation to the user.
  • the string retrieval order can be retrieved from front to back or from back to front. The following two methods are described separately.
  • the processor 23 When the string retrieval order is from front to back retrieval, the processor 23 is configured to: record the current cursor position; and search backward from the current cursor position until the first character string is retrieved or retrieved to the end position of the first file block. That is, the processor 23 retrieves the current block position to the file block portion between the end positions of the first file block. When searching, the current cursor position is used as the starting point for retrieving the first character string, and is retrieved line by line until the first file is retrieved. The end position of the block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the processor 23. The current cursor position is the current position of the cursor in the first file block.
  • the memory 22 also stores the current cursor position, the first position of the first file block, and the last position of the first file block.
  • the processor 23 retrieves from the current cursor position to the end position of the first file block and does not retrieve the first character string, and the processor is further configured to: if the first character string is not retrieved in the first file block, The other file blocks after the first file block are sequentially loaded into the memory and retrieved the first character string until the first character string is retrieved; if the first file string is not retrieved in the other file blocks after the first file block , from the first file block of the file to the previous file block of the first file block, sequentially loaded into the memory and retrieved the first string until the first string is retrieved; if the first file block of the file If the first character string is not retrieved until the previous file block of the first file block, the first character string is retrieved from the first position of the first file block to the current cursor position until the first character string is retrieved.
  • the processor 23 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the next file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
  • the processor 23 When the string retrieval order is retrieved from the back to the front, the processor 23 is configured to: record the current cursor position; search forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block . That is, the processor 23 retrieves the current block position to the file block portion between the first file block head position. When searching, the current cursor position is used as the starting point for retrieving the first character string, and is retrieved line by line until the first file is retrieved. The first position of the block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the processor 23. The current cursor position is the current position of the cursor in the first file block.
  • the processor 23 retrieves from the current cursor position to the first position of the first file block and does not retrieve the first character string, and the processor 23 is further configured to: if the first character string is not retrieved in the first file block, The other file blocks preceding the first file block are sequentially loaded into the memory and retrieved the first character string until the first character string is retrieved; if the first file character is not retrieved in the other file blocks before the first file block The string, from the last file block of the file to the next file block of the first file block, is sequentially loaded into the memory and retrieves the first string until the first string is retrieved; if the last file block of the file is If the first character string is not retrieved in the next file block of the first file block, the first character string is retrieved from the last position of the first file block to the current cursor position until the first character string is retrieved.
  • the processor 23 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks.
  • the use of system resources in the entire retrieval process is controlled to be limited. In the range.
  • the present invention also provides a computer storage medium storing a program, the program being executed by a computer processor to execute a string retrieval method, the method comprising: receiving a string retrieval request, the retrieval request including The first character string to be retrieved; the first character string is retrieved in the first file block that has been loaded into the memory; if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately retrieve the first string until the first string is retrieved or the entire file is traversed.
  • the full-text string retrieval function that is completely consistent with the traditional method user experience can be realized without occupying a large amount of memory.

Abstract

A string search method and device. The string search method is used for searching for a string in a file that is divided into multiple file blocks, comprising: receiving a string search request, where the search request comprises a first string to be searched (S10); searching for the first string in a first file block loaded in memory (S11); if the first string is not found in the first file block, sequentially and discretely loading the other file blocks, and searching for the first string until the first string is found or the entire file is traversed (S12), thus implementing a full text string search function completely consistent with the user experience of a conventional method without taking up a large amount of memory.

Description

字符串检索方法及装置 String retrieval method and device
【技术领域】[Technical Field]
本发明涉及文件处理技术领域,特别是涉及一种字符串检索方法及装置。The present invention relates to the field of file processing technologies, and in particular, to a string retrieval method and apparatus.
【背景技术】 【Background technique】
传统的文本编辑器在对文本文件进行任何操作之前,必须先将文件的全部内容载入内存,然后才能对已读入内存的文本内容进行全文字符串检索。如图1所示,首先将待检索的文本文件的全部文本内容载入内存,然后才对该文件进行检索,获取检索结果。可见,传统的检索方法的实现是建立在对系统资源,尤其是系统内存资源,高消耗的基础之上的。一旦文本文件容量无限制增长,对其进行字符串检索时所占用的系统资源总量也会随之陷入无限制增长的困境之中,在内存容量比较有限的电子设备上使用该方式会严重影响操作系统的运行效率。Traditional text editors must load the entire contents of a file into memory before performing any operations on the text file before it can perform full-text string retrieval of the text content that has been read into memory. As shown in FIG. 1 , the entire text content of the text file to be retrieved is first loaded into the memory, and then the file is retrieved to obtain the retrieval result. It can be seen that the implementation of the traditional retrieval method is based on the high resource consumption of system resources, especially system memory resources. Once the capacity of a text file grows without limit, the total amount of system resources used for string retrieval will also fall into the premise of unrestricted growth. This method will be seriously affected on electronic devices with limited memory capacity. The operating efficiency of the operating system.
【发明内容】  [Summary of the Invention]
本发明主要解决的技术问题是提供一种字符串检索方法及装置,能够在不对内存进行大量占用的前提下实现与传统方法用户体验完全一致的字符串全文检索功能。The technical problem to be solved by the present invention is to provide a string retrieval method and device, which can realize a full-text string retrieval function that is completely consistent with the user experience of the traditional method without occupying a large amount of memory.
为解决上述技术问题,本发明采用的一个技术方案是,提供一种字符串检索方法,该检索方法用于在被划分为多个文件块的文件中进行字符串检索,检索方法包括:接收字符串检索请求,检索请求包括待检索的第一字符串;在已载入内存的第一文件块中检索第一字符串;如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。In order to solve the above technical problem, a technical solution adopted by the present invention is to provide a string retrieval method for performing string retrieval in a file divided into a plurality of file blocks, the retrieval method comprising: receiving characters a string retrieval request, the retrieval request including the first character string to be retrieved; retrieving the first character string in the first file block loaded into the memory; if the first character string is not retrieved in the first file block, the other file is The block is loaded into memory separately and retrieves the first string until the first string is retrieved or the entire file is traversed.
其中,方法还包括:如果检索到第一字符串,将光标移动到检索到的第一字符串上并终止检索。The method further includes: if the first character string is retrieved, moving the cursor to the retrieved first character string and terminating the retrieval.
其中,字符串检索顺序为从前向后检索;在已载入内存的第一文件块中检索第一字符串包括:记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。The string retrieval order is from front to back retrieval; retrieving the first character string in the first file block that has been loaded into the memory includes: recording the current cursor position; searching backward from the current cursor position until the first search is performed The string is either retrieved to the end of the first file block.
其中,如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止包括:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。Wherein, if the first string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and the first string is retrieved until the first string is retrieved or the entire file is traversed: The first string is not retrieved in a file block, and the other file blocks arranged after the first file block are separately loaded into the memory and the first string is retrieved until the first character string is retrieved; if ranked first If the first string is not retrieved by other file blocks after the file block, the first file block from the first file block of the file to the previous file block of the first file block is sequentially loaded into the memory and the first string is retrieved until the search Until the first character string; if the first file block of the file does not retrieve the first character string from the previous file block of the first file block, the search is performed from the first position of the first file block to the current cursor position. A string until the first string is retrieved.
其中,字符串检索顺序为从后向前检索;在已载入内存的第一文件块中检索第一字符串包括:记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。The string retrieval order is retrieved from the back to the front; the first character string retrieved in the first file block that has been loaded into the memory includes: recording the current cursor position; searching forward from the current cursor position until the first search is performed A string or retrieved to the first position of the first file block.
其中,如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止包括:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。Wherein, if the first string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and the first string is retrieved until the first string is retrieved or the entire file is traversed: The first string is not retrieved in a file block, and the other file blocks arranged before the first file block are separately loaded into the memory and the first string is retrieved until the first character string is retrieved; if ranked first If the first file string is not retrieved by other file blocks before the file block, the file block from the last file block to the next file block of the first file block is sequentially loaded into the memory and the first string is retrieved until the first string is retrieved. Until the first character string; if the first file string of the file to the next file block of the first file block does not retrieve the first character string, the first character is retrieved from the end position of the first file block to the current cursor position String until the first string is retrieved.
为解决上述技术问题,本发明采用的一个技术方案是,提供一种字符串检索装置,该检索装置用于被划分为多个文件块的文件中进行字符串检索,检索装置包括:接收模块,用于接收字符串检索请求,检索请求包括待检索的第一字符串;第一检索模块,与接收模块连接,用于在已载入内存的第一文件块中检索第一字符串;第二检索模块,与第一检索模块连接,用于如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。In order to solve the above technical problem, a technical solution adopted by the present invention is to provide a character string retrieving device for performing character string retrieval in a file divided into a plurality of file blocks, the retrieving device comprising: a receiving module, For receiving a string retrieval request, the retrieval request includes a first character string to be retrieved; the first retrieval module is coupled to the receiving module, and configured to retrieve the first character string in the first file block that has been loaded into the memory; a retrieval module, connected to the first retrieval module, configured to: if the first character string is not retrieved in the first file block, load the other file blocks into the memory separately and retrieve the first character string until the first string is retrieved Or traverse the entire file.
其中,检索装置还包括跳转模块,跳转模块用于,当检索到第一字符串时,将光标移动到检索到的第一字符串上并终止检索。The retrieval device further includes a jump module, and the jump module is configured to: when the first character string is retrieved, move the cursor to the retrieved first character string and terminate the retrieval.
其中,字符串检索顺序为从前向后检索;第一检索模块用于:记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。Wherein, the string retrieval order is from front to back retrieval; the first retrieval module is configured to: record the current cursor position; start backward retrieval from the current cursor position until the first character string is retrieved or retrieved to the end of the first file block position.
其中,第二检索模块用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The second retrieval module is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string in sequence, until the retrieval Until the first string; if the first string is not retrieved by other file blocks after the first file block, then from the first file block of the file to the previous file block of the first file block, respectively Loading the memory and retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then from the first The first character string is searched from the first position of the file block to the current cursor position until the first character string is retrieved.
其中,字符串检索顺序为从后向前检索;第一检索模块用于:记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。The string retrieval order is retrieved from the back to the front; the first retrieval module is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first file block. First position.
其中,第二检索模块用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The second retrieval module is configured to: if the first character string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first character string in sequence, until the retrieval Until the first string; if the first string is not retrieved by other file blocks before the first file block, then the last file block from the file to the next file block of the first file block, respectively Into the memory and retrieve the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the next file block of the first file block, then from the first file block The last position to the current cursor position retrieves the first character string until the first character string is retrieved.
为解决上述技术问题,本发明采用的一个技术方案是,提供一种字符串检索装置,该检索装置用于被划分为多个文件块的文件中进行字符串检索,检索装置包括:收发器、存储器、处理器以及数据总线,收发器、存储器以及处理器通过数据总线相连,以进行相互通信;收发器用于接收字符串检索请求,检索请求包括待检索的第一字符串;存储器用于存储文件;处理器用于在已载入内存的第一文件块中检索第一字符串;如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。In order to solve the above technical problem, a technical solution adopted by the present invention is to provide a character string retrieval device for performing character string retrieval in a file divided into a plurality of file blocks, the retrieval device comprising: a transceiver, a memory, a processor, and a data bus, the transceiver, the memory, and the processor are connected by a data bus for communicating with each other; the transceiver is configured to receive a string retrieval request, the retrieval request includes a first character string to be retrieved; and the memory is configured to store the file The processor is configured to retrieve the first string in the first file block that has been loaded into the memory; if the first string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and retrieve the first character String until the first string is retrieved or the entire file is traversed.
其中,处理器还用于:当检索到第一字符串时,将光标移动到检索到的第一字符串上并终止检索。The processor is further configured to: when the first string is retrieved, move the cursor to the retrieved first string and terminate the retrieval.
其中,字符串检索顺序为从前向后检索;处理器用于:记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。The string retrieval order is from front to back retrieval; the processor is configured to: record the current cursor position; and search backward from the current cursor position until the first character string is retrieved or retrieved to the end position of the first file block.
其中,处理器用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The processor is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string until the first string is retrieved. Until the string is up; if the first string is not retrieved by other file blocks after the first file block, the memory file is loaded separately from the first file block of the file to the previous file block of the first file block. And retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then from the first file block The first character string is retrieved from the first position to the current cursor position until the first character string is retrieved.
其中,字符串检索顺序为从后向前检索;处理器用于:记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。The string retrieval order is retrieved from the back to the front; the processor is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block.
其中,处理器用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The processor is configured to: if the first string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first string until the first string is retrieved. Until the string is up; if the first string is not retrieved by other file blocks before the first file block, the memory file is loaded separately from the last file block of the file to the next file block of the first file block. Retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the next file block of the first file block, then from the end of the first file block The first character string is retrieved to the current cursor position until the first character string is retrieved.
通过上述方案,本发明的有益效果是:在文件中检索第一字符串时,先在已载入内存的第一文件块中检索第一字符串,如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止,使得在同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,能够在不对内存进行大量占用的前提下实现与传统方法用户体验完全一致的字符串全文检索功能。 Through the above solution, the beneficial effect of the present invention is: when the first character string is retrieved in the file, the first character string is first retrieved in the first file block loaded into the memory, if the first file block is not retrieved in the first file block a string that loads the other file blocks into memory separately and retrieves the first string until the first string is retrieved or the entire file is traversed, so that at the same time, except for the file block presented to the user in the text editor There is only one file block in the memory, which can realize the full-text string retrieval function that is completely consistent with the traditional method user experience without occupying a large amount of memory.
【附图说明】 [Description of the Drawings]
图1是现有技术中的文件载入内存的方法示意图;1 is a schematic diagram of a method for loading a file into a memory in the prior art;
图2是本发明实施例的字符串检索方法的流程示意图;2 is a schematic flow chart of a character string retrieval method according to an embodiment of the present invention;
图3是本发明实施例的文件载入内存的方法示意图;3 is a schematic diagram of a method for loading a file into a memory according to an embodiment of the present invention;
图4是图2中从前向后检索时步骤S12的方法流程示意图;4 is a schematic flow chart of the method of step S12 when searching from front to back in FIG. 2;
图5是本发明实施例的从前向后检索的方法示意图;FIG. 5 is a schematic diagram of a method for retrieving from front to back according to an embodiment of the present invention; FIG.
图6是图5中的字符串检索方法的具体流程示意图;6 is a schematic diagram of a specific process of the string retrieval method in FIG. 5;
图7是图2中从后向前检索时步骤S12的方法流程示意图;Figure 7 is a flow chart showing the method of step S12 when searching from back to front in Figure 2;
图8是本发明实施例的从后向前检索的方法示意图;8 is a schematic diagram of a method for retrieving from the back to the front according to an embodiment of the present invention;
图9是本发明第一实施例的字符串检索装置的结构示意图;FIG. 9 is a schematic structural diagram of a character string retrieving apparatus according to a first embodiment of the present invention; FIG.
图10是本发明第二实施例的字符串检索装置的结构示意图;FIG. 10 is a schematic structural diagram of a character string retrieving apparatus according to a second embodiment of the present invention; FIG.
图11是本发明第三实施例的字符串检索装置的结构示意图。Figure 11 is a block diagram showing the structure of a character string retrieving apparatus according to a third embodiment of the present invention.
【具体实施方式】【detailed description】
下面结合附图和实施方式对本发明进行详细说明。The invention will now be described in detail in conjunction with the drawings and embodiments.
图2是本发明实施例的字符串检索方法的流程示意图。如图2所示,字符串检索方法包括:2 is a schematic flow chart of a character string retrieval method according to an embodiment of the present invention. As shown in Figure 2, the string retrieval method includes:
步骤S10:接收字符串检索请求,检索请求包括待检索的第一字符串。Step S10: Receive a string retrieval request, where the retrieval request includes the first character string to be retrieved.
本发明实施例的检索方法用于在被划分为多个文件块的文件中进行字符串检索。文件的划分如图3所示,以文本文件为例,文件划分为n个区域大小相同的文件块,n为正整数。同一时刻只载入一个文件块到内存中,如图中的文件块2。The retrieval method of the embodiment of the present invention is for performing character string retrieval in a file divided into a plurality of file blocks. The file is divided as shown in Figure 3. Taking a text file as an example, the file is divided into n blocks of the same size, and n is a positive integer. Only one file block is loaded into memory at the same time, as in file block 2 in the figure.
步骤S11:在已载入内存的第一文件块中检索第一字符串。Step S11: Retrieve the first character string in the first file block that has been loaded into the memory.
检索时,先对第一文件块进行检索,其中第一文件块为已载入内存的当前文件块,该当前文件块部分或全部载入文件编辑器中。如果在第一文件块中检索到第一字符串,将光标跳转到匹配的字符串的位置,终止检索。When retrieving, the first file block is searched first, wherein the first file block is the current file block loaded into the memory, and the current file block is partially or completely loaded into the file editor. If the first character string is retrieved in the first file block, the cursor is jumped to the position of the matching character string, and the retrieval is terminated.
步骤S12:如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。Step S12: If the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately and the first character string is retrieved until the first character string is retrieved or the entire file is traversed.
在步骤S12中,对其它文件块进行检索时,同一时刻只将其它文件块中一个待检索的文件块载入内存并检索第一字符串。对该文件块检索完成后,如果没有检索到第一字符串,则将该已检索完的文件块移除内存,并依次将该文件块的下一个文件块载入内存并继续检索第一字符串,直至检索到第一字符串或遍历整个文件为止。如果检索到第一字符串,将光标移动到检索到的第一字符串上并终止检索,同时将第一字符串所在的文件块载入文本编辑器呈现给用户。如此使得在此检索过程中同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,能够在不对内存进行大量占用的前提下实现与传统方法用户体验完全一致的字符串全文检索功能。In step S12, when searching for other file blocks, only one file block to be retrieved in other file blocks is loaded into the memory and the first character string is retrieved at the same time. After the file block is retrieved, if the first string is not retrieved, the retrieved file block is removed from the memory, and the next file block of the file block is sequentially loaded into the memory and the first character is continuously retrieved. String until the first string is retrieved or the entire file is traversed. If the first string is retrieved, the cursor is moved to the retrieved first string and the retrieval is terminated, and the file block in which the first string is located is loaded into the text editor for presentation to the user. In this way, in the retrieval process, except for the file block presented to the user in the text editor, and only one file block exists in the memory, the user experience with the traditional method can be realized without occupying a large amount of memory. Fully consistent string full-text search capabilities.
在更具体的实施例中,字符串检索顺序可以为从前向后检索,也可以为从后向前检索。以下分别对两种检索方法进行说明。In a more specific embodiment, the string retrieval order may be retrieved from front to back or from back to front. The following two methods are described separately.
字符串检索顺序可以为从前向后检索时,先检索当前光标位置至第一文件块的末位置的文件部分,再检索第一文件块的末位置至文件末尾的文件部分,然后检索文件开头至第一文件块的首位置的文件部分,最后检索第一文件块的首位置至当前光标位置的文件部分。其中,首位置为第一文件块起点在文件全文中所处的位置,即文件指针从文件开头移动到第一文件块起点所产生的偏移量。末位置为当第一文件块终点在文件全文中所处的位置,即文件指针从文件开头移动到第一文件块终点所产生的偏移量。The string retrieval order may be to retrieve the current cursor position to the end of the first file block when searching from front to back, and then search the end of the first file block to the file portion at the end of the file, and then retrieve the file to the beginning The file portion of the first position of the first file block, and finally the first portion of the first file block is retrieved to the portion of the file at the current cursor position. The first position is the position where the starting point of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the beginning of the first file block. The last position is the position where the end of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the end of the first file block.
字符串检索顺序可以为从前向后检索时,在步骤S11中,记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。即检索当前光标位置至第一文件块末位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的末位置。距离当前光标位置越近的字符串越优先被检索到。如果检索到第一字符串,将光标跳转到第一字符串的位置并选中第一字符串。若在完成对第一文件块中的当前光标位置至第一文件块末位置之间的文件块部分的遍历后仍未能检索到匹配的字符串,则继续执行后续的检索。其中,当前光标位置为光标在第一文件块中当前所处位置。在步骤S11的检索过程中,同一时刻有仅只有第一文件块载入内存中。不对内存进行大量占用。The string retrieval order may be from the front to the back retrieval, in step S11, the current cursor position is recorded; the current cursor position is searched backward until the first character string is retrieved or the last position of the first file block is retrieved. That is, the file block portion between the current cursor position and the end position of the first file block is retrieved. When searching, the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the end of the first file block is retrieved. position. The closer the string is to the current cursor position, the more preferential it is retrieved. If the first string is retrieved, the cursor is jumped to the position of the first string and the first string is selected. If the matching string is not retrieved after completing the traversal of the file block portion between the current cursor position in the first file block and the end position of the first file block, the subsequent retrieval is continued. The current cursor position is the current position of the cursor in the first file block. In the retrieval process of step S11, only the first file block is loaded into the memory at the same time. Do not use a lot of memory.
参见图4,在步骤S12中,包括:Referring to FIG. 4, in step S12, the method includes:
步骤S120:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止。Step S120: If the first character string is not retrieved in the first file block, the other file blocks arranged after the first file block are sequentially loaded into the memory and the first character string is retrieved until the first character string is retrieved. .
其中,排在第一文件块之后的其它文件块表示与第一文件块的末位置至文件末尾之间的文件部分。在步骤S120中,以文件块为单位,将该部分的文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并将与该文件块相邻的下一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历该文件部分为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。Among them, the other file blocks ranked after the first file block represent the portion of the file between the end position of the first file block and the end of the file. In step S120, the file blocks of the portion are sequentially loaded into the memory in units of file blocks and the first character string is retrieved line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
步骤S121:如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止。Step S121: If the first character string is not retrieved from other file blocks that are arranged after the first file block, the first file block from the file to the previous file block of the first file block are sequentially loaded into the memory. The first string is retrieved until the first string is retrieved.
其中,从文件的第一个文件块至第一文件块的上一个文件块表示文件开头至第一文件块的首位置的文件部分。步骤S121中的检索方法与步骤S120中方法类似,以文件开头为起点至第一文件块的首位置,以文件块为单位,依次将该部分的文件块单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并将与该文件块相邻的下一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历该文件部分为止。Wherein, the first file block from the file to the previous file block of the first file block represents the file portion at the beginning of the file to the first position of the first file block. The retrieval method in step S121 is similar to the method in step S120, starting from the beginning of the file to the first position of the first file block, in the file block unit, sequentially loading the partial file block into the memory and searching the first line by line. String. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file.
步骤S120和步骤S121中检索的文件部分在检索之前是不在内存中的,只在检索时载入内存,完成检索且未检索到第一字符串则立即移除内存。如果在检索过程中检索到第一字符串后终止检索,将第一字符串所在的文件块载入文本编辑器呈现给用户,并将光标跳转到第一字符串的位置并选中该第一字符串。The portion of the file retrieved in step S120 and step S121 is not in memory before the retrieval, and is only loaded into the memory at the time of retrieval, and the memory is immediately removed after the retrieval is completed and the first character string is not retrieved. If the retrieval is terminated after the first string is retrieved during the retrieval process, the file block in which the first character string is located is loaded into the text editor and presented to the user, and the cursor is jumped to the position of the first character string and the first is selected. String.
步骤S122:如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。Step S122: If the first file string of the file does not retrieve the first character string from the first file block of the first file block, the first character string is retrieved from the first position of the first file block to the current cursor position. Until the first string is retrieved.
在步骤S122中,将当前光标位置将作为检索第一字符串的终点,逐行进行检索,直至遍历从第一文件块的首位置至当前光标位置的文件部分。In step S122, the current cursor position is retrieved line by line as the end point for retrieving the first character string until the portion of the file from the first position of the first file block to the current cursor position is traversed.
在本发明实施例的整个检索过程中,同一时刻除文本编辑器中呈现给用户的第一文件块之外至多有一个文件块存在于内存中,即同一时刻至多有两个文件块存在于内存中,而本发明实施例的检索方法能够达到与传统方法相同的检索效果,因此能够在不对内存进行大量占用的前提下实现与传统方法用户体验完全一致的字符串全文检索功能。In the entire retrieval process of the embodiment of the present invention, at least one file block exists in the memory except for the first file block presented to the user in the text editor at the same time, that is, at most two file blocks exist in the memory at the same time. The retrieval method of the embodiment of the present invention can achieve the same retrieval effect as the traditional method, so that the full-text string retrieval function consistent with the user experience of the traditional method can be realized without occupying a large amount of memory.
图5是本发明实施例的从前向后检索的方法示意图。如图5所示,文件中的第一文件块已经载入内存中,并部分或全部载入了文件编译器中。而文件中的除第一文件块以外的其余文件块未载入内存中。首位置为第一文件块起点在文件全文中所处的位置,即文件指针从文件开头移动到第一文件块起点所产生的偏移量。末位置为第一文件块终点在文件全文中所处的位置,即文件指针从文件开头移动到第一文件块终点所产生的偏移量。图中箭头表示检索的方向,即从当前光标位置向后检索,具体包括:FIG. 5 is a schematic diagram of a method for retrieving from front to back according to an embodiment of the present invention. As shown in Figure 5, the first file block in the file is already loaded into memory and partially or fully loaded into the file compiler. The remaining file blocks in the file except the first file block are not loaded into memory. The first position is the position where the starting point of the first file block is in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the beginning of the first file block. The last position is the position of the end of the first file block in the full text of the file, that is, the offset generated by the file pointer moving from the beginning of the file to the end of the first file block. The arrow in the figure indicates the direction of the search, that is, the search from the current cursor position, including:
步骤1:检索当前光标位置至第一文件块末位置之间的文件部分。Step 1: Retrieve the portion of the file between the current cursor position and the end position of the first file block.
步骤2:检索第一文件块末位置至文件末尾之间的文件部分。Step 2: Retrieve the portion of the file between the end of the first file block and the end of the file.
步骤3:检索文件开头至第一文件块首位置之间的文件部分。Step 3: Retrieve the portion of the file between the beginning of the file and the first position of the first file block.
步骤4:检索第一文件块首位置至当前光标位置之间的文件部分。Step 4: Retrieve the portion of the file between the first file block head position and the current cursor position.
更具体的流程参见参见图6,基于文件的检索方法包括:For a more specific process, see Figure 6, the file-based retrieval method includes:
步骤S100:对第一文件块中光标后面的文件部分进行检索。即检索当前光标位置至第一文件块在文件中的末位置之间的文件部分。在此检索过程中,同一时刻只有文本编辑器中呈现给用户的第一文件块,保证了检索过程中对系统资源的占用被控制在有限的范围内。Step S100: Searching for a portion of the file behind the cursor in the first file block. That is, the portion of the file between the current cursor position and the last position of the first file block in the file is retrieved. In this retrieval process, only the first file block presented to the user in the text editor at the same time ensures that the occupation of system resources in the retrieval process is controlled within a limited range.
步骤S101:判断是否检索到第一字符串。如果在第一文件块中光标后面的文件部分中没有检索到字符串,则执行步骤S102,如果在第一文件块中光标后面的文件部分中检索到字符串,则执行步骤S108。Step S101: It is determined whether the first character string is retrieved. If the character string is not retrieved in the file portion behind the cursor in the first file block, step S102 is performed, and if the character string is retrieved in the file portion following the cursor in the first file block, step S108 is performed.
步骤S102:对第一文件块末位置与文件末尾之间的文件部分进行检索。即检索第一文件块在文件中的末位置至文件末尾之间的文件部分。Step S102: Searching for a portion of the file between the end position of the first file block and the end of the file. That is, the file portion of the first file block between the end of the file and the end of the file is retrieved.
在步骤S102中,以第一文件块在文件中的末位置为起点,以文件块为单位,依次单独将要检索的文件块载入内存并检索第一字符串,检索完成后,将该文件块移除内存并将该文件块的下一文件块载入内存继续检索第一字符串,直至检索到第一字符串,或者完成对末位置与文件末尾之间的文件部分的检索。在此检索过程中,可以保证同一时刻除文本编辑器中呈现给用户的第一文件块之外有且仅有一个文件块存在于内存中,从而保证了检索过程中对系统资源的占用被控制在有限的范围内。In step S102, the file block to be retrieved is sequentially loaded into the memory and the first character string is sequentially searched in units of file blocks in the file block as the starting point of the first file block, and the file block is retrieved after the retrieval is completed. The memory is removed and the next file block of the file block is loaded into memory to continue to retrieve the first string until the first string is retrieved, or the retrieval of the portion of the file between the end position and the end of the file is completed. In this retrieval process, it can be ensured that at the same time, except for the first file block presented to the user in the text editor, and only one file block exists in the memory, thereby ensuring that the occupation of system resources during the retrieval process is controlled. Within a limited range.
步骤S103:判断是否检索到第一字符串。如果在末位置与文件末尾之间的文件部分中没有检索到字符串,则执行步骤S104,如果在末位置与文件末尾之间的文件部分中检索到字符串,则执行步骤S108。Step S103: It is judged whether the first character string is retrieved. If the character string is not retrieved in the file portion between the last position and the end of the file, step S104 is performed, and if the character string is retrieved in the file portion between the last position and the end of the file, step S108 is performed.
步骤S104:对文件开头与首位置之间的文件部分进行检索。即检索文件开头至第一文件块在文件中的首位置之间的文件部分。Step S104: Searching for a portion of the file between the beginning and the first position of the file. That is, the portion of the file between the beginning of the file and the first position of the first file block in the file is retrieved.
在步骤S104中,以文件开头为起点,第一文件块在文件中的首位置为终点,以文件块为单位,依次将要检索的文件块载入内存并检索第一字符串。检索完成后,将该文件块移除内存并将该文件块的下一文件块载入内存继续检索第一字符串,直至检索到第一字符串,或者完成对文件开头与首位置之间的文件部分的检索。在此检索过程中,可以保证同一时刻除文本编辑器中呈现给用户的第一文件块之外有且仅有一个文件块存在于内存中,从而保证了检索过程中对系统资源的占用被控制在有限的范围内。In step S104, starting from the beginning of the file, the first file block is the end point in the file, and in the file block unit, the file block to be retrieved is sequentially loaded into the memory and the first character string is retrieved. After the retrieval is completed, the file block is removed from the memory and the next file block of the file block is loaded into the memory to continue to retrieve the first string until the first string is retrieved, or between the beginning and the beginning of the file. Retrieval of the file part. In this retrieval process, it can be ensured that at the same time, except for the first file block presented to the user in the text editor, and only one file block exists in the memory, thereby ensuring that the occupation of system resources during the retrieval process is controlled. Within a limited range.
步骤S105:判断是否检索到第一字符串。如果在文件开头与首位置之间的文件部分中没有检索到第一字符串,则执行步骤S106,如果在文件开头与首位置之间的文件部分中检索到字符串,则执行步骤S108。Step S105: It is judged whether the first character string is retrieved. If the first character string is not retrieved in the file portion between the beginning of the file and the first position, step S106 is performed, and if the character string is retrieved in the file portion between the beginning and the beginning of the file, step S108 is performed.
步骤S106:对第一文件块中当前光标位置前面的文件部分检索第一字符串。即检索第一文件块在文件中的首位置至当前光标位置之前的文件部分,以第一文件块在文件中的首位置为起点,当前光标位置为终点检索第一字符串。在此检索过程中,同一时刻只有文本编辑器中呈现给用户的第一文件块,保证了检索过程中对系统资源的占用被控制在有限的范围内。Step S106: Retrieve the first character string for the portion of the file preceding the current cursor position in the first file block. That is, the first file block is retrieved from the first position in the file to the file portion before the current cursor position, and the first file block is used as the starting point in the first position of the file, and the current cursor position is the end point to retrieve the first character string. In this retrieval process, only the first file block presented to the user in the text editor at the same time ensures that the occupation of system resources in the retrieval process is controlled within a limited range.
步骤S107:判断是否检索到第一字符串。如果在第一文件块中当前光标位置前面的文件部分中没有检索到第一字符串,则执行步骤S106,如果在第一文件块中当前光标位置的文件部分中检索到第一字符串,则执行步骤S108。Step S107: It is judged whether the first character string is retrieved. If the first character string is not retrieved in the file portion preceding the current cursor position in the first file block, step S106 is performed, if the first character string is retrieved in the file portion of the current cursor position in the first file block, Step S108 is performed.
步骤S108:检索成功,返回字第一字符串所处位置。即检索到第一字符串,将光标跳转到第一字符串的位置并选中该第一字符串。如果检索到的第一字符串所在的文件块为除第一文件块之外的其它文件块,则同时将该文件块载入文件编辑器呈现给用户。Step S108: The retrieval is successful, and the position where the first character string of the word is located is returned. That is, the first character string is retrieved, the cursor is jumped to the position of the first character string, and the first character string is selected. If the file block in which the retrieved first string is located is a file block other than the first file block, the file block is simultaneously loaded into the file editor and presented to the user.
步骤S109:检索失败。说明整个文件中不存在匹配的字符串。Step S109: The retrieval fails. Indicates that there is no matching string in the entire file.
以下以字符串检索顺序可以为从后向前检索进行说明:The following can be retrieved from the back to the front in the string search order:
字符串检索顺序可以为从后向前检索时,先检索当前光标位置至第一文件块的首位置的文件部分,再检索第一文件块的首位置至文件开头的文件部分,然后检索文件末尾至第一文件块的末位置的文件部分,最后检索第一文件块的末位置至当前光标位置的文件部分。The string retrieval order may be, when searching from the back to the front, first retrieving the current cursor position to the file portion of the first position of the first file block, and then retrieving the first position of the first file block to the file portion at the beginning of the file, and then retrieving the end of the file. To the portion of the file at the end of the first file block, the last portion of the first file block is finally retrieved to the portion of the file at the current cursor position.
此时在步骤S11中,记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。即检索当前光标位置至第一文件块首位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的首位置。距离当前光标位置越近的字符串越优先被检索到。如果检索到第一字符串,将光标跳转到第一字符串的位置并选中第一字符串。若在完成对第一文件块中的当前光标位置至第一文件块首位置之间的文件块部分的遍历后仍未能检索到匹配的字符串,则继续执行后续的检索。其中,当前光标位置为光标在第一文件块中当前所处位置。At this time, in step S11, the current cursor position is recorded; the forward search is started from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block. That is, the file block portion between the current cursor position and the first file block position is retrieved, and when the search is performed, the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the first file block is retrieved. position. The closer the string is to the current cursor position, the more preferential it is retrieved. If the first string is retrieved, the cursor is jumped to the position of the first string and the first string is selected. If the matching character string is still not retrieved after completing the traversal of the file block portion between the current cursor position in the first file block and the first file block head position, the subsequent retrieval is continued. The current cursor position is the current position of the cursor in the first file block.
参见图7,在步骤S12中,包括:Referring to FIG. 7, in step S12, the method includes:
步骤S123:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止。Step S123: If the first character string is not retrieved in the first file block, the other file blocks arranged before the first file block are separately loaded into the memory and the first character string is retrieved until the first character string is retrieved. .
其中,排在第一文件块之前的其它文件块表示与第一文件块的首位置至文件开头之间的文件部分。在步骤S123中,以文件块为单位,将该部分的文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并将与该文件块相邻的上一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历该文件部分为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。Among them, other file blocks ranked before the first file block represent portions of the file from the first position of the first file block to the beginning of the file. In step S123, the file blocks of the portion are sequentially loaded into the memory in units of file blocks and the first character string is retrieved line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
步骤S124:如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止。Step S124: If the first character string is not retrieved from other file blocks before the first file block, the last file block from the file to the next file block of the first file block are sequentially loaded into the memory and retrieved. The first string until the first string is retrieved.
其中,文件的最后一个文件块至第一文件块的下一个文件块表示文件末尾至第一文件块的末位置的文件部分。步骤S124中的检索方法与步骤S123中方法类似,以文件末尾为起点至第一文件块的末位置,以文件块为单位,依次将该部分的文件块单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并将与该文件块相邻的下一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历该文件部分为止。The last file block of the file to the next file block of the first file block represents the file portion at the end of the file to the end of the first file block. The retrieval method in step S124 is similar to the method in step S123, starting from the end of the file to the end of the first file block, in the file block unit, sequentially loading the partial file block into the memory and searching the first line by line. String. If the first string is not retrieved in the retrieved file block, the file block is removed from memory, and the next file block adjacent to the file block is loaded into the memory to continue to retrieve the first string line by line until Retrieve the first string or traverse the portion of the file.
步骤S123和步骤S124中检索的文件部分在检索之前是不在内存中的,只在检索时载入内存,完成检索且未检索到第一字符串则立即移除内存。如果在检索过程中检索到第一字符串后终止检索,将第一字符串所在的文件块载入文本编辑器呈现给用户,并将光标跳转到第一字符串的位置并选中该第一字符串。The file portion retrieved in step S123 and step S124 is not in memory before the retrieval, and is only loaded into the memory at the time of retrieval, and the memory is immediately removed after the retrieval is completed and the first character string is not retrieved. If the retrieval is terminated after the first string is retrieved during the retrieval process, the file block in which the first character string is located is loaded into the text editor and presented to the user, and the cursor is jumped to the position of the first character string and the first is selected. String.
步骤S125:如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。Step S125: If the first file string is not retrieved from the last file block of the file to the next file block of the first file block, the first character string is retrieved from the end position of the first file block to the current cursor position until Retrieve the first string.
在步骤S125中,将当前光标位置将作为检索第一字符串的终点,逐行进行检索,直至遍历从第一文件块的末位置至当前光标位置的文件部分。In step S125, the current cursor position is retrieved line by line as the end point of the first character string, until the file portion from the last position of the first file block to the current cursor position is traversed.
图8是本发明实施例的从后向前检索的方法示意图。与图5相比,区别仅在于箭头所表示的检索的方向刚好相反,即从当前光标位置向前检索,具体包括:FIG. 8 is a schematic diagram of a method for retrieving from the back to the front according to an embodiment of the present invention. Compared with FIG. 5, the only difference is that the direction of the search indicated by the arrow is just the opposite, that is, the forward search from the current cursor position, specifically including:
步骤10:检索当前光标位置至第一文件块首位置之间的文件部分。Step 10: Retrieve the portion of the file between the current cursor position and the first file block head position.
步骤20:检索第一文件块首位置至文件开头之间的文件部分。Step 20: Retrieve the portion of the file between the first file block header and the beginning of the file.
步骤30:检索文件末尾至第一文件块末位置之间的文件部分。Step 30: Retrieve the portion of the file between the end of the file and the end of the first file block.
步骤40:检索第一文件块末位置至当前光标位置之间的文件部分。Step 40: Retrieve the portion of the file between the end position of the first file block and the current cursor position.
更具体的流程与从当前光标位置向后检索类似,区别仅在于检索的方向不同。例如,在步骤20中,以第一文件块在文件中的首位置为起点,文件开头为终点,以文件块为单位,依次单独将要检索的文件块载入内存并检索第一字符串。检索完成后,将该文件块移除内存并将该文件块的下一文件块载入内存继续检索第一文件块,直至检索到第一字符串,或者完成对文件开头与首位置之间的文件部分的检索。其他文件部分以此类推,不再赘述。A more specific process is similar to retrieving backwards from the current cursor position, except that the direction of the search is different. For example, in step 20, the first file block starts from the first position in the file, the file starts as the end point, and the file block to be retrieved is sequentially loaded into the memory and the first character string is retrieved in units of file blocks. After the retrieval is completed, the file block is removed from the memory and the next file block of the file block is loaded into the memory to continue to retrieve the first file block until the first string is retrieved, or between the beginning and the beginning of the file. Retrieval of the file part. Some other parts of the document are deduced by analogy and will not be described again.
图9是本发明第一实施例的字符串检索装置的结构示意图。如图9所示,字符串检索装置10包括:接收模块11、第一检索模块12以及第二检索模块13。Fig. 9 is a block diagram showing the structure of a character string retrieving apparatus according to a first embodiment of the present invention. As shown in FIG. 9, the character string retrieval device 10 includes a receiving module 11, a first retrieval module 12, and a second retrieval module 13.
检索装置10用于被划分为多个文件块的文件中进行字符串检索。接收模块11用于接收字符串检索请求,检索请求包括待检索的第一字符串。第一检索模块12与接收模块11连接,用于在已载入内存的第一文件块中检索第一字符串。第二检索模块13与第一检索模块12连接,用于如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。The retrieval device 10 performs a character string search for a file divided into a plurality of file blocks. The receiving module 11 is configured to receive a string retrieval request, where the retrieval request includes a first character string to be retrieved. The first retrieval module 12 is coupled to the receiving module 11 for retrieving the first character string in the first file block that has been loaded into the memory. The second retrieval module 13 is connected to the first retrieval module 12, and if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and the first character string is retrieved until the first character string is retrieved. A string or traversing the entire file.
参见图10,检索装置10还包括跳转模块14。跳转模块14用于当检索到第一字符串时,将光标移动到检索到的第一字符串上并终止检索。如果第二检索模块13在其它文件块中检索到第一字符串,则跳转模块14还将第一字符串所在的文件块载入文本编辑器呈现给用户。Referring to FIG. 10, the retrieval device 10 further includes a jump module 14. The jump module 14 is configured to move the cursor to the retrieved first character string and terminate the retrieval when the first character string is retrieved. If the second retrieval module 13 retrieves the first character string in other file blocks, the jump module 14 also presents the file block in which the first character string is located to the text editor for presentation to the user.
字符串检索顺序可以为从前向后检索,也可以为从后向前检索。以下分别对两种检索方法进行说明。The string retrieval order can be retrieved from front to back or from back to front. The following two methods are described separately.
字符串检索顺序为从前向后检索时,第一检索模块12用于:记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。即第一检索模块12检索当前光标位置至第一文件块末位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的末位置。距离当前光标位置越近的字符串越优先被第一检索模块12检索到。其中,当前光标位置为光标在第一文件块中当前所处位置。When the string retrieval order is from front to back retrieval, the first retrieval module 12 is configured to: record the current cursor position; start backward retrieval from the current cursor position until the first character string is retrieved or retrieved to the end of the first file block position. That is, the first search module 12 retrieves the file block portion between the current cursor position and the end position of the first file block. When searching, the current cursor position is used as the starting point for searching the first character string, and the search is performed line by line until the first search is performed. The end position of a file block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the first retrieval module 12. The current cursor position is the current position of the cursor in the first file block.
此时第二检索模块13用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。At this time, the second retrieval module 13 is configured to: if the first character string is not retrieved in the first file block, load the other file blocks that are arranged after the first file block into the memory and retrieve the first character string, respectively, until Retrieving the first character string; if the first file string is not retrieved by other file blocks after the first file block, then from the first file block of the file to the previous file block of the first file block, in turn Loading the memory separately and retrieving the first string until the first string is retrieved; if the first file block of the file does not retrieve the first string from the previous file block of the first file block, then The first character string of the first block to the current cursor position is retrieved until the first character string is retrieved.
在上述检索过程中,第二检索模块13以文件块为单位,将文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并依次将与该文件块相邻的下一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历其它文件块为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。In the above retrieval process, the second retrieval module 13 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the next file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
字符串检索顺序为从后向前检索时,第一检索模块12用于:记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。即第一检索模块12检索当前光标位置至第一文件块首位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的首位置。距离当前光标位置越近的字符串越优先被第一检索模块12检索到。其中,当前光标位置为光标在第一文件块中当前所处位置。When the string retrieval order is retrieved from the back to the front, the first retrieval module 12 is configured to: record the current cursor position; and search forward from the current cursor position until the first character string is retrieved or retrieved to the first file block. First position. That is, the first retrieval module 12 retrieves the current block position to the file block portion between the first file block head position. When searching, the current cursor position is used as the starting point for retrieving the first character string, and the search is performed line by line until the first search is performed. The first position of a file block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the first retrieval module 12. The current cursor position is the current position of the cursor in the first file block.
此时第二检索模块13用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。At this time, the second retrieval module 13 is configured to: if the first character string is not retrieved in the first file block, load the other file blocks before the first file block into the memory and retrieve the first character string, respectively, until Retrieving the first character string; if the first file string is not retrieved by other file blocks before the first file block, then from the last file block of the file to the next file block of the first file block, respectively Loading the memory and retrieving the first string until the first string is retrieved; if the first file from the last file block of the file to the next file block of the first file block does not retrieve the first string, then from the first file The first character string is retrieved from the end position of the block to the current cursor position until the first character string is retrieved.
在上述检索过程中,第二检索模块13以文件块为单位,将文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并依次将与该文件块相邻的上一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历其它文件块为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。In the above retrieval process, the second retrieval module 13 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
如果判第一检索模块12在已载入内存的第一文件块中未检索第一字符串,并且第二检索模块13在其它文件块中也未检索到第一字符串,则说明文件中不存在匹配的字符串,检索失败。If it is determined that the first search module 12 does not retrieve the first character string in the first file block that has been loaded into the memory, and the second search module 13 does not retrieve the first character string in other file blocks, then the file does not indicate There is a matching string and the search failed.
图11是本发明第一实施例的字符串检索装置的结构示意图。如图11所示,字符串检索装置20包括:收发器21、存储器22、处理器23以及数据总线24,收发器21、存储器22以及处理器23通过数据总线24相连,以进行相互通信。Figure 11 is a block diagram showing the structure of a character string retrieving apparatus according to a first embodiment of the present invention. As shown in FIG. 11, the character string retrieval device 20 includes a transceiver 21, a memory 22, a processor 23, and a data bus 24. The transceiver 21, the memory 22, and the processor 23 are connected via a data bus 24 to communicate with each other.
收发器21用于接收字符串检索请求,检索请求包括待检索的第一字符串。存储器22用于存储文件。处理器23用于在已载入内存的第一文件块中检索第一字符串;如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。The transceiver 21 is configured to receive a string retrieval request, the retrieval request including a first character string to be retrieved. The memory 22 is used to store files. The processor 23 is configured to retrieve the first character string in the first file block that has been loaded into the memory; if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and retrieved first A string until the first string is retrieved or the entire file is traversed.
在本发明实施例中,处理器23还用于:当检索到第一字符串时,将光标移动到检索到的第一字符串上并终止检索。如果处理器23在其它文件块中检索到第一字符串,则处理器23还将第一字符串所在的文件块载入文本编辑器呈现给用户。In the embodiment of the present invention, the processor 23 is further configured to: when the first character string is retrieved, move the cursor to the retrieved first character string and terminate the retrieval. If the processor 23 retrieves the first character string in other file blocks, the processor 23 also presents the file block in which the first character string is located to the text editor for presentation to the user.
字符串检索顺序可以为从前向后检索,也可以为从后向前检索。以下分别对两种检索方法进行说明。The string retrieval order can be retrieved from front to back or from back to front. The following two methods are described separately.
字符串检索顺序为从前向后检索时,处理器23用于:记录下当前光标位置;从当前光标位置开始向后检索,直至检索到第一字符串或者检索至第一文件块的末位置。即处理器23检索当前光标位置至第一文件块末位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的末位置。距离当前光标位置越近的字符串越优先被处理器23检索到。其中,当前光标位置为光标在第一文件块中当前所处位置。存储器22还存储当前光标位置、第一文件块的首位置以及第一文件块的末位置。When the string retrieval order is from front to back retrieval, the processor 23 is configured to: record the current cursor position; and search backward from the current cursor position until the first character string is retrieved or retrieved to the end position of the first file block. That is, the processor 23 retrieves the current block position to the file block portion between the end positions of the first file block. When searching, the current cursor position is used as the starting point for retrieving the first character string, and is retrieved line by line until the first file is retrieved. The end position of the block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the processor 23. The current cursor position is the current position of the cursor in the first file block. The memory 22 also stores the current cursor position, the first position of the first file block, and the last position of the first file block.
处理器23从当前光标位置检索至第一文件块的末位置未检索检索到第一字符串,则处理器还用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之后的其它文件块均未检索出第一字符串,则从文件的第一个文件块至第一文件块的上一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的第一个文件块至第一文件块的上一个文件块均未检索出第一字符串,则从第一文件块的首位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The processor 23 retrieves from the current cursor position to the end position of the first file block and does not retrieve the first character string, and the processor is further configured to: if the first character string is not retrieved in the first file block, The other file blocks after the first file block are sequentially loaded into the memory and retrieved the first character string until the first character string is retrieved; if the first file string is not retrieved in the other file blocks after the first file block , from the first file block of the file to the previous file block of the first file block, sequentially loaded into the memory and retrieved the first string until the first string is retrieved; if the first file block of the file If the first character string is not retrieved until the previous file block of the first file block, the first character string is retrieved from the first position of the first file block to the current cursor position until the first character string is retrieved.
在上述检索过程中,处理器23以文件块为单位,将文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并依次将与该文件块相邻的下一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历其它文件块为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。In the above retrieval process, the processor 23 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the next file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the file block presented to the user in the text editor, only one file block exists in the memory, which ensures that the occupation of system resources in the entire retrieval process is controlled within a limited range. Inside.
字符串检索顺序为从后向前检索时,处理器23用于:记录下当前光标位置;从当前光标位置开始向前检索,直至检索到第一字符串或者检索至第一文件块的首位置。即处理器23检索当前光标位置至第一文件块首位置之间的文件块部分,检索时,将当前光标位置将作为检索第一字符串的起点,逐行进行检索,直至检索到第一文件块的首位置。距离当前光标位置越近的字符串越优先被处理器23检索到。其中,当前光标位置为光标在第一文件块中当前所处位置。When the string retrieval order is retrieved from the back to the front, the processor 23 is configured to: record the current cursor position; search forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block . That is, the processor 23 retrieves the current block position to the file block portion between the first file block head position. When searching, the current cursor position is used as the starting point for retrieving the first character string, and is retrieved line by line until the first file is retrieved. The first position of the block. The closer the character string is to the current cursor position, the more preferentially it is retrieved by the processor 23. The current cursor position is the current position of the cursor in the first file block.
处理器23从当前光标位置检索至第一文件块的首位置未检索检索到第一字符串,则处理器23还用于:如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果排在第一文件块之前的其它文件块均未检索出第一字符串,则从文件的最后一个文件块至第一文件块的下一个文件块,依次单独载入内存并检索第一字符串,直至检索到第一字符串为止;如果文件的最后一个文件块至第一文件块的下一个文件块均未检索出第一字符串,则从第一文件块的末位置至当前光标位置进行检索第一字符串,直至检索到第一字符串为止。The processor 23 retrieves from the current cursor position to the first position of the first file block and does not retrieve the first character string, and the processor 23 is further configured to: if the first character string is not retrieved in the first file block, The other file blocks preceding the first file block are sequentially loaded into the memory and retrieved the first character string until the first character string is retrieved; if the first file character is not retrieved in the other file blocks before the first file block The string, from the last file block of the file to the next file block of the first file block, is sequentially loaded into the memory and retrieves the first string until the first string is retrieved; if the last file block of the file is If the first character string is not retrieved in the next file block of the first file block, the first character string is retrieved from the last position of the first file block to the current cursor position until the first character string is retrieved.
在上述检索过程中,处理器23以文件块为单位,将文件块依次单独载入内存并逐行检索第一字符串。如果在检索的文件块中没有检索到第一字符串,则将该文件块移除内存,并依次将与该文件块相邻的上一文件块载入内存继续逐行检索第一字符串,直到检索到第一字符串或者遍历其它文件块为止。在此检索过程中,同一时刻除文本编辑器中呈现给用户的第一文件块之外有且仅有一个文件块存在于内存中,保证了整个检索过程中对系统资源的占用被控制在有限的范围内。In the above retrieval process, the processor 23 sequentially loads the file blocks into the memory in units of file blocks and retrieves the first character string line by line. If the first string is not retrieved in the retrieved file block, the file block is removed from the memory, and the previous file block adjacent to the file block is sequentially loaded into the memory to continue to retrieve the first string line by line. Until the first string is retrieved or traversed through other file blocks. In this retrieval process, at the same time, except for the first file block presented to the user in the text editor, and only one file block exists in the memory, the use of system resources in the entire retrieval process is controlled to be limited. In the range.
本发明还提供一种计算机存储介质,所述计算机存储介质存储有程序,所述程序被计算机处理器执行时运行一种字符串检索方法,所述方法包括:接收字符串检索请求,检索请求包括待检索的第一字符串;在已载入内存的第一文件块中检索第一字符串;如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索第一字符串,直至检索到第一字符串或遍历整个文件为止。如此能够在不对内存进行大量占用的前提下实现与传统方法用户体验完全一致的字符串全文检索功能。The present invention also provides a computer storage medium storing a program, the program being executed by a computer processor to execute a string retrieval method, the method comprising: receiving a string retrieval request, the retrieval request including The first character string to be retrieved; the first character string is retrieved in the first file block that has been loaded into the memory; if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately Retrieve the first string until the first string is retrieved or the entire file is traversed. In this way, the full-text string retrieval function that is completely consistent with the traditional method user experience can be realized without occupying a large amount of memory.
以上仅为本发明的实施方式,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。 The above is only the embodiment of the present invention, and is not intended to limit the scope of the invention, and the equivalent structure or equivalent process transformation made by the specification and the drawings of the present invention may be directly or indirectly applied to other related technical fields. The same is included in the scope of patent protection of the present invention.

Claims (18)

  1. 一种字符串检索方法,其中,所述检索方法用于在被划分为多个文件块的文件中进行字符串检索,所述方法包括:A string retrieval method, wherein the retrieval method is used for performing string retrieval in a file divided into a plurality of file blocks, the method comprising:
    接收字符串检索请求,所述检索请求包括待检索的第一字符串;Receiving a string retrieval request, the retrieval request including a first character string to be retrieved;
    在已载入内存的第一文件块中检索所述第一字符串;Retrieving the first string in a first file block that has been loaded into memory;
    如果在所述第一文件块中未检索到所述第一字符串,将其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串或遍历整个所述文件为止。If the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately and the first character string is retrieved until the first character string is retrieved or the entire directory is traversed Until the document is mentioned.
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method of claim 1 further comprising:
    当检索到所述第一字符串时,将光标移动到检索到的所述第一字符串上并终止检索。When the first character string is retrieved, the cursor is moved to the retrieved first character string and the retrieval is terminated.
  3. 根据权利要求1所述的方法,其特征在于,所述字符串检索顺序为从前向后检索;The method of claim 1 wherein said string retrieval order is retrieved from front to back;
    所述在已载入内存的第一文件块中检索所述第一字符串包括:The retrieving the first string in the first file block that has been loaded into the memory comprises:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向后检索,直至检索到所述第一字符串或者检索至所述第一文件块的末位置。Searching backward from the current cursor position until the first character string is retrieved or retrieved to the last position of the first file block.
  4. 根据权利要求3所述的方法,其特征在于,所述如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串或遍历整个文件为止包括:The method according to claim 3, wherein if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately and the first character string is retrieved until retrieval To include the first string or traverse the entire file:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged after the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之后的其它文件块均未检索出所述第一字符串,则从所述文件的第一个文件块至所述第一文件块的上一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks that are arranged after the first file block, then from the first file block of the file to the previous file block of the first file block, respectively Entering the memory and retrieving the first string until the first string is retrieved;
    如果所述文件的第一个文件块至第一文件块的上一个文件块均未检索出所述第一字符串,则从所述第一文件块的首位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。Retrieving from the first position of the first file block to the current cursor position if the first file string of the file does not retrieve the first character string from the previous file block of the first file block The first character string until the first character string is retrieved.
  5. 根据权利要求1所述的方法,其特征在于,所述字符串检索顺序为从后向前检索;The method of claim 1 wherein said string retrieval order is retrieved from back to front;
    所述在已载入内存的第一文件块中检索所述第一字符串包括:The retrieving the first string in the first file block that has been loaded into the memory comprises:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向前检索,直至检索到所述第一字符串或者检索至所述第一文件块的首位置。Searching forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block.
  6. 根据权利要求5所述的方法,其特征在于,所述如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串或遍历整个文件为止包括:The method according to claim 5, wherein if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory separately and the first character string is retrieved until retrieval To include the first string or traverse the entire file:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged before the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之前的其它文件块均未检索出所述第一字符串,则从所述文件的最后一个文件块至所述第一文件块的下一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks preceding the first file block, the last file block from the file to the next file block of the first file block are sequentially loaded separately Memory and retrieving the first string until the first string is retrieved;
    如果所述文件的最后一个文件块至所述第一文件块的下一个文件块均未检索出所述第一字符串,则从所述第一文件块的末位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。If the first file string of the file to the next file block of the first file block does not retrieve the first character string, proceed from the last position of the first file block to the current cursor position Retrieving the first character string until the first character string is retrieved.
  7. 一种字符串检索装置,其中,所述检索装置用于在被划分为多个文件块的文件中进行字符串检索,所述检索装置包括:A character string retrieval device, wherein the retrieval device is configured to perform a character string retrieval in a file divided into a plurality of file blocks, the retrieval device comprising:
    接收模块,用于接收字符串检索请求,所述检索请求包括待检索的第一字符串;a receiving module, configured to receive a string retrieval request, where the retrieval request includes a first character string to be retrieved;
    第一检索模块,与所述接收模块连接,用于在已载入内存的第一文件块中检索所述第一字符串;a first retrieval module, connected to the receiving module, configured to retrieve the first character string in a first file block that has been loaded into the memory;
    第二检索模块,与所述第一检索模块连接,用于如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串或遍历整个文件为止。a second retrieval module, coupled to the first retrieval module, configured to: if the first character string is not retrieved in the first file block, load the other file blocks into the memory separately and retrieve the first character string until Retrieve the first string or traverse the entire file.
  8. 根据权利要求7所述的检索装置,其中,所述检索装置还包括跳转模块,所述跳转模块用于,当检索到所述第一字符串时,将光标移动到检索到的所述第一字符串上并终止检索。The retrieval device according to claim 7, wherein said retrieval means further comprises a jump module, said jump module for moving the cursor to said retrieved when said first character string is retrieved The first string is over and the search is terminated.
  9. 根据权利要求7所述的检索装置,其中,所述字符串检索顺序为从前向后检索;The retrieval device according to claim 7, wherein said character string retrieval order is a front-to-back retrieval;
    其中,所述第一检索模块用于:Wherein the first retrieval module is configured to:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向后检索,直至检索到所述第一字符串或者检索至所述第一文件块的末位置。Searching backward from the current cursor position until the first character string is retrieved or retrieved to the last position of the first file block.
  10. 根据权利要求9所述的检索装置,其中,所述第二检索模块用于:The retrieval device according to claim 9, wherein said second retrieval module is configured to:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged after the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之后的其它文件块均未检索出所述第一字符串,则从所述文件的第一个文件块至所述第一文件块的上一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks that are arranged after the first file block, then from the first file block of the file to the previous file block of the first file block, respectively Entering the memory and retrieving the first string until the first string is retrieved;
    如果所述文件的第一个文件块至第一文件块的上一个文件块均未检索出所述第一字符串,则从所述第一文件块的首位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。Retrieving from the first position of the first file block to the current cursor position if the first file string of the file does not retrieve the first character string from the previous file block of the first file block The first character string until the first character string is retrieved.
  11. 根据权利要求7所述的检索装置,其中,所述字符串检索顺序为从后向前检索;The retrieval device according to claim 7, wherein said character string retrieval order is retrieved from back to front;
    其中,所述第一检索模块用于:Wherein the first retrieval module is configured to:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向前检索,直至检索到所述第一字符串或者检索至所述第一文件块的首位置。Searching forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block.
  12. 根据权利要求11所述的检索装置,其中,所述第二检索模块用于:The retrieval device of claim 11 wherein said second retrieval module is for:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged before the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之前的其它文件块均未检索出所述第一字符串,则从所述文件的最后一个文件块至所述第一文件块的下一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks preceding the first file block, the last file block from the file to the next file block of the first file block are sequentially loaded separately Memory and retrieving the first string until the first string is retrieved;
    如果所述文件的最后一个文件块至所述第一文件块的下一个文件块均未检索出所述第一字符串,则从所述第一文件块的末位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。If the first file string of the file to the next file block of the first file block does not retrieve the first character string, proceed from the last position of the first file block to the current cursor position Retrieving the first character string until the first character string is retrieved.
  13. 一种字符串检索装置,其中,所述检索装置用于在被划分为多个文件块的文件中进行字符串检索,所述检索装置包括:收发器、存储器、处理器以及数据总线,所述收发器、所述存储器以及所述处理器通过数据总线相连,以进行相互通信;A character string retrieval device, wherein the retrieval device is configured to perform a character string retrieval in a file divided into a plurality of file blocks, the retrieval device comprising: a transceiver, a memory, a processor, and a data bus, a transceiver, the memory, and the processor are connected by a data bus to communicate with each other;
    所述收发器用于接收字符串检索请求,所述检索请求包括待检索的第一字符串;所述存储器用于存储所述文件;The transceiver is configured to receive a string retrieval request, the retrieval request includes a first character string to be retrieved, and the memory is configured to store the file;
    所述处理器用于在已载入内存的第一文件块中检索所述第一字符串;如果在第一文件块中未检索到第一字符串,将其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串或遍历整个文件为止。The processor is configured to retrieve the first character string in a first file block that has been loaded into the memory; if the first character string is not retrieved in the first file block, the other file blocks are sequentially loaded into the memory and retrieved The first string until the first string is retrieved or the entire file is traversed.
  14. 根据权利要求13所述的检索装置,其中,所述处理器还用于:The retrieval device of claim 13, wherein the processor is further configured to:
    当检索到所述第一字符串时,将光标移动到检索到的所述第一字符串上并终止检索。When the first character string is retrieved, the cursor is moved to the retrieved first character string and the retrieval is terminated.
  15. 根据权利要求13所述的检索装置,其中,所述字符串检索顺序为从前向后检索;The retrieval device according to claim 13, wherein said character string retrieval order is a front-to-back retrieval;
    其中,所述处理器用于:Wherein the processor is used to:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向后检索,直至检索到所述第一字符串或者检索至所述第一文件块的末位置。Searching backward from the current cursor position until the first character string is retrieved or retrieved to the last position of the first file block.
  16. 根据权利要求15所述的检索装置,其中,所述处理器用于:The retrieval device of claim 15 wherein said processor is operative to:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之后的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged after the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之后的其它文件块均未检索出所述第一字符串,则从所述文件的第一个文件块至所述第一文件块的上一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks that are arranged after the first file block, then from the first file block of the file to the previous file block of the first file block, respectively Entering the memory and retrieving the first string until the first string is retrieved;
    如果所述文件的第一个文件块至第一文件块的上一个文件块均未检索出所述第一字符串,则从所述第一文件块的首位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。Retrieving from the first position of the first file block to the current cursor position if the first file string of the file does not retrieve the first character string from the previous file block of the first file block The first character string until the first character string is retrieved.
  17. 根据权利要求13所述的检索装置,其中,所述字符串检索顺序为从后向前检索;The retrieval device according to claim 13, wherein said character string retrieval order is retrieved from back to front;
    其中,所述处理器用于:Wherein the processor is used to:
    记录下当前光标位置;Record the current cursor position;
    从所述当前光标位置开始向前检索,直至检索到所述第一字符串或者检索至所述第一文件块的首位置。Searching forward from the current cursor position until the first character string is retrieved or retrieved to the first position of the first file block.
  18. 根据权利要求17所述的检索装置,其中,所述处理器用于:The retrieval device of claim 17, wherein the processor is configured to:
    如果在第一文件块中未检索到第一字符串,将排在第一文件块之前的其它文件块依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved in the first file block, the other file blocks arranged before the first file block are sequentially loaded into the memory and retrieved, respectively, until the first character string is retrieved. until;
    如果排在第一文件块之前的其它文件块均未检索出所述第一字符串,则从所述文件的最后一个文件块至所述第一文件块的下一个文件块,依次单独载入内存并检索所述第一字符串,直至检索到所述第一字符串为止;If the first character string is not retrieved by other file blocks preceding the first file block, the last file block from the file to the next file block of the first file block are sequentially loaded separately Memory and retrieving the first string until the first string is retrieved;
    如果所述文件的最后一个文件块至所述第一文件块的下一个文件块均未检索出所述第一字符串,则从所述第一文件块的末位置至所述当前光标位置进行检索所述第一字符串,直至检索到所述第一字符串为止。If the first file string of the file to the next file block of the first file block does not retrieve the first character string, proceed from the last position of the first file block to the current cursor position Retrieving the first character string until the first character string is retrieved.
PCT/CN2015/099960 2015-12-30 2015-12-30 String search method and device WO2017113230A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201580079772.1A CN107615271A (en) 2015-12-30 2015-12-30 Character string retrieving method and device
PCT/CN2015/099960 WO2017113230A1 (en) 2015-12-30 2015-12-30 String search method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2015/099960 WO2017113230A1 (en) 2015-12-30 2015-12-30 String search method and device

Publications (1)

Publication Number Publication Date
WO2017113230A1 true WO2017113230A1 (en) 2017-07-06

Family

ID=59224072

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/099960 WO2017113230A1 (en) 2015-12-30 2015-12-30 String search method and device

Country Status (2)

Country Link
CN (1) CN107615271A (en)
WO (1) WO2017113230A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101369267A (en) * 2007-08-15 2009-02-18 中兴通讯股份有限公司 Fuzzy query method based on internal memory warehouse
CN101763408A (en) * 2009-11-19 2010-06-30 青岛海信移动通信技术股份有限公司 Method for decoding txt file and device thereof, as well as electronic product comprising device
CN101763407A (en) * 2009-11-19 2010-06-30 青岛海信移动通信技术股份有限公司 Txt file reading method based on brew platform and reader thereof
CN102467543A (en) * 2010-11-15 2012-05-23 福州星网视易信息系统有限公司 Method and system for searching file in VOD (Video-On-Demand) music query system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957839A (en) * 2010-09-15 2011-01-26 苏州恩巨网络有限公司 Map file format
CN104123280B (en) * 2013-04-24 2017-08-25 中国银联股份有限公司 File comparison method and equipment
CN103544281A (en) * 2013-10-23 2014-01-29 中安消技术有限公司 Method, device and system for retrieving keywords

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101369267A (en) * 2007-08-15 2009-02-18 中兴通讯股份有限公司 Fuzzy query method based on internal memory warehouse
CN101763408A (en) * 2009-11-19 2010-06-30 青岛海信移动通信技术股份有限公司 Method for decoding txt file and device thereof, as well as electronic product comprising device
CN101763407A (en) * 2009-11-19 2010-06-30 青岛海信移动通信技术股份有限公司 Txt file reading method based on brew platform and reader thereof
CN102467543A (en) * 2010-11-15 2012-05-23 福州星网视易信息系统有限公司 Method and system for searching file in VOD (Video-On-Demand) music query system

Also Published As

Publication number Publication date
CN107615271A (en) 2018-01-19

Similar Documents

Publication Publication Date Title
WO2013174172A1 (en) File information previewing method and system
WO2012155709A1 (en) A method, system and storage medium for pushing user's personal label dynamically
WO2018036329A1 (en) Clipboard control method and system based on mobile terminal
WO2010123168A1 (en) Database management method and system
WO2018214320A1 (en) Database service logic monitoring method and system, and storage medium
SE515459C2 (en) Method for synchronizing a host database and a remote database
WO2010005261A2 (en) File generation and search methods for data search, and database management system for data file search
WO2018076865A1 (en) Data sharing method, device, storage medium, and electronic device
WO2016101441A1 (en) File synchronization method and system
WO2013174210A1 (en) Data storage method and device in flash memory device
WO2014044130A1 (en) Service polling method and system, and computer storage medium
WO2021051492A1 (en) Database service node switching method, apparatus and device, and computer storage medium
WO2015180434A1 (en) Data management method, node and system for database cluster
WO2020062640A1 (en) Method, server and storage medium for switching dynamic copywriting language of terminal application
WO2018090535A1 (en) Method and device for processing accumulative retrieval, terminal and storage medium
WO2012159436A1 (en) Method and device for adjusting disk partitions in windows
WO2017113230A1 (en) String search method and device
WO2018182060A1 (en) Method for storing and searching text log data on basis of relational database
WO2016023509A1 (en) File display method and file display device
WO2021012487A1 (en) Cross-system information synchronisation method, user device, storage medium, and apparatus
WO2021187682A1 (en) Owl-horst ontology reasoning method and apparatus using distributed table structure in cloud computing environment
WO2016180218A1 (en) Method for generating track line vertex sequence, terminal and server
JPH0561758A (en) Information link device
WO2024019224A1 (en) Method for processing structured data and unstructured data in database, and data processing platform for providing method
WO2015096139A1 (en) Method and equipment for character processing

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15911859

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15911859

Country of ref document: EP

Kind code of ref document: A1