Text search method and device, electronic equipment and storage medium

By monitoring text content changes and updating the search result cache stack, the performance loss problem caused by full search in the real-time update editor is solved, and a fast response and efficient text search experience is achieved.

CN119862267APending Publication Date: 2025-04-22ANHUI IFLYREC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411808625.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-10
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

In the prior art, the new generation of real-time update editor needs to traverse the entire document when looking for search results for updated paragraphs, resulting in performance loss and slow response, affecting the user experience.

Method used

By monitoring the changes in text content, determine the modified text and its location, search based on the text structure of the modified text, obtain the search results, and update the search result cache stack.

Benefits of technology

Real-time search updates are realized, avoiding the performance loss caused by full search, and significantly improving page performance and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862267A_ABST
    Figure CN119862267A_ABST
Patent Text Reader

Abstract

The invention provides a text search method and device, electronic equipment and a storage medium, and the method comprises the steps: determining a modified text and the position of the modified text under the condition that the change of text content is monitored; searching the modified text based on the text structure of the modified text to obtain a search result of the modified text; and updating a search result cache stack based on the position of the modified text and the search result, the search result cache stack being created based on the initial search result of the text content. According to the text search method and device, the electronic equipment and the storage medium provided by the invention, by monitoring the text content, re-search can be automatically triggered every time the content changes. No matter when a user edits, the system can immediately capture the changes and start real-time search, and the real-time search updating mechanism greatly improves the user experience and the working efficiency, especially in a text processing scene needing frequent editing and searching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a text search method, device, electronic device and storage medium. Background Art

[0002] As an important tool for information processing and creation, text editors play a vital role in clients or browsers. These editors not only allow users to set basic styles for text content, such as font, color, bold, etc., but also support complex editing operations such as adding new content and deleting redundant content, greatly improving the user's creation efficiency and flexibility.

[0003] The new generation editor adds a partial rendering function to ensure smooth operation when working with large amounts of text. The text editor returns updated paragraph information, but when searching for search results for updated paragraphs, you need to traverse the entire document to find the target content, which increases page performance loss and causes performance issues. The slow response to search content affects the user experience. Summary of the invention

[0004] The present invention provides a text search method, device, electronic device and storage medium, which are used to solve the defect in the prior art that a new generation of real-time update editors require full search, resulting in performance loss.

[0005] The present invention provides a text search method, comprising: When a change in the text content is detected, determining the modified text and the position of the modified text; Based on the text structure of the modified text, searching the modified text to obtain search results of the modified text; Based on the position of the modified text and the search results, a search result cache stack is updated, wherein the search result cache stack is created based on the initial search results of the text content.

[0006] According to the text search method provided by the present invention, the data structure hierarchy of the search result cache stack includes paragraphs, nodes and search selections, and updating the search result cache stack based on the position of the modified text and the search results includes: Based on the paragraph position of the modified text, the search result and the modification type, the search selection area corresponding to the paragraph position in the search result cache stack is updated.

[0007] According to the text search method provided by the present invention, after updating the search result cache stack based on the position of the modified text and the search result, the method further includes: Combining the search selections of each paragraph in the search result cache stack into an array structure, and marking the updated search selections; Data rendering is performed based on the updated search selection.

[0008] According to the text search method provided by the present invention, the data structure description of the search selection includes the start position and the end position of the search selection, and the unique identifier of the search selection, and the unique identifier is determined based on the paragraph index and the search result index.

[0009] According to the text search method provided by the present invention, the text structure includes paragraphs and nodes, and the text structure based on the modified text is used to search for the modified text to obtain search results of the modified text, including: Search the paragraph contents of each paragraph in the modified text to obtain the search position of the search results in each paragraph; Traversing the node content of each node in each paragraph to obtain the node position of the node content in each paragraph; The search position of the search result and the node position of the node content are compared to obtain the search result of the modified text.

[0010] According to the text search method provided by the present invention, the step of comparing the search position of the search result with the node position of the node content to obtain the search result of the modified text includes: Comparing the start position and the end position in the search position, and the start position and the end position in the node position, to obtain a comparison result; Based on the comparison result and the length of the node content, the start position and the end position of the search selection area corresponding to the search result are determined.

[0011] According to the text search method provided by the present invention, the updating of the search result cache stack based on the position of the modified text and the search result includes: Based on the position of the modified text and the search results, the search result cache stack and the search result corresponding stack are updated, and the data structure hierarchy of the search result corresponding stack includes paragraphs, unique identifiers of search selections, and search selections.

[0012] The present invention also provides a text search device, comprising: A text determination unit, configured to determine the modified text and the position of the modified text when a change in the text content is detected; A search unit, configured to search the modified text based on the text structure of the modified text to obtain search results of the modified text; An updating unit is used to update a search result cache stack based on the position of the modified text and the search result, wherein the search result cache stack is created based on the initial search result of the text content.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned text search methods when executing the computer program.

[0014] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the text search method described in any one of the above is implemented.

[0015] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned text search methods.

[0016] The text search method, device, electronic device and storage medium provided by the present invention automatically trigger a re-search each time the content changes by monitoring the text content. This means that no matter when the user makes an edit, the system can immediately capture these changes and start a real-time search. This real-time search update mechanism greatly improves the user experience and work efficiency, especially in text processing scenarios that require frequent editing and searching. In addition, by directly locating the location of the modified text that has changed, it is only necessary to search for the modified text and update the search result cache stack to obtain the location of the matching item in the entire text. Compared with traversing the entire document for a full search, it avoids the performance loss caused by a full search, can significantly improve page performance, make the search content respond quickly, and greatly enhance the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 This is one of the flow charts of the text search method provided by the present invention.

[0019] Figure 2 It is a schematic diagram of the modified text provided by the present invention.

[0020] Figure 3 This is the second flow chart of the text search method provided by the present invention.

[0021] Figure 4 It is a flowchart of step 120 in the text search method provided by the present invention.

[0022] Figure 5It is a structural schematic diagram of the text search device provided by the present invention.

[0023] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0025] Traditional text search technology usually follows a one-time search mode, that is, after the user enters the search keyword, the system will search for the part that matches the keyword in the entire text content. In this process, the system will first traverse the entire text, determine the specific location of the matching item through the content comparison algorithm, and then map this location information to the corresponding element node. Once a match is found, the system will render the search results into these element nodes in a highlighted or other visual form so that users can intuitively see the search results.

[0026] However, the one-time search mode has certain limitations when dealing with dynamically changing text content. When users continue to edit text after completing a search, traditional search technology does not automatically update the search results. This means that if the user wants to see whether the edited text still contains the previous search keywords, or whether new matches have appeared, the user needs to manually re-execute the search function, and the search process will restart from the beginning of the text. This non-real-time search update mechanism is particularly inconvenient in scenarios where large amounts of text are processed or frequent editing is required, because it increases the user's operational burden and reduces work efficiency.

[0027] In view of the above problems, an embodiment of the present invention proposes a text search method, which supports real-time search and update text editing technology. In this method, when a change in text content is detected, the modified text and the position of the modified text are determined; based on the text structure of the modified text, the modified text is searched to obtain the search results of the modified text; based on the position of the modified text and the search results, the search result cache stack is updated, and the search result cache stack is created based on the initial search results of the text content.

[0028] By monitoring the text content, a new search is automatically triggered every time the content changes. This means that no matter when the user makes an edit, the system can immediately capture these changes and start a real-time search. This real-time search update mechanism greatly improves user experience and work efficiency, especially in text processing scenarios that require frequent editing and searching.

[0029] In addition, this embodiment can directly locate the position of the modified text that has changed. It only needs to search the modified text and update the search result cache stack to obtain the position of the matching item in the entire text. Compared with traversing the entire document for a full search, it avoids the performance loss caused by the full search, can significantly improve page performance, make the search content respond quickly, and greatly enhance the user experience.

[0030] The embodiments of the present invention can be applied to scenarios where text search is required, such as a new generation of real-time update editor scenarios. The execution subject of the method can be an electronic device such as a terminal device, a computer, a server, a server cluster, or a specially designed text search device, or a text search device set in the electronic device, and the text search device can be implemented by software, hardware, or a combination of the two.

[0031] Figure 1 It is one of the flowcharts of the text search method provided by the present invention, such as Figure 1 As shown, the method comprises the following steps: Step 110, when a change in the text content is detected, determine the modified text and the location of the modified text.

[0032] Specifically, this embodiment describes the text search method by taking a text editor as an example. Here, the text is the text from which the target content needs to be searched, and the text can be the entire document in the text editor or one or more text fragments therein, which is not specifically limited in the embodiment of the present invention.

[0033] The text editor will continue to monitor changes in the text content entered by the user. This includes new text added by the user, old text deleted, or any modifications to existing text, such as changes caused by deletion, modification, pasting, style modification, segmentation, etc.

[0034] Once a change in the text content is detected, the editor will analyze the changed content, determine which text has changed, and record the specific location of the changed text in the original text. The text content can be compared character by character or word by word to accurately identify the changed part. The new generation of real-time update editors can return the changed text in real time.

[0035] Here, the modified text refers to the text that may affect the change of the search results. The modified text can be the sentence where the changed text is located, or the paragraph where it is located, or the upper and lower paragraphs of the paragraph where it is located. The embodiment of the present invention does not make specific limitations on this.

[0036] The position of the modified text refers to the position of the modified text in the text after the content is changed, for example, it can be represented by specific paragraph information.

[0037] For example, the user enters a character in the third node in the first paragraph. After the input is completed, only the third node in the first paragraph changes. At this time, the content in the first paragraph is used as the modified text, and the location of the modified text is the first paragraph.

[0038] For another example, when the user performs a line break operation in the first paragraph, the first and second paragraphs are updated. The contents of the first and second paragraphs can be used as modified texts, and the positions of the modified texts correspond to the first and second paragraphs respectively.

[0039] Step 120 , based on the text structure of the modified text, search for the modified text to obtain search results for the modified text.

[0040] Specifically, after obtaining the modified text, the editor will use an efficient search algorithm to search the modified text. During the search process, the text structure of the modified text, such as words, sentences, paragraphs, etc., will be fully considered to improve the accuracy and efficiency of the search. Through the search, the editor can find search results that match the target content. The search results may include specific words, phrases, or entire paragraphs in the text.

[0041] Step 130, based on the position of the modified text and the search results, update the search result cache stack, which is created based on the initial search results.

[0042] After obtaining the search results of the modified text, the editor will update the search results cache stack based on these results and the location of the modified text. The search results cache stack is created when the user searches for the first time, that is, when the user enters the search criteria for the first search, the search results cache stack is created based on the first search results. In each subsequent search process, the search results are automatically updated after they are obtained. The search results cache stack is used to store and manage search results.

[0043] The update of the search result cache stack can be achieved by modifying the position of the text and the search results, for example, only updating the search result cache stack corresponding to the position of the modified text. If the modified text is in the second section, then the search results of the second section in the cache stack are modified accordingly.

[0044] It should be noted that, in this embodiment, the target content to be searched may be input by the user during the initial search. When the target content remains unchanged, the target content does not need to be input again during subsequent searches.

[0045] The method provided by the embodiment of the present invention automatically triggers a new search each time the content changes by monitoring the text content. This means that no matter when the user edits, the system can immediately capture these changes and start real-time search. This real-time search update mechanism greatly improves user experience and work efficiency, especially in text processing scenarios that require frequent editing and searching.

[0046] In addition, this embodiment can directly locate the position of the modified text that has changed. It only needs to search the modified text and update the search result cache stack to obtain the position of the matching item in the entire text. Compared with traversing the entire document for a full search, it avoids the performance loss caused by the full search, can significantly improve page performance, make the search content respond quickly, and greatly enhance the user experience.

[0047] Based on any of the above embodiments, the data structure level of the search result cache stack includes paragraphs, nodes and search selections. In step 130, based on the position of the modified text and the search results, the search result cache stack is updated, which specifically includes: Step 131, based on the paragraph position of the modified text, the search result and the modification type, update the search selection corresponding to the paragraph position in the search result cache stack.

[0048] Specifically, the data structure of the search result cache stack includes three levels: paragraph, node, and search selection, so as to efficiently manage and update search results. Specifically, it can be expressed as: paragraph--node--[search selection, search selection].

[0049] Here, a node usually refers to the basic unit or element that makes up a paragraph. Each node can contain specific text content or formatting information and can be associated with other nodes in the document structure. A node can contain actual text characters, which can be normal text or formatted text (such as bold, italic, underlined, etc.).

[0050] Each node can contain formatting information about its text content. For example, a bold node would contain information indicating that its text should be bold, and a strikethrough node would contain information indicating that its text should be struck through. Figure 2 It is a schematic diagram of the modified text provided by the present invention, such as Figure 2 As shown, a paragraph may contain multiple different independent nodes, which can be text nodes, bold nodes, strikethrough nodes, etc.

[0051] The update of the search result cache stack is achieved by updating the search selection corresponding to the paragraph position in the search result cache stack based on the paragraph position of the modified text, the search result and the modification type.

[0052] After detecting a change in the text content and determining to modify the text, the editor will first determine the paragraph position where the modified text is located.

[0053] The editor will analyze the search results corresponding to the modified text, including the specific content, location, and number of search results. At the same time, the editor will also determine the type of modification, such as addition, deletion, or replacement.

[0054] Then, the editor will locate the search selection corresponding to the paragraph position in the search result cache stack. If the modification type is add or replace, the editor will add or update the corresponding search results in the search selection. For example, the new search results will be inserted into the correct position and the content, position and other properties of the search results will be updated.

[0055] If the modification type is deletion, the editor will delete the search selection at the paragraph position corresponding to the modified text from the search result cache stack.

[0056] For example, the user enters a character in the third node in the first paragraph. After the input is completed, only the third node in the first paragraph changes. At this time, the content in the first paragraph is searched, and the search selection corresponding to the first paragraph in the search result cache stack is updated.

[0057] When the user performs a line break operation in the first paragraph, the first paragraph and the second paragraph are updated. At this time, the first paragraph and the second paragraph are searched respectively, and the search selections corresponding to the first paragraph and the second paragraph in the search result cache stack are updated.

[0058] When the user deletes the second section of content, the search selection corresponding to the second section in the search result cache stack is deleted.

[0059] The method provided in the embodiment of the present invention updates the search selection corresponding to the paragraph position in the search result cache stack based on the paragraph position of the modified text, the search results and the modification type, and only performs real-time search on the modified content. It adds a search result cache stack mechanism to prevent excessive search from wasting machine performance, and can further improve the efficiency and accuracy of text search.

[0060] Based on any of the above embodiments, Figure 3 This is the second flow chart of the text search method provided by the present invention. Figure 3 As shown, after updating the search result cache stack based on the position of the modified text and the search results, the method further includes: Step 140, combining the search selections of each paragraph in the search result cache stack into an array structure, and marking the updated search selections; Step 150: Render data based on the updated search area.

[0061] Specifically, the search selection areas in all paragraphs in the search result cache stack are traversed in a loop. The search selection area information of each paragraph may include the starting position and the ending position of the search word in the paragraph.

[0062] First, an array element may be created for each paragraph, which contains the text content of the paragraph and all relevant search selection information. The search selection information may be an object or a structure, which records the search term, the starting position, the ending position, and the like.

[0063] In the process of constructing the array structure, the search selection that is updated due to text modification is specially marked. This can be achieved by adding an "updated" flag to the search selection information, or using other methods (such as color coding, special markers, etc.) to distinguish between the old and new search selections, such as the "updated search selection" in the above data structure.

[0064] Integrate the array elements of all paragraphs into a larger array structure, that is, combine the search selections of all paragraphs into an ordered search result array structure. This array structure can be represented as: [search selection, search selection, update search selection, search selection]. This structure will be used as input for subsequent data rendering.

[0065] In step 150, the constructed array structure is read to parse each paragraph and the search selection information related thereto. When the system re-renders the selection data, if the search selection is not updated, the historical search results are retained; if the search selection is updated, the system re-renders according to the new selection.

[0066] For search selections marked as "updated", use a special highlighting style (such as a different background color, font color, or border) to display. This helps users quickly identify which search results are updated based on the latest text modifications. For search selections not marked as "updated", you can use the default rendering style to display. This ensures consistency in the user interface while avoiding excessive processing of unmodified content.

[0067] The method provided by the embodiment of the present invention adds an independent identifier to the updated selection area, and re-renders the interface according to the updated search results when rendering the search results, thereby preventing performance problems caused by rendering the full amount of search results.

[0068] Based on any of the above embodiments, the data structure description of the search selection includes the start position and the end position of the search selection, and a unique identifier of the search selection, and the unique identifier is determined based on the paragraph index and the search result index.

[0069] Specifically, the data structure of the search selection can be defined as a structure or class containing the following fields: Start Position: Indicates the starting point of the search selection in the document or string.

[0070] End Position: Same as the start position type, indicating the end point of the search selection in the document or string.

[0071] Unique Identifier (UID): A unique identifier generated based on the paragraph index and search result index to distinguish different search selections. The unique identifier should be generated in a way that ensures that each search selection can obtain a unique identifier in multiple searches of documents or strings.

[0072] First, get the paragraph index: traverse the document or string, divide the content into paragraphs, and assign a unique paragraph index to each paragraph. For example, the paragraph index can be incremented from 0, or assigned according to other rules.

[0073] Get search result index: Search in each paragraph, record the position of each search result in the paragraph, and assign a unique search result index to each search result based on the position of the search result. The search result index can also be incremented from 0 or assigned according to other rules.

[0074] Combine to generate a unique identifier: Combine the paragraph index and search result index to generate a unique identifier. The combination can be a simple string concatenation or a more complex encoding method. For example, the paragraph index and search result index can be converted into strings and then concatenated using a specific separator (such as "-" or "_"). For example, a unique identifier = paragraph index + search result index can represent the nth search result in the nth paragraph.

[0075] Based on any of the above embodiments, the text structure includes paragraphs and nodes. Figure 4 is a flow chart of step 120 in the text search method provided by the present invention, such as Figure 4 As shown, based on the text structure of the modified text, the modified text is searched to obtain the search results of the modified text, that is, step 120 specifically includes: Step 121, searching for the paragraph content of each paragraph in the modified text, and obtaining the search position of the search result in each paragraph; Step 122, traverse the node content of each node in each paragraph to obtain the node position of the node content in each paragraph; Step 123, comparing the search position of the search result with the node position of the node content to obtain the search result of the modified text.

[0076] Specifically, the search for the modified text in this embodiment is based on paragraphs. First, the modified text is parsed into multiple paragraphs, each of which can be regarded as an independent unit in the text, including a part of the content of the text.

[0077] Perform a search operation in each paragraph content, which can be implemented through text matching algorithms, such as string matching, regular expression matching, etc., to find the position of the search keyword or phrase in the paragraph. For each match found, record its search position in the paragraph. The search position here can include the starting position and the ending position, or only the starting position, depending on specific needs.

[0078] In each paragraph, further parse its internal structure, such as sentences, phrases, words, etc., which can be regarded as nodes. A node can be any element in the text, depending on the granularity of text parsing. For each node, record its position in the paragraph, that is, the node position, which can include, for example, the start position and end position of the node.

[0079] The search position of the search result is compared with the node position of each node to determine whether the search result is associated with the specific node content in the text. A node may contain multiple search results, or a search result may contain multiple nodes.

[0080] By comparison, the search results of modified text have the following situations: there is no search content in the node, the search content includes all the content of the node, only the first half of the node is searched, the search content is in the node, and the second half of the node is searched.

[0081] The method provided by the embodiment of the present invention solves the cross-node search problem by using a text position calculation method. The method can more accurately reflect the position and content of the search results in the text, thereby improving the accuracy and practicality of the search.

[0082] Based on any of the above embodiments, the search position of the search result and the node position of the node content are compared to obtain the search result of the modified text, that is, step 123 specifically includes: Step 123-1, comparing the start position and the end position in the search position, and the start position and the end position in the node position, to obtain a comparison result; Step 123-2, based on the comparison result and the length of the node content, determine the start position and end position of the search selection area corresponding to the search result.

[0083] Specifically, the plain text in the paragraph is used for retrieval to determine whether the plain text contains search results. If so, the search position of the search results in the plain text is recorded, and the start position (searchStart) and end position (searchEnd) of the search position are extracted.

[0084] Traverse all nodes in the paragraph, calculate the node position of the content in the node in the paragraph, and extract the start position (nodeStart) and end position (nodeEnd) of the node position. The length of the node content is: nodeLen. Compare with the search result position, the comparison results are as follows: a. There is no search content in the node. That is, the end position of the node is less than the start position of the search content, which is represented by nodeEnd <searchStart。

[0085] b. The search content includes the entire content of the node. That is, the start position of the node is greater than or equal to the start position of the search content, and the end position of the node is less than or equal to the end position of the search content, which is expressed as nodeStart>=searchStart&&nodeEnd<=searchEnd.

[0086] At this time, the data of the search area corresponding to the search result is: starting position: 0, ending position: nodeLen.

[0087] c. Only the first half of the node is searched, that is, the start position of the search content is less than the start position of the node, and the end position of the search content is greater than the start position of the node, and the end position of the search content is less than or equal to the end position of the node. Expressed as: searchStart<nodeStart&&searchEnd> nodeStart&&searchEnd<=nodeEnd.

[0088] At this time, the data of the search area corresponding to the search results are: starting position: 0, ending position: searchEnd –nodeStart.

[0089] d. The search content is in the node, that is, the start position of the search content is greater than or equal to the start position of the node, and the end position of the search content is less than or equal to the end position of the node. It is expressed as: searchStart>= nodeStart&&searchEnd<= nodeEnd.

[0090] At this time, the data of the search area corresponding to the search results are: starting position: searchStart - nodeStart, ending position: searchEnd - nodeStart.

[0091] e. The second half of the node is searched, that is, the end position of the search content is greater than the end position of the node, and the start position of the search content is less than the end content of the node, expressed as: searchEnd>nodeEnd&&searchStart <nodeEnd。

[0092] At this time, the data of the search area corresponding to the search result is: starting position: searchStart - nodeStart, ending position: nodeLe.

[0093] The method provided by the embodiment of the present invention solves the cross-node search problem by calculating the text position.

[0094] Based on any of the above embodiments, updating the search result cache stack based on the position of the modified text and the search result includes: Based on the position of the modified text and the search results, the search result cache stack and the search result corresponding stack are updated. The data structure hierarchy of the search result corresponding stack includes paragraphs, unique identifiers of search selections, and search selections.

[0095] Specifically, after obtaining the search result of the current modified text, not only can the search result cache stack be updated based on the position of the modified text and the search result, but also the search result corresponding stack can be updated.

[0096] Here, the search result corresponding stack is used to store the corresponding relationship between the search results and the specific positions in the text, and is used to quickly locate the corresponding search area according to the searched target results during replacement, thereby realizing content replacement.

[0097] Each element in the stack corresponding to the search result may be a more complex data structure, including the following levels: paragraph--search selection unique identifier--[search selection, search selection].

[0098] The paragraph refers to the paragraph identifier in the text, which can be a paragraph number or a hash value of the paragraph content.

[0099] The unique identifier of the search selection is used to uniquely identify the position of the search result in the text. The search selection is the actual searched text segment, which may include highlighted keywords, etc.

[0100] In the method provided by the embodiment of the present invention, the existence of the search result cache stack and the search result corresponding stack is conducive to counting the full amount of search results in the local update editor, and facilitates the subsequent counting, positioning and search replacement of the search quantity.

[0101] Based on any of the above embodiments, a text search method is provided, including: S1, create a search result cache stack and a search result corresponding stack according to the initial search results. The search result cache stack is used to cache the search results to reduce the matching range of the search when the content is changed next time; the search result corresponding stack is used to quickly locate the corresponding search area according to the searched target results when replacing, so as to achieve content replacement.

[0102] The data structure hierarchy of the search result cache stack is: paragraph--node--[search selection, search selection]. The data structure hierarchy of the search result corresponding stack is: paragraph--search selection unique identifier--[search selection, search selection]. The data structure description of the search selection is: {start position, end position, search selection unique identifier}. Unique identifier = paragraph index + search result index.

[0103] S2, when a change in the text content is detected, determining to modify the text and the location of the modified text.

[0104] S3, based on the text structure of the modified text, search for the modified text and obtain search results of the modified text. Specifically including: Search and modify the paragraph contents of each paragraph in the text to obtain the search position of the search results in each paragraph; traverse the node contents of each node in each paragraph to obtain the node positions of the node contents in each paragraph; compare the start position and the end position in the search position, and the start position and the end position in the node position to obtain the comparison result; based on the comparison result and the length of the node content, determine the start position and the end position of the search selection corresponding to the search result.

[0105] S4, based on the paragraph position of the modified text, the search result and the modification type, update the search selection corresponding to the paragraph position in the search result cache stack, and update the search result corresponding stack.

[0106] S5, combining the search selections of each paragraph in the search result cache stack into an array structure, and marking the updated search selections; and rendering data based on the updated search selections.

[0107] The method provided by the embodiment of the present invention caches the search results of paragraphs in the system during the initial search, and does not need to search the entire content during real-time updates; the search result cache stack uses the paragraph node as the key value, and quickly searches for the corresponding search result stack when the paragraph is updated; an independent identifier is added to the updated selection, which facilitates the system to quickly update the latest search results to the selection; the existence of the search result cache stack is conducive to counting the full amount of search results in the local update editor, and facilitates the subsequent statistics, positioning and search replacement of the number of searches. This embodiment optimizes the full-text flush search of local updates to a real-time search only for updated content, adds a search result cache stack mechanism, and prevents excessive searches from wasting machine performance; at the same time, the cross-node search problem is solved by calculating the text position during retrieval; when rendering the search results, the interface is re-rendered according to the updated search results to prevent performance problems caused by rendering the search results in full.

[0108] The text search device provided by the present invention is described below. The text search device described below and the text search method described above can be referenced to each other.

[0109] Based on any of the above embodiments, Figure 5 is a schematic diagram of the structure of the text search device provided by the present invention, such as Figure 5 As shown, a text search device is provided, comprising: The text determination unit 510 is used to determine the modified text and the position of the modified text when a change in the text content is detected; A search unit 520, configured to search the modified text based on the text structure of the modified text to obtain search results of the modified text; The updating unit 530 is used to update the search result cache stack based on the position of the modified text and the search result, wherein the search result cache stack is created based on the initial search result of the text content.

[0110] The device provided by the embodiment of the present invention monitors the text content and automatically triggers a new search every time the content changes. This means that no matter when the user edits, the system can immediately capture these changes and start real-time search. This real-time search update mechanism greatly improves user experience and work efficiency, especially in text processing scenarios that require frequent editing and searching.

[0111] In addition, this embodiment can directly locate the position of the modified text that has changed. It only needs to search the modified text and update the search result cache stack to obtain the position of the matching item in the entire text. Compared with traversing the entire document for a full search, it avoids the performance loss caused by the full search, can significantly improve page performance, make the search content respond quickly, and greatly enhance the user experience.

[0112] Based on any of the above embodiments, the data structure level of the search result cache stack includes paragraphs, nodes and search selections, and the updating unit is specifically used for: Based on the paragraph position of the modified text, the search result and the modification type, the search selection area corresponding to the paragraph position in the search result cache stack is updated.

[0113] Based on any of the above embodiments, it further includes a rendering unit, which is used to: Combining the search selections of each paragraph in the search result cache stack into an array structure, and marking the updated search selections; Data rendering is performed based on the updated search selection.

[0114] Based on any of the above embodiments, the data structure description of the search selection includes the start position and the end position of the search selection, and a unique identifier of the search selection, and the unique identifier is determined based on the paragraph index and the search result index.

[0115] Based on any of the above embodiments, the text structure includes paragraphs and nodes, and the search unit is specifically used for: Search the paragraph contents of each paragraph in the modified text to obtain the search position of the search results in each paragraph; Traversing the node content of each node in each paragraph to obtain the node position of the node content in each paragraph; The search position of the search result and the node position of the node content are compared to obtain the search result of the modified text.

[0116] Based on any of the above embodiments, the search unit is specifically used for: Comparing the start position and the end position in the search position, and the start position and the end position in the node position, to obtain a comparison result; Based on the comparison result and the length of the node content, the start position and the end position of the search selection area corresponding to the search result are determined.

[0117] Based on any of the above embodiments, the updating unit is specifically used for: Based on the position of the modified text and the search results, the search result cache stack and the search result corresponding stack are updated, and the data structure hierarchy of the search result corresponding stack includes paragraphs, unique identifiers of search selections, and search selections.

[0118] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the text search method, which includes: determining the modified text and the position of the modified text when a change in the text content is detected; searching the modified text based on the text structure of the modified text to obtain the search result of the modified text; and updating the search result cache stack based on the position of the modified text and the search result, wherein the search result cache stack is created based on the initial search result of the text content.

[0119] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0120] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the text search method provided by the above-mentioned methods, which method includes: determining the modified text and the position of the modified text when a change in the text content is detected; searching for the modified text based on the text structure of the modified text to obtain search results for the modified text; and updating the search result cache stack based on the position of the modified text and the search results, wherein the search result cache stack is created based on the initial search results of the text content.

[0121] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the text search method provided by the above-mentioned methods, the method comprising: determining a modified text and a position of the modified text upon detecting a change in text content; searching for the modified text based on the text structure of the modified text to obtain search results for the modified text; and updating a search result cache stack based on the position of the modified text and the search results, the search result cache stack being created based on the initial search results of the text content.

[0122] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0123] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A text search method, characterized in that: include: When a change in the text content is detected, determining the modified text and the position of the modified text; Based on the text structure of the modified text, searching the modified text to obtain search results of the modified text; Based on the position of the modified text and the search results, a search result cache stack is updated, wherein the search result cache stack is created based on the initial search results of the text content.

2. The text search method according to claim 1, characterized in that: The data structure hierarchy of the search result cache stack includes paragraphs, nodes and search selections, and updating the search result cache stack based on the position of the modified text and the search results includes: Based on the paragraph position of the modified text, the search result and the modification type, the search selection area corresponding to the paragraph position in the search result cache stack is updated.

3. The text search method according to claim 2, characterized in that: After updating the search result cache stack based on the position of the modified text and the search results, the method further includes: Combining the search selections of each paragraph in the search result cache stack into an array structure, and marking the updated search selections; Data rendering is performed based on the updated search selection.

4. The text search method according to claim 2, characterized in that: The data structure description of the search selection includes the start position and the end position of the search selection, and a unique identifier of the search selection, and the unique identifier is determined based on the paragraph index and the search result index.

5. The text search method according to any one of claims 1 to 4, characterized in that: The text structure includes paragraphs and nodes, and the searching for the modified text based on the text structure of the modified text to obtain search results of the modified text includes: Search the paragraph contents of each paragraph in the modified text to obtain the search position of the search results in each paragraph; Traversing the node content of each node in each paragraph to obtain the node position of the node content in each paragraph; The search position of the search result and the node position of the node content are compared to obtain the search result of the modified text.

6. The text search method according to claim 5, characterized in that: The comparing the search position of the search result with the node position of the node content to obtain the search result of the modified text includes: Comparing the start position and the end position in the search position, and the start position and the end position in the node position, to obtain a comparison result; Based on the comparison result and the length of the node content, the start position and the end position of the search selection area corresponding to the search result are determined.

7. The text search method according to any one of claims 1 to 4, characterized in that: The updating of the search result cache stack based on the position of the modified text and the search result includes: Based on the position of the modified text and the search results, the search result cache stack and the search result corresponding stack are updated, and the data structure hierarchy of the search result corresponding stack includes paragraphs, unique identifiers of search selections, and search selections.

8. A text search device, characterized in that: include: A text determination unit, configured to determine the modified text and the position of the modified text when a change in the text content is detected; A search unit, configured to search the modified text based on the text structure of the modified text to obtain search results of the modified text; An updating unit is used to update a search result cache stack based on the position of the modified text and the search result, wherein the search result cache stack is created based on the initial search result of the text content.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the text search method according to any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the text search method according to any one of claims 1 to 7 is implemented.