CN114296606A - Text search method and device, electronic equipment and storage medium - Google Patents

Text search method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114296606A
CN114296606A CN202111613097.XA CN202111613097A CN114296606A CN 114296606 A CN114296606 A CN 114296606A CN 202111613097 A CN202111613097 A CN 202111613097A CN 114296606 A CN114296606 A CN 114296606A
Authority
CN
China
Prior art keywords
search
information
chinese character
mapping
pinyin
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202111613097.XA
Other languages
Chinese (zh)
Inventor
姜勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Yuexuebang Network Technology Co ltd
Original Assignee
Wuhan Yuexuebang Network Technology Co ltd
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 Wuhan Yuexuebang Network Technology Co ltd filed Critical Wuhan Yuexuebang Network Technology Co ltd
Priority to CN202111613097.XA priority Critical patent/CN114296606A/en
Publication of CN114296606A publication Critical patent/CN114296606A/en
Pending legal-status Critical Current

Links

Images

Abstract

The disclosure provides a text search method, a text search device, an electronic device and a storage medium, wherein the method comprises the following steps: acquiring search information input by a user; judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; under the condition that the search mode of the search information is the fuzzy matching search, performing first highlight display on first target texts corresponding to the search information at two ends of the separator; and under the condition that the searching mode of the searching information is the accurate matching searching, performing second highlighting on a second target text corresponding to the searching information, wherein the second highlighting is different from the first highlighting in display mode. According to the embodiment of the disclosure, the highlight display modes of the target text are different according to different search modes of the user, so that the diversity of the highlight display modes is increased, the user can distinguish prompts of key information corresponding to different search modes conveniently, and the user experience is improved.

Description

Text search method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a text search method and apparatus, an electronic device, and a storage medium.
Background
With the continuous development of the application technology of electronic devices, keyword search has been widely applied in different service scenarios. In some electronic device applications, when a user inputs a search keyword, a part of words in a text associated with the search keyword is often highlighted in order to facilitate display of important information in the text. For example, in a search interface of a mobile phone address book or an address book of an a application, when a user inputs "zhaozh", the search interface may display a name "zhao zhen" or "zhao zhi" associated with "zhaozh" and highlight the name.
However, the highlighting form in the prior art is too single, for example, when a user inputs a search keyword "zhao zh" or "zhao zh", the two search modes are obviously different, and there is a case where a separator (such as a space) may exist in the search information, whereas the highlighting form in the prior art for the two search modes is the same, for example, both the font color and font thickness are the same, the display mode is not flexible enough, the pertinence is lacking, and the user experience is not good enough.
Disclosure of Invention
The embodiment of the disclosure at least provides a text searching method, a text searching device, electronic equipment and a computer-readable storage medium.
In a first aspect, an embodiment of the present disclosure provides a text search method, including:
acquiring search information input by a user;
judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that no separator exists in the search information;
under the condition that the search mode of the search information is the fuzzy matching search, performing first highlight display on first target texts corresponding to the search information at two ends of the separator;
under the condition that the searching mode of the searching information is the accurate matching searching, second highlighting is carried out on a second target text corresponding to the searching information; wherein the second highlighting is in a different display manner than the first highlighting.
According to the embodiment of the disclosure, the highlight display modes of the target text are different according to different search modes of the user, so that the diversity of the highlight display modes is increased, the user can distinguish prompts of key information corresponding to different search modes conveniently, and the user experience is improved.
According to the first aspect, in a possible implementation manner, the first highlighting the first target text corresponding to the search information at both ends of the separator includes:
acquiring a search field associated with the search information;
judging whether the search information is first type information or not, wherein the first type information comprises pinyin;
under the condition that the search information is first type information, constructing a first mapping of the search information and the position of a Chinese character corresponding to the search information in the search field;
determining a first starting position and a first ending position of the search information corresponding to the search field based on the first mapping;
and traversing the search field, determining the first target text according to the first starting position and the first ending position, and performing the first highlighting on the first target text.
In the embodiment of the disclosure, the positions of the search information and the Chinese characters corresponding to the search information in the search field are mapped to be highlighted, so that the highlight display accuracy is improved, and the search modes of various situations can be processed.
According to the first aspect, in one possible implementation, the method further comprises:
determining a second starting position and a second ending position of the search information corresponding to the search field if the search information is not the first kind of information;
and traversing the search field, determining a first target text according to the second starting position and the second ending position, and performing first highlighting on the first target text.
In the embodiment of the disclosure, under the condition that the search information is not the first type of information, the first target text can be highlighted, so that the search mode and the highlighting method are more comprehensive, and the application range is expanded.
According to the first aspect, in a possible implementation manner, the constructing a first mapping of the search information and the position of the chinese character corresponding to the search information in the search field includes:
converting the search field into pinyin, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
constructing a third mapping between each Chinese character in the search field and the position of each Chinese character in the search field;
constructing the first mapping based on the search information, the second mapping, and the third mapping.
In the embodiment of the disclosure, the first mapping is further constructed by constructing the second mapping and the third mapping, so that the corresponding relation between the search keyword in the search information and the position of the search keyword in the search field is realized, and the accuracy of the target text highlight display method is ensured.
In a possible implementation manner, the constructing a second mapping between each chinese character in the search field and the pinyin corresponding to the each chinese character includes:
establishing a fourth mapping between each Chinese character in the search field and the pinyin which starts with the first letter and corresponds to each Chinese character aiming at the first keyword of the search information;
aiming at other keywords except the first keyword of the search information, constructing a fifth mapping between each Chinese character in the search field and the pinyin which starts with any letter and corresponds to each Chinese character;
constructing the second mapping based on the search information, the fourth mapping, and the fifth mapping.
In the embodiment of the disclosure, since other keywords except the first keyword in the search information can construct a mapping starting with any letter, the highlight display range is expanded, and the comprehensiveness of the search mode is improved.
In a possible implementation form, after the constructing a fifth mapping between each chinese character in the search field and the pinyin beginning with an arbitrary letter corresponding to the each chinese character, the method further includes:
determining the starting position of the first keyword and the ending position of the other keywords as a third starting position and a third ending position when the starting position of the other keywords is less than or equal to the ending position of the first keyword;
and traversing the search field, determining the first target text according to the third starting position and the third ending position, and performing the first highlighting on the first target text.
In the embodiment of the disclosure, repeated highlighting can be avoided, and processing steps can be reduced.
According to the first aspect, in a possible implementation, before the converting the search field into pinyin, the method further includes:
judging whether the characters in the search field are expressions or not;
converting the search field into pinyin under the condition that the characters in the search field are not expressions, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
in the case where the character in the search field is an emoticon, no conversion is performed.
In the embodiment of the disclosure, the conversion efficiency can be improved, and the conversion precision can be improved.
In a possible implementation manner, the converting the search field into pinyin and constructing a second mapping between each chinese character in the search field and the pinyin corresponding to the each chinese character includes:
storing the full pinyin corresponding to the converted pinyin into a full pinyin set, and constructing a second mapping between each Chinese character in the search field and the full pinyin corresponding to each Chinese character; and/or the presence of a gas in the gas,
and storing the first letter of the Chinese character corresponding to the converted pinyin into a first letter set, and constructing a second mapping between each Chinese character in the search field and the first letter corresponding to each Chinese character.
In the embodiment of the disclosure, not only the target text corresponding to the full spelling input by the user can be highlighted, but also the target text corresponding to the first letter input by the user can be highlighted, so that the search range is improved.
In a second aspect, an embodiment of the present disclosure further provides a text search apparatus, including:
the acquisition module is used for acquiring search information input by a user;
the judging module is used for judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that no separator exists in the search information;
the first display module is used for carrying out first highlight display on first target texts corresponding to the search information at the two ends of the separator under the condition that the search mode of the search information is the fuzzy matching search;
the second display module is used for carrying out second highlight display on a second target text corresponding to the search information under the condition that the search mode of the search information is the accurate matching search; wherein the second highlighting is in a different display manner than the first highlighting.
According to the second aspect, in a possible implementation manner, the first display module is specifically configured to:
acquiring a search field associated with the search information;
judging whether the search information is first type information or not, wherein the first type information comprises pinyin;
under the condition that the search information is first type information, constructing a first mapping of the search information and the position of a Chinese character corresponding to the search information in the search field;
determining a first starting position and a first ending position of the search information corresponding to the search field based on the first mapping;
and traversing the search field, determining the first target text according to the first starting position and the first ending position, and performing the first highlighting on the first target text.
In a possible implementation manner, according to the second aspect, the first display module is further configured to:
determining a second starting position and a second ending position of the search information corresponding to the search field if the search information is not the first kind of information;
and traversing the search field, determining a first target text according to the second starting position and the second ending position, and performing first highlighting on the first target text.
According to the second aspect, in a possible implementation manner, the first display module is specifically configured to:
converting the search field into pinyin, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
constructing a third mapping between each Chinese character in the search field and the position of each Chinese character in the search field;
constructing the first mapping based on the search information, the second mapping, and the third mapping.
According to the second aspect, in a possible implementation manner, the first display module is specifically configured to:
establishing a fourth mapping between each Chinese character in the search field and the pinyin which starts with the first letter and corresponds to each Chinese character aiming at the first keyword of the search information;
aiming at other keywords except the first keyword of the search information, constructing a fifth mapping between each Chinese character in the search field and the pinyin which starts with any letter and corresponds to each Chinese character;
constructing the second mapping based on the search information, the fourth mapping, and the fifth mapping.
In a possible implementation manner, according to the second aspect, the first display module is further configured to:
determining the starting position of the first keyword and the ending position of the other keywords as a third starting position and a third ending position when the starting position of the other keywords is less than or equal to the ending position of the first keyword;
and traversing the search field, determining the first target text according to the third starting position and the third ending position, and performing the first highlighting on the first target text.
In a possible implementation manner, according to the second aspect, the first display module is further configured to:
judging whether the characters in the search field are expressions or not;
converting the search field into pinyin under the condition that the characters in the search field are not expressions, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
in the case where the character in the search field is an emoticon, no conversion is performed.
According to the second aspect, in a possible implementation manner, the first display module is specifically configured to:
storing the full pinyin corresponding to the converted pinyin into a full pinyin set, and constructing a second mapping between each Chinese character in the search field and the full pinyin corresponding to each Chinese character; and/or the presence of a gas in the gas,
and storing the first letter of the Chinese character corresponding to the converted pinyin into a first letter set, and constructing a second mapping between each Chinese character in the search field and the first letter corresponding to each Chinese character.
In a third aspect, an embodiment of the present disclosure further provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, the processor and the memory communicate via the bus when the electronic device is running, and the machine-readable instructions, when executed by the processor, perform the text search method of the first aspect or any possible implementation manner of the first aspect.
In a fourth aspect, this disclosed embodiment further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program performs the text search method in the first aspect described above or any one of the possible implementation manners of the first aspect.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly described below, and the drawings herein incorporated in and forming a part of the specification illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the technical solutions of the present disclosure. It is appreciated that the following drawings depict only certain embodiments of the disclosure and are therefore not to be considered limiting of its scope, for those skilled in the art will be able to derive additional related drawings therefrom without the benefit of the inventive faculty.
Fig. 1 shows a flowchart of a text search method provided by an embodiment of the present disclosure;
FIG. 2 is a diagram illustrating a first highlighting of a first target text provided by an embodiment of the present disclosure;
FIG. 3 is a flowchart illustrating a specific method for performing a first highlighting of a first target text according to an embodiment of the present disclosure;
FIG. 4 is a flowchart illustrating a method for constructing a first mapping of search information and locations of Chinese characters corresponding to the search information in a search field according to an embodiment of the present disclosure;
FIG. 5 illustrates a logic flow diagram of a highlighting method provided by an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of a text search apparatus provided in an embodiment of the present disclosure;
fig. 7 shows a schematic diagram of an electronic device provided by an embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
With the continuous development of the application technology of electronic devices, keyword search has been widely applied in different service scenarios. In some electronic device applications, when a user inputs a search keyword, a part of words in a text associated with the search keyword is often highlighted in order to facilitate display of important information in the text. For example, in a search interface of a mobile phone address book or an address book of an a application, when a user inputs "zhaozh", the search interface may display a name "zhao zhen" or "zhao zhi" associated with "zhaozh" and highlight the name.
Research shows that the highlighting form in the prior art is too single, for example, when a user inputs a search keyword "zhao zh" or "zhao zh", the two search modes are obviously different, and a separator (for example, a space) may exist in the search keyword, whereas the highlighting form in the prior art for the two search modes is the same, for example, the change of the same font color or the font thickening, the display mode is not flexible enough, the pertinence is lacked, and the user experience is not good.
Based on the above research, the present disclosure provides a text search method, which obtains search information input by a user, and then determines whether a search mode of the search information is an exact match search or a fuzzy match search, wherein the fuzzy match search indicates that a separator exists in the search information, the exact match search indicates that no separator exists in the search information, in a case that the search mode of the search information is the fuzzy match search, first highlighting is performed on first target texts corresponding to the search information at both ends of the separator, in a case that the search mode of the search information is the exact match search, second highlighting is performed on second target texts corresponding to the search information, wherein the second highlighting is different from the first highlighting, and thus, aiming at different search modes of the user, the highlight display modes of the target text are different, so that the diversity of the highlight display modes is increased, the prompt for distinguishing the key information corresponding to different search modes by the user is facilitated, and the user experience is improved.
To facilitate understanding of the present embodiment, first, a text search method disclosed in the embodiments of the present disclosure is described in detail, where an execution subject of the text search method provided in the embodiments of the present disclosure is generally an electronic device with certain computing capability, and the electronic device includes, for example: a terminal device, which may be a mobile device, a user terminal, a handheld device, a computing device, a vehicle device, a wearable device, or the like, or a server or other processing device. In some possible implementations, the text search method may be implemented by a processor invoking computer readable instructions stored in a memory.
Referring to fig. 1, a flowchart of a text search method provided by the embodiment of the present disclosure is shown, where the method may be applied to the electronic device, or applied to a local or cloud server. The text search method shown in fig. 1 includes the following S101 to S104:
s101, acquiring search information input by a user.
For example, the mode of inputting the search information by the user may be an input mode such as a keyboard input, a touch input, or a mouse input for the computer terminal, and an input mode such as a keyboard input, a touch input, or a trackball input for the smart mobile terminal.
The search information comprises a search keyword input by a user on a search interface of the terminal, and the search keyword can be a single character or a character string. The language type of the search keyword may include, but is not limited to, numeral, chinese, english, japanese, french, german, etc. For example, when the user searches for the name "zhao zhen" in the address book of the application a, the user may input the search information "zhaozhen" in the search interface of the address book, may also input "zhaozh", and may also directly input the chinese character "zhao zhen", which is not limited herein.
S102, judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that a separator does not exist in the search information.
For example, the exact match search is a search mode in a case that the user completely knows a target text that needs to be searched, that is, the search information input by the user is continuous without any break or separator, for example, the search information may be "lixiaoming", or "lixiaom", or the like. The fuzzy matching search is a condition that a user may forget a certain word of a target text to be searched or input by mistake, a separator exists in the input search information, for example, the search information may be li ming, or li, ming, the user may forget a small word in friend names 'li ming' in an address book, and the separator 'space' is used for replacing the small word when the search information is input. Therefore, before highlighting the target text, it is necessary to determine whether the search mode of the user is an exact match search or a fuzzy match search.
And S103, under the condition that the search mode of the search information is the fuzzy matching search, performing first highlight display on first target texts corresponding to the search information at the two ends of the separator.
Illustratively, for example, the search information input by the user is "zhao zh", and the first target text may be a word of "zhao" and "true" in the friend name "zhao" in the address book of the user terminal. The highlight display mode can be a bold font of the target text, and can also be a change of the font display color of the target text so as to be distinguished and displayed relative to the common text, and further give a corresponding prompt to the user. For example, for a bold face of a bold text, highlighting can be achieved by changing the color of the font, and for a font with a special color, highlighting can be achieved by changing the thickness of the font. In some embodiments, the highlighting of the target text may also be achieved by other means, which are not limited herein.
For example, referring to fig. 2, a schematic diagram for performing a first highlighting on a first target text provided by an embodiment of the present disclosure is shown, where "zhao zh" is search information a, "zhao zhen", "zhao", and "zhao" in the zhao and "zhao", and "zhi" is a first target text b corresponding to "zhao" and "zh" at two ends of a "space", and the first target text is highlighted in a manner of "bold font", that is, the fonts of "zhao" and "zhao" in "zhao zhen", i.e., the fonts of "zhao" and "zhi" in "zhao zhen", are bold compared with other common fonts, so that a user can see important information in the target text conveniently.
S104, under the condition that the searching mode of the searching information is the accurate matching searching, second highlighting is carried out on a second target text corresponding to the searching information; wherein the second highlighting is in a different display manner than the first highlighting.
In this step, the search information is continuous without a separator in the middle, such as "zhaozh", and the corresponding second target text may be "zhao" or "zhao" and the second highlight may be displayed in a different manner from the first highlight. For example, if the first highlighting display mode is "font bolding", the second highlighting display mode may be "changing font color"; for another example, if the first highlighting is displayed in a "font is red", the second highlighting may be displayed in a "font is yellow". The display mode may be other modes, and is not limited herein.
According to the method and the device, the highlight display modes of the target text are different according to different search modes of the user, the diversity of the highlight display modes is increased, the user can distinguish prompts of key information corresponding to different search modes conveniently, and the user experience is improved.
With reference to the above S103, referring to fig. 3, a flowchart of a specific method for performing first highlighting on a first target text provided by the embodiment of the present disclosure includes the following S1031 to S1037:
and S1031, obtaining the search field associated with the search information.
For example, when the user inputs search information, the user terminal may receive the search information input by the user through the search interface, and search and acquire a search field or context with the search information from a local database according to the search information. Specifically, whether the search field or the context is obtained is combined with a specific service scenario, which is not limited in the embodiment of the present disclosure.
For example, when the search information input by the user on the address book search interface of the application program a is "zhaozh", the user terminal may obtain a search field containing a Chinese character corresponding to "zhaozh" in the address book of the application program a, such as "zhao zhengyang" and "zhangdong", that is, all the friend names corresponding to "zhaozh" in the address book.
S1032, judging whether the search information is first type information or not, wherein the first type information comprises pinyin; if yes, go to step S1033; if not, go to step S1036.
For example, the first type information may be pinyin or english, and is not limited herein, and the following methods of the present disclosure are mainly described by taking pinyin as an example.
S1033, constructing a first mapping of the search information and the position of the Chinese character corresponding to the search information in the search field.
For example, in the case that the search information is pinyin, for example, if the search information input by the user is "zhao sh", and the corresponding search field is "zhao winner", the starting and ending positions of "zhao" in "zhao winner" corresponding to "zhao" are [0,0], and a first mapping of "zhao" and [0,0] is constructed. In this embodiment, it is assumed that the position of the chinese character in the search field is from 0, for example, the starting and ending positions of "zhao" in "zhao victory" are [0,0], "victory" in "zhao victory" is [1,1], "zhao victory" in "zhao victory" is [0,1 ]. In other embodiments, the position of the chinese character in the search field may be defined in other ways, and is not limited herein.
S1034, determining a first start position and a first end position of the search information in the search field, based on the first mapping.
Illustratively, the first start position and the first end position of the search information "zhao" in the search field "zhao" are [0,0], and the first start position and the first end position of the search information "sh" in the search field "zhao" are [1,1 ].
In some embodiments, in a case where there are multiple search keywords in the search information, there may be a case where the first search keyword includes the second search keyword, for example, the search information is "zhao zh", the first search keyword "zhao" includes the second search keyword "zh", where it is necessary to add 1 to the end position of "zhao" as the start position of "zh", for example, the position index of "zhao" is [0,0], and the position index of "zh" is [1,1 ]. Therefore, repeated highlighting can be avoided, and processing steps can be reduced.
S1035, traversing the search field, determining the first target text according to the first start position and the first end position, and performing the first highlighting on the first target text.
For example, if the search information is "zhao sh", two search fields "zhao sheng" and "zhao yang" are searched in the address book, then the first target text of "zhao sh" in the search field "zhao" is "zhao sheng", and the first target text of "zhao sh" in the search field "zhao sheng" is "zhao", and the search interface highlights "zhao sheng" and "zhao sheng".
In the embodiment of the disclosure, the positions of the search information and the Chinese characters corresponding to the search information in the search field are mapped to be highlighted, so that the highlight display accuracy is improved, and the search modes of various situations can be processed.
S1036, determining a second starting position and a second ending position of the search information corresponding to the search field.
For example, in the case that the search information is a chinese character, for example, because there is no need to construct a mapping of positions of the pinyin and the chinese character corresponding to the pinyin in the search field, the second start position and the second end position of the chinese character corresponding to the search field may be directly obtained by a preset method. For example, the search information is "lie small", the search field is "lie diming", and then the "lie small" can be directly obtained to be [0,1] at the second start position and the second end position of the search field "lie diming". The preset method may be a java method or other methods, and is not limited herein.
S1037, traversing the search field, determining a first target text according to the second starting position and the second ending position, and performing first highlighting on the first target text.
Illustratively, such as the example in step S1036, when the first target text corresponding to [0,1] is "lie small", the "lie small" is highlighted.
In the embodiment of the disclosure, even if the search information is not the first type of information, the first target text can be highlighted, so that the search mode and the highlighting method are more comprehensive, and the application range is expanded.
With reference to the above S1033, referring to fig. 4, a flowchart of a method for constructing a first mapping of search information and positions of chinese characters corresponding to the search information in a search field provided by an embodiment of the present disclosure includes the following S10331 to S10333:
s10331, converting the search field into pinyin, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character.
It can be understood that, in the case that the search information is pinyin, in order to construct the first mapping, the search field needs to be first converted into pinyin, and a mapping relationship between each chinese character in the search field and the pinyin corresponding to each chinese character is constructed, and in the case that polyphones may exist, one chinese character may Map multiple pinyins, and a data structure is created as Map < String, List < String > wordpinmap for storing the mapping between each chinese character in the search field and pinyin.
In this embodiment, since the search information is not only a search keyword due to the fuzzy matching search, the pinyin for the first search keyword must start with the first letter of a chinese character, but other search keywords may not start with the first letter of a chinese character, and therefore the first search keyword and other search keywords that follow need to be processed separately. Firstly, aiming at a first search keyword, a mapping relation between a Chinese character in a search field and pinyin which is corresponding to the Chinese character and starts with an initial letter is constructed, for example, the search field is 'li Xiaoming', and a mapping between 'li' and 'li' is constructed. And aiming at other keywords behind the first search keyword, constructing a mapping relation between the Chinese characters in the search field and pinyin starting from any letter corresponding to the Chinese characters, such as constructing a mapping between 'small' and 'ao', and also a mapping between 'small' and 'iao'. And then the two mappings are stored in the wordpinymap.
In some embodiments, for a first search keyword and other search keywords in the case of fuzzy matching search, when a start position and an end position are obtained, there are cases where the start position of the other search keywords is less than or equal to the end position of the first search keyword, for example, the start and end positions corresponding to "chen" are [0,0], and the start and end positions corresponding to "enli" are [0,1 ].
In some embodiments, before the search field is converted into pinyin, there may be a case where an expression exists in the search field, and the determination is made in such a manner that the lengths of the expression and the chinese character are different, and it is necessary to determine whether the character in the search field is an expression. If the expression is the expression, the expression is directly stored into the wordpinymap without conversion; if the Chinese characters are Chinese characters, the Chinese characters need to be converted into pinyin and then stored in the wordpinymap. Therefore, the conversion efficiency and the conversion precision can be improved.
In some embodiments, where the search information is pinyin, the user's search type may be the full pinyin of the pinyin, such as "lixiaoming," or the first letter of the pinyin, such as "lxm. Correspondingly, when the search field is converted into pinyin, the search field can be converted into pinyin full pinyin and stored in the full pinyin Set < String > quanpin, and then a second mapping between the Chinese characters in the search field and the corresponding full pinyin of the Chinese characters is constructed, such as the "li" mapping; it is also possible to convert the search field to the first letter of the chinese character corresponding to the pinyin and store it in the Set of first letters < String > shouzimu, and then construct a second mapping between the chinese character in the search field and the first letter corresponding to the chinese character, such as the "li" mapping "l. Therefore, the target text corresponding to the full spelling input by the user can be highlighted, the target text corresponding to the first letter input by the user can be highlighted, and the search range is widened.
S10332, constructing a third mapping between each Chinese character in the search field and the position of each Chinese character in the search field.
Illustratively, after the mapping between each chinese character and the pinyin corresponding to each chinese character in the search field is constructed, the mapping relationship between each chinese character and the position of each chinese character in the search field also needs to be constructed, for example, in the search field "lisgming", lie "forms a mapping with [0,0], small" forms a mapping with [1,1], and "lisgmi" forms a mapping with [0,1], and a data structure is created as Map < Integer, String > indexmap for storing the mapping relationship between each chinese character and the position of each chinese character in the search field.
S10333, constructing the first mapping based on the search information, the second mapping, and the third mapping.
Illustratively, based on the second mapping and the third mapping in the above steps, a mapping relationship of positions of the pinyin and the chinese characters corresponding to the pinyin in the search field can be constructed, and a data structure of Map < String, wordlndex > pinyindinxmap is created for storing the mapping relationship of the positions of the pinyin and the chinese characters corresponding to the pinyin in the search field. For example, "li xiao qiang" is converted into pinyin, and then "lixiaoqi", "l" and "li" are part of the pinyin of the "li" word, so the starting and ending positions corresponding to the two character strings are both [0,0], "lix" is [0,1], "x" is [1,1 ]. In addition, it should be noted that the initial letter of each pinyin is only the first letter of any Chinese character in the search field, for example, "ix" does not appear. Then, based on the mapping relation, the starting position and the ending position of the search information in the search field can be obtained to determine the target text, and then the target text is highlighted.
In the embodiment of the disclosure, the first mapping is further constructed by constructing the second mapping and the third mapping, so that the corresponding relation between the search keyword in the search information and the position of the search keyword in the search field is realized, and the accuracy of the target text highlight display method is ensured.
Referring to fig. 5, a logic flow diagram of a highlighting method provided by the embodiment of the present disclosure includes the following steps S110 to S123:
s111, judging whether the searching mode is accurate matching searching or fuzzy matching searching, and if the searching mode is accurate matching, executing S112; if the fuzzy match is true, S116 is executed.
S112, judging whether pinyin searching is passed, if yes, executing S113; if not, go to S114.
S113, mapping of the pinyin started by the initial letter and the position of the Chinese character corresponding to the pinyin in the search field is constructed.
S114, acquiring the position of the search keyword in the search field.
And S115, carrying out second highlighting on the second target text corresponding to the search keyword.
S116, judging whether pinyin searching is passed, if yes, executing S117; if not, S121 is executed.
S117, judging whether the keyword is the first search keyword, if so, executing S118; if not, go to step S119.
S118, mapping of the pinyin started by the first letter and the position of the Chinese character corresponding to the pinyin in the search field is constructed.
S119, mapping of the pinyin initiated by any letter and the position of the Chinese character corresponding to the pinyin in the search field is constructed.
And S120, acquiring the position of the search keyword in the search field and combining the overlapped positions.
S121, acquiring the position of the search keyword in the search field.
And S122, performing first highlighting on the first target text corresponding to the search keyword.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same technical concept, a text search device corresponding to the text search method is further provided in the embodiment of the present disclosure, and as the principle of solving the problem of the device in the embodiment of the present disclosure is similar to the text search method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and repeated details are not repeated.
Referring to fig. 6, a schematic structural diagram of a text search apparatus provided in an embodiment of the present disclosure is shown, where the apparatus 500 includes:
an obtaining module 501, configured to obtain search information input by a user;
a judging module 502, configured to judge whether a search mode of the search information is an exact match search or a fuzzy match search; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that no separator exists in the search information;
a first display module 503, configured to perform first highlighting on first target texts corresponding to the search information at two ends of the separator if the search manner of the search information is the fuzzy matching search;
a second display module 504, configured to perform second highlighting on a second target text corresponding to the search information when the search mode of the search information is the exact match search; wherein the second highlighting is in a different display manner than the first highlighting.
In a possible implementation manner, the first display module 503 is specifically configured to:
acquiring a search field associated with the search information;
judging whether the search information is first type information or not, wherein the first type information comprises pinyin;
under the condition that the search information is first type information, constructing a first mapping of the search information and the position of a Chinese character corresponding to the search information in the search field;
determining a first starting position and a first ending position of the search information corresponding to the search field based on the first mapping;
and traversing the search field, determining the first target text according to the first starting position and the first ending position, and performing the first highlighting on the first target text.
In a possible implementation, the first display module 503 is further configured to:
determining a second starting position and a second ending position of the search information corresponding to the search field if the search information is not the first kind of information;
and traversing the search field, determining a first target text according to the second starting position and the second ending position, and performing first highlighting on the first target text.
In a possible implementation manner, the first display module 503 is specifically configured to:
converting the search field into pinyin, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
constructing a third mapping between each Chinese character in the search field and the position of each Chinese character in the search field;
constructing the first mapping based on the search information, the second mapping, and the third mapping.
In a possible implementation manner, the first display module 503 is specifically configured to:
establishing a fourth mapping between each Chinese character in the search field and the pinyin which starts with the first letter and corresponds to each Chinese character aiming at the first keyword of the search information;
aiming at other keywords except the first keyword of the search information, constructing a fifth mapping between each Chinese character in the search field and the pinyin which starts with any letter and corresponds to each Chinese character;
constructing the second mapping based on the search information, the fourth mapping, and the fifth mapping.
In a possible implementation, the first display module 503 is further configured to:
determining the starting position of the first keyword and the ending position of the other keywords as a third starting position and a third ending position when the starting position of the other keywords is less than or equal to the ending position of the first keyword;
and traversing the search field, determining the first target text according to the third starting position and the third ending position, and performing the first highlighting on the first target text.
In a possible implementation, the first display module 503 is further configured to:
judging whether the characters in the search field are expressions or not;
converting the search field into pinyin under the condition that the characters in the search field are not expressions, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
in the case where the character in the search field is an emoticon, no conversion is performed.
In a possible implementation manner, the first display module 503 is specifically configured to:
storing the full pinyin corresponding to the converted pinyin into a full pinyin set, and constructing a second mapping between each Chinese character in the search field and the full pinyin corresponding to each Chinese character; and/or the presence of a gas in the gas,
and storing the first letter of the Chinese character corresponding to the converted pinyin into a first letter set, and constructing a second mapping between each Chinese character in the search field and the first letter corresponding to each Chinese character.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Based on the same technical concept, the embodiment of the disclosure also provides an electronic device. Referring to fig. 7, a schematic structural diagram of an electronic device 700 provided in the embodiment of the present disclosure includes a processor 701, a memory 702, and a bus 703. The memory 702 is used for storing execution instructions and includes a memory 7021 and an external memory 7022; the memory 7021 is also referred to as an internal memory and temporarily stores operation data in the processor 701 and data exchanged with an external memory 7022 such as a hard disk, and the processor 701 exchanges data with the external memory 7022 via the memory 7021.
In this embodiment, the memory 702 is specifically configured to store application program codes for executing the scheme of the present application, and is controlled by the processor 701 to execute. That is, when the electronic device 700 is operated, the processor 701 and the memory 702 communicate with each other via the bus 703, so that the processor 701 executes the application program code stored in the memory 702 to perform the method disclosed in any of the foregoing embodiments.
The Memory 702 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
The processor 701 may be an integrated circuit chip having signal processing capabilities. The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It is to be understood that the illustrated structure of the embodiment of the present application does not specifically limit the electronic device 700. In other embodiments of the present application, the electronic device 700 may include more or fewer components than shown, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The embodiment of the present disclosure also provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program performs the text search method in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the text search method in the foregoing method embodiments, which may be referred to specifically for the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (11)

1. A text search method, comprising:
acquiring search information input by a user;
judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that no separator exists in the search information;
under the condition that the search mode of the search information is the fuzzy matching search, performing first highlight display on first target texts corresponding to the search information at two ends of the separator;
under the condition that the searching mode of the searching information is the accurate matching searching, second highlighting is carried out on a second target text corresponding to the searching information; wherein the second highlighting is in a different display manner than the first highlighting.
2. The method according to claim 1, wherein the first highlighting the first target text corresponding to the search information at both ends of the separator comprises:
acquiring a search field associated with the search information;
judging whether the search information is first type information or not, wherein the first type information comprises pinyin;
under the condition that the search information is first type information, constructing a first mapping of the search information and the position of a Chinese character corresponding to the search information in the search field;
determining a first starting position and a first ending position of the search information corresponding to the search field based on the first mapping;
and traversing the search field, determining the first target text according to the first starting position and the first ending position, and performing the first highlighting on the first target text.
3. The method of claim 2, further comprising:
determining a second starting position and a second ending position of the search information corresponding to the search field if the search information is not the first kind of information;
and traversing the search field, determining a first target text according to the second starting position and the second ending position, and performing the first highlighting on the first target text.
4. The method of claim 2, wherein the constructing a first mapping of the search information and the position of the Chinese character corresponding to the search information in the search field comprises:
converting the search field into pinyin, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
constructing a third mapping between each Chinese character in the search field and the position of each Chinese character in the search field;
constructing the first mapping based on the search information, the second mapping, and the third mapping.
5. The method of claim 4, wherein constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to the each Chinese character comprises:
establishing a fourth mapping between each Chinese character in the search field and the pinyin which starts with the first letter and corresponds to each Chinese character aiming at the first keyword of the search information;
aiming at other keywords except the first keyword of the search information, constructing a fifth mapping between each Chinese character in the search field and the pinyin which starts with any letter and corresponds to each Chinese character;
constructing the second mapping based on the search information, the fourth mapping, and the fifth mapping.
6. The method of claim 5, wherein after constructing a fifth mapping between each Chinese character in the search field and the pinyin beginning with any letter corresponding to said each Chinese character, the method further comprises:
determining the starting position of the first keyword and the ending position of the other keywords as a third starting position and a third ending position when the starting position of the other keywords is less than or equal to the ending position of the first keyword;
and traversing the search field, determining the first target text according to the third starting position and the third ending position, and performing the first highlighting on the first target text.
7. The method of claim 4, wherein prior to converting the search field to pinyin, the method further comprises:
judging whether the characters in the search field are expressions or not;
converting the search field into pinyin under the condition that the characters in the search field are not expressions, and constructing a second mapping between each Chinese character in the search field and the pinyin corresponding to each Chinese character;
in the case where the character in the search field is an emoticon, no conversion is performed.
8. The method of claim 4, wherein converting the search field to pinyin and constructing a second mapping between each chinese character in the search field and the pinyin corresponding to the each chinese character comprises:
storing the full pinyin corresponding to the converted pinyin into a full pinyin set, and constructing a second mapping between each Chinese character in the search field and the full pinyin corresponding to each Chinese character; and/or the presence of a gas in the gas,
and storing the first letter of the Chinese character corresponding to the converted pinyin into a first letter set, and constructing a second mapping between each Chinese character in the search field and the first letter corresponding to each Chinese character.
9. A text search apparatus, comprising:
the acquisition module is used for acquiring search information input by a user;
the judging module is used for judging whether the searching mode of the searching information is accurate matching searching or fuzzy matching searching; wherein the fuzzy matching search means that a separator exists in the search information, and the exact matching search means that no separator exists in the search information;
the first display module is used for carrying out first highlight display on first target texts corresponding to the search information at the two ends of the separator under the condition that the search mode of the search information is the fuzzy matching search;
the second display module is used for carrying out second highlight display on a second target text corresponding to the search information under the condition that the search mode of the search information is the accurate matching search; wherein the second highlighting is in a different display manner than the first highlighting.
10. An electronic device, comprising: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating over the bus when the electronic device is operating, the machine-readable instructions when executed by the processor performing the text search method of any of claims 1 to 8.
11. A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out a text search method according to any one of claims 1 to 8.
CN202111613097.XA 2021-12-27 2021-12-27 Text search method and device, electronic equipment and storage medium Pending CN114296606A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111613097.XA CN114296606A (en) 2021-12-27 2021-12-27 Text search method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111613097.XA CN114296606A (en) 2021-12-27 2021-12-27 Text search method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114296606A true CN114296606A (en) 2022-04-08

Family

ID=80969949

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111613097.XA Pending CN114296606A (en) 2021-12-27 2021-12-27 Text search method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114296606A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1206883A (en) * 1997-07-01 1999-02-03 株式会社日立制作所 Structural file searching display method and device thereof
CN101178737A (en) * 2006-12-12 2008-05-14 北京搜狗科技发展有限公司 Method and system for publishing information related to internet key character
CN105956047A (en) * 2016-04-26 2016-09-21 北京橙鑫数据科技有限公司 Search method and device
CN111767451A (en) * 2020-01-15 2020-10-13 北京沃东天骏信息技术有限公司 Searching method, electronic equipment and computer readable storage medium
CN112380420A (en) * 2020-11-11 2021-02-19 Vidaa美国公司 Searching method and display device
CN113449069A (en) * 2020-03-26 2021-09-28 华为技术有限公司 Method for searching contact and related equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1206883A (en) * 1997-07-01 1999-02-03 株式会社日立制作所 Structural file searching display method and device thereof
CN101178737A (en) * 2006-12-12 2008-05-14 北京搜狗科技发展有限公司 Method and system for publishing information related to internet key character
CN105956047A (en) * 2016-04-26 2016-09-21 北京橙鑫数据科技有限公司 Search method and device
CN111767451A (en) * 2020-01-15 2020-10-13 北京沃东天骏信息技术有限公司 Searching method, electronic equipment and computer readable storage medium
CN113449069A (en) * 2020-03-26 2021-09-28 华为技术有限公司 Method for searching contact and related equipment
WO2021190309A1 (en) * 2020-03-26 2021-09-30 华为技术有限公司 Method for finding contact, and related device
CN112380420A (en) * 2020-11-11 2021-02-19 Vidaa美国公司 Searching method and display device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
单纯的心: "elasticsearch搜索中文分词理解、类似SQL语句中的_LIKE"条件的模糊搜索以及忽略大小写搜索_elasticsearch like 不分词", pages 1 - 16, Retrieved from the Internet <URL:https://blog.csdn.net/zhangqiang_accp/article/details/80422820> *
博客人: "如何用SQL语句实现精确搜索以及模糊搜索", pages 1 - 2, Retrieved from the Internet <URL:https://www.cnblogs.com/BoKeRen/archive/2006/03/08/345755.html> *

Similar Documents

Publication Publication Date Title
KR101116547B1 (en) Apparatus, method and system for a data entry interface
US9508028B2 (en) Converting text strings into number strings, such as via a touchscreen input
US7962857B2 (en) Automatic language selection for improving text accuracy
US9996586B2 (en) Method and device for searching for contact object, and storage medium
US10409820B2 (en) Semantic mapping of form fields
US8073258B2 (en) Using handwriting recognition in computer algebra
CN112559672B (en) Information detection method, electronic device and computer storage medium
CN111198936B (en) Voice search method and device, electronic equipment and storage medium
CN102063482A (en) High-efficiency contact searching method of handheld device
CN110096599B (en) Knowledge graph generation method and device
US20230252222A1 (en) Formatting module, system and method for formatting an electronic character sequence
WO2017216642A2 (en) Cross lingual search using multi-language ontology for text based communication
CN114638218A (en) Symbol processing method, device, electronic equipment and storage medium
CN107679122B (en) Fuzzy search method and terminal
CA2563233C (en) Automatic language selection for improving text accuracy
CN114296606A (en) Text search method and device, electronic equipment and storage medium
CN108628911B (en) Expression prediction for user input
CN113869046B (en) Method, device and equipment for processing natural language text and storage medium
WO2015075920A1 (en) Input assistance device, input assistance method and recording medium
CN114610955A (en) Intelligent retrieval method and device, electronic equipment and storage medium
CN109727591B (en) Voice search method and device
JP4004060B1 (en) Character search method
US20240104297A1 (en) Analysis of spreadsheet table in response to user input
JP4765107B2 (en) Character string input device and program
CN115270757A (en) Text recognition method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination