CN107301215B - Search result caching method and device and search method and device - Google Patents

Search result caching method and device and search method and device Download PDF

Info

Publication number
CN107301215B
CN107301215B CN201710433653.2A CN201710433653A CN107301215B CN 107301215 B CN107301215 B CN 107301215B CN 201710433653 A CN201710433653 A CN 201710433653A CN 107301215 B CN107301215 B CN 107301215B
Authority
CN
China
Prior art keywords
search
target
result
cache
search result
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.)
Active
Application number
CN201710433653.2A
Other languages
Chinese (zh)
Other versions
CN107301215A (en
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.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and 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 Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201710433653.2A priority Critical patent/CN107301215B/en
Publication of CN107301215A publication Critical patent/CN107301215A/en
Application granted granted Critical
Publication of CN107301215B publication Critical patent/CN107301215B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a search result caching method and device and a search method and device, wherein the search result caching method comprises the following steps: obtaining the searched times of each search term in a first type of search terms within a preset time, wherein the first type of search terms are as follows: searching words searched within the preset time length in the searching words of the cached searching results; setting the cache expiration time of the search results of each search word in the first type of search words in sequence according to the sequence of the obtained searched times from large to small and the principle of time length from short to long; and determining whether to continue caching search results of each search word in a second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: and searching words of the search words of the cached search results, which are not searched within the preset time length. When the scheme provided by the embodiment of the invention is applied to the cache of the search result, the data cached locally is more comprehensive.

Description

Search result caching method and device and search method and device
Technical Field
The invention relates to the technical field of software, in particular to a search result caching method and device and a search method and device.
Background
With the continuous development of internet technology, the user access volume of each large website is increased explosively, and a caching technology is developed in order to solve the network bottleneck problem caused by large-scale data access. For example, a large number of users search for files such as video files, audio files, image files, etc. every day. In order to facilitate a user to obtain a search result quickly and stably, a search record with a large search amount generally needs to be cached, and the search record generally includes: the search engine comprises search words and search results, wherein the search results are searched according to the search words.
As the content that the network can provide is more and more rich, for a search word of a cached search record, the search result may change, so to improve the reliability of the cached search result, the cache server usually needs to set a cache expiration time, and after the cache expiration time is exceeded, the cached search result is deleted or marked as unusable, so that the search result cannot be obtained locally, and further, the search result corresponding to the search word needs to be obtained again and cached locally, thereby achieving the purpose of updating the local cache. Currently, a method for caching search results includes: and caching the search results of all the search terms for the same time, namely uniformly setting the cache expiration time.
However, in real life, the search volume of some search terms is very high, and the search results corresponding to the search terms are changed frequently, and such search terms may be called hot search terms; the search quantity of some search terms is low, and the search results corresponding to the search terms are basically unchanged, and such search terms may be called cold search terms. When the search result corresponding to the search word is updated, the cache server receives an update message for updating the search result corresponding to the search word, so that the cache server can frequently receive the update information for updating the search result corresponding to the popular search word; and the received update information for updating the search result corresponding to the cold search term is less. Because the same cache expiration time is set for the search results corresponding to the search terms with different search volumes by the existing cache server, the search results corresponding to the popular search terms are updated when the cache time is not reached, and then the cache time corresponding to the search results restarts timing, the search results can still be cached effectively locally; and for the search result corresponding to the cold search word, the cache expiration time may be up, and the corresponding update message is not obtained, so that the search result cached locally is deleted or identified as unavailable, resulting in incomplete data cached locally.
Disclosure of Invention
The embodiment of the invention aims to provide a search result caching method and device and a search method and device, so that cached data is more comprehensive. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a search result caching method, where the method includes:
obtaining the searched times of each search term in a first type of search terms within a preset time, wherein the first type of search terms are as follows: searching words searched within the preset time length in the searching words of the cached searching results;
setting the cache expiration time of the search results of each search word in the first type of search words in sequence according to the sequence of the obtained searched times from large to small and the principle of time length from short to long; and determining whether to continue caching search results of each search word in a second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: and searching words of the search words of the cached search results, which are not searched within the preset time length.
Optionally, the method further includes:
setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
Optionally, the search terms of the cached search results are: search results are cached in search terms in the first database; the method further comprises the following steps:
correspondingly caching each search word in the first type of search words and the effective caching duration of the search result of the search word to a second database;
and correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
Optionally, the sequentially setting the cache expiration durations of the search results of each search term in the first type of search terms according to the sequence of the obtained times of being searched from large to small and according to the principle that the durations are from short to long includes:
determining the grade of each search term in the first type of search terms according to a preset grading strategy and the obtained searched times, wherein the grading strategy is as follows: the more times of searching the search word, the higher the level of the search word is divided;
and sequentially setting the cache expiration durations of the search results of the search words in the first type of search words according to the sequence of the grades of the search words in the first type of search words from high to low and the principle that the durations are from short to long, wherein the cache expiration durations of the search results of the search words belonging to the same level are equal.
In a second aspect, an embodiment of the present invention further provides a search method, where the method includes:
obtaining a target search request, wherein the target search request carries target search words;
judging whether the search result of the target search word exists in the cached search results, wherein the cached search results are as follows: caching the search result according to the search result method;
if so, obtaining a final search result of the target search word according to the search result of the target search word in the cached search results.
Optionally, the obtaining a final search result of the target search term according to the search result of the target search term in the cached search results includes:
judging whether a target search result is set to be cached for an expired time or not, wherein the target search result is as follows: caching the search results of the target search words in the search results;
if the target cache expiration time is set, obtaining a first ratio of a target cache expiration time to a preset value, and judging whether the first ratio is greater than the target cache time, wherein the target cache expiration time is as follows: the cache expiration time for which the target search result has been set is: the cache duration of the target search result;
and if so, determining the target search result as a final search result of the target search word.
Optionally, if the search result of the target search term does not exist in the cached search results, or if the first ratio is less than or equal to the target caching duration, the method further includes:
forwarding the target search request to a search server, so that the search server performs searching according to the target search word to obtain a search result;
and receiving a search result sent by the search server, and determining the received search result as a final search result of the target search term.
Optionally, the method further includes:
and caching the received search results.
Optionally, in a case that the target search result is not set to the cache expiration time, the method further includes:
judging whether the effective caching duration of the target search result is set or not;
if the target cache effective duration is set, obtaining a second ratio of the target cache effective duration to a preset value, and judging whether the second ratio is greater than the target cache duration, wherein the target cache effective duration is as follows: the effective caching duration of the target search result is set;
if so, determining the target search result as a final search result of the target search word;
and if not, forwarding the target search request to a search server, so that the search server searches according to the target search word to obtain a search result, receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
Optionally, if the cache validity duration of the target search result is not set, the method further includes:
and determining the target search result as a final search result of the target search word.
In a third aspect, an embodiment of the present invention provides a search result caching apparatus, where the apparatus includes:
the first obtaining module is used for obtaining the searched times of each search term in a first type of search terms within a preset time length, wherein the first type of search terms are as follows: searching words searched within the preset time length in the searching words of the cached searching results;
the first setting module is used for sequentially setting the cache expiration time of the search results of each search term in the first type of search terms according to the principle that the time length is from short to long according to the sequence of the obtained searched times from large to small; and determining whether to continue caching search results of each search word in a second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: and searching words of the search words of the cached search results, which are not searched within the preset time length.
Optionally, the apparatus further comprises:
and the second setting module is used for setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
Optionally, the search terms of the cached search results are: search results are cached in search terms in the first database;
the device further comprises:
the first cache module is used for correspondingly caching each search word in the first type of search words and the cache effective duration of the search result of the search word to a second database;
and the second cache module is used for correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
Optionally, the first setting module includes:
a first determining sub-module, configured to determine, according to a preset ranking policy and according to the obtained number of times of being searched, a rank of each search term in the first category of search terms, where the ranking policy is: the more times of searching the search word, the higher the level of the search word is divided;
and the setting submodule is used for sequentially setting the cache expiration time lengths of the search results of the search words in the first type of search words according to the principle that the time lengths are from short to long according to the sequence of the grades of the search words in the first type of search words from high to low, wherein the cache expiration time lengths of the search results of the search words belonging to the same grade are equal.
In a fourth aspect, an embodiment of the present invention further provides a search apparatus, where the apparatus includes:
the second obtaining module is used for obtaining a target search request, wherein the target search request carries target search words;
a judging module, configured to judge whether a search result of the target search term exists in the cached search results, where the cached search result is: caching the search results according to the search result caching method;
and the third obtaining module is used for obtaining a final search result of the target search word according to the search result of the target search word in the cached search results when the judgment result of the judging module is yes.
Optionally, the third obtaining module includes:
the first judgment submodule is used for judging whether a target search result is set to have an expiration time, wherein the target search result is as follows: caching the search results of the target search words in the search results;
a first obtaining submodule, configured to, when a determination result of the first determining submodule is yes, obtain a first ratio of a target cache expiration time to a preset value, and determine whether the first ratio is greater than the target cache time, where the target cache expiration time is: the cache expiration time for which the target search result has been set is: the cache duration of the target search result;
and the second determining submodule is used for determining the target search result as the final search result of the target search word when the judgment result of the first obtaining submodule is yes.
Optionally, when the determination result of the determining module is negative, or when the determination result of the first obtaining sub-module is negative, the third obtaining module further includes:
the first transceiving submodule is used for forwarding the target search request to a search server so that the search server searches according to the target search word to obtain a search result; and receiving a search result sent by the search server, and determining the received search result as a final search result of the target search term.
Optionally, the third obtaining module further includes:
and the cache submodule is used for caching the received search results.
Optionally, in a case that the determination result of the first determining sub-module is negative, the third obtaining module further includes:
the second judgment submodule is used for judging whether the target search result is set with effective caching duration or not;
a second obtaining sub-module, configured to, when a determination result of the second determining sub-module is yes, obtain a second ratio of a target cache effective duration to a preset value, and determine whether the second ratio is greater than the target cache duration, where the target cache effective duration is: the effective caching duration of the target search result is set;
a third determining sub-module, configured to determine, when a determination result of the second obtaining sub-module is yes, the target search result as a final search result of the target search term;
and the second transceiving submodule forwards the target search request to the search server when the judgment result of the second obtaining submodule is negative, so that the search server searches according to the target search word to obtain a search result, receives the search result sent by the search server, and determines the received search result as the final search result of the target search word.
Optionally, when the determination result of the second determining sub-module is negative, the third obtaining module further includes:
and the fourth determining submodule is used for determining the target search result as a final search result of the target search word.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute the above-mentioned search result caching method.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the above-described search method.
In yet another aspect of the present invention, the present invention further provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the above-mentioned search result caching method.
In yet another aspect of the present invention, the present invention also provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the above-mentioned search method.
It can be seen that, when the technical scheme provided by the embodiment of the present invention is applied to the search result caching, for the search terms that have been searched within the preset time, the cache expiration time of the search result of the search term with the larger number of search times can be set to be shorter, the cache expiration time of the search result of the search term with the smaller number of search times is set to be longer, and for the search terms that have not been searched within the preset time, a preset elimination algorithm can be adopted to determine whether to continue caching the search results.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is an application scenario diagram of a search result caching method according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a search result caching method according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of a searching method according to an embodiment of the present invention;
FIG. 4 is a schematic diagram illustrating a search operation performed by a search method according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a search result caching apparatus according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a search apparatus according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of another electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
In order to solve the problem that cached data may not be comprehensive in the prior art, the embodiment of the invention discloses a search result caching method and device and electronic equipment.
Specifically, referring to fig. 1, fig. 1 is an application scenario diagram of a search result caching method according to an embodiment of the present invention. As shown in fig. 1, a search term collection central process 11 in a server obtains the number of times of being searched for each search term in a first type of search terms within a preset time period, and sequentially sets the cache expiration time of the search result of each search term in the first type of search terms according to the principle that the time length is from short to long according to the sequence of the obtained number of times of being searched for from large to small; and sending each cache expiration time to the service process 12, so that the service process 12 in the server caches the search results of each search word in the first type of search words according to each cache expiration time, and determines whether to continue caching the search results of each search word in the second type of search words by adopting a preset elimination algorithm, thereby realizing that the locally cached data is more comprehensive.
The following describes a search result caching method provided by an embodiment of the present invention in detail.
It should be noted that the search result caching method provided by the embodiment of the present invention is applied to an electronic device, wherein in a specific application, the electronic device may be a server or a terminal device, which is reasonable. In addition, the functional software for implementing the search result caching method provided by the embodiment of the invention may be special caching software, or may be a plug-in existing caching software or other software with a caching function.
Referring to fig. 2, fig. 2 is a schematic flowchart of a search result caching method according to an embodiment of the present invention, including the following steps:
s201, obtaining the searched times of each search term in the first type of search terms in a preset time length.
Wherein the first type of search term is: and searching the searched search words within a preset time length in the search words of the cached search results.
In practical application, the preset duration can be designed according to the requirements of users, and the embodiment of the invention does not limit the preset duration. For example, the preset time period may be 5 hours, 6 hours, 9 hours, 12 hours, and the like.
The following describes an embodiment of the present invention with a server as an execution subject, and the server is only a specific example of the present invention and is not limited to the present invention. In practical application, the execution subject can be set according to the needs of the user.
The embodiment of the present invention does not limit the manner in which the server obtains the number of times each search term in the first type of search terms is searched within a preset time period, for example, the manner may be: the searched times are obtained by the process statistics of a search term collection center (query _ collect _ center) in the server; alternatively, it may be: the number of times of search is counted by a server other than the server, and the result of the counting is periodically sent to the server.
Specifically, the process of counting the number of times of searching each search term (query) in the first type of search terms within a preset time period by the query _ collect _ center in the server may be: the service process receiving the search request in each server counts the query in time T (such as 0.5 hour) and the searched times of each query. And sending the statistical result to a query _ collect _ center in a message data mode, receiving the statistical result sent by each service process by the query _ collect _ center, summarizing each statistical result by taking the time T as a unit, and obtaining the searched times of the query in a preset time length, wherein the preset time length is the time T.
Further, the preset duration can be prolonged according to the user requirement, and the method for prolonging the preset duration is not limited in the embodiment of the invention. The method can be as follows: the time T may be directly extended as follows: the query _ collection _ center summarizes the obtained number of times that the query is searched in K time units, and uses the summarized result as the number of times that the query is searched in a preset time length, which can be seen that the preset time length is K time lengths T, for example, K is 24, T is 0.5 hour, and the preset time length is: and k, T, 24, 0.5, 12 hours, summarizing the searched times of the query in the past 12 hours, namely, obtaining the searched times of the query in the preset time duration.
In an embodiment, in order to improve the storage space utilization of the server, after the message data is sent, the service process receiving the search request may empty the statistical result, so that the query condition within the time T may be counted again.
S202, setting the cache expiration time of the search results of each search word in the first type of search words in sequence according to the sequence of the obtained searched times from large to small and the principle of time length from short to long; and determining whether to continue caching the search results of each search word in the second type of search words by adopting a preset elimination algorithm.
Wherein the second category of search terms is: and searching words of the search words of the cached search results, which are not searched within a preset time length.
It should be noted that, caching the expiration time means that after the time exceeds the time, the search result of the search term cached by the server will expire, and the expired search result will be identified as unavailable, and the server needs to obtain the search result of the search term again and cache the obtained search result in the local again, so as to achieve the purpose of updating the local cache. When the search result of the search word is cached again, the cache expiration duration of the search result can be reset by applying the embodiment of the invention.
According to the sequence of the obtained searched times from large to small, the cache expiration time of the search results of each search word in the first type of search words is sequentially set according to the principle that the time is from short to long, so that the search results of the search words with more searched times are shortened, and the cache expiration time is shortened; the smaller the number of times of being searched for, the longer the cache expiration time, for example, the first type of search word includes A, B, C, the number of times of being searched for of search word a > the number of times of being searched for of search word B > the number of times of being searched for of search word C, the cache expiration time of the search result of search word a < the cache expiration time of the search result of search word B < the cache expiration time of the search result of search word C is set.
It can be seen that for the popular search terms with a large number of searched times, the cache expiration time of the search results is short, so that the local cache results can be frequently updated, and the characteristic that the search results of the popular search terms need to be frequently updated is met; for the cold search terms with less searched times, the cache expiration time of the search results is longer, so that when the cache expiration time of the hot search terms is reached, the search of the cold search terms still does not exceed the cache expiration time, the search results of the cold search terms cached by the server are not marked as unavailable, the search results of each cold search term can be cached effectively, the search results of the cold search terms are not required to be updated, and the characteristic that the search results of the cold search terms are not required to be updated frequently is also met.
In practical application, the preset elimination algorithm may be: LRU (Least recently Used) algorithm, FIFO (First In First Out) algorithm, LFU (Least Frequently Used) algorithm, and the like. The embodiment of the invention does not limit the specific elimination algorithm. For example, the culling algorithm used is: the LRU algorithm eliminates data according to the historical access records of the data, and has the core idea that: if the data is accessed recently and the probability of being accessed in the future is higher, the step of determining whether to continue caching the search results of each search term in the second type of search terms by adopting a preset elimination algorithm may be: and aiming at the search results of each search word in the second type of search words, obtaining the latest used time of each search result, eliminating the search result with the latest used time being farthest from the current time, and continuously caching the rest search results.
Since the second category of search terms is: the search words of the cached search results are not searched within the preset time length, so the second type of search words can be regarded as cold search words, and the search results do not need to be updated frequently, therefore, for each search word in the second type of search words, the cache expiration time is not set, but a culling algorithm is used for determining whether to continue the search results, so that the cache time of the search results of the cold search words in the server can be prolonged, and the data cached by the server is more comprehensive.
It can be seen that, when the technical scheme provided by the embodiment of the present invention is applied to the search result caching, for the search terms that have been searched within the preset time, the cache expiration time of the search result of the search term with the larger number of search times can be set to be shorter, the cache expiration time of the search result of the search term with the smaller number of search times is set to be longer, and for the search terms that have not been searched within the preset time, a preset elimination algorithm can be adopted to determine whether to continue caching the search results.
Further, in order to save system resources and improve the utilization rate of the storage space of the server, specifically, the method may further include:
setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
Therefore, the server can delete the search results exceeding the effective caching duration in time, and the aims of reducing the occupation of unnecessary storage space and improving the utilization rate of the storage space of the server are fulfilled.
It should be noted that, after detecting that the search result of the search word is updated, the data update server will use the search word with the updated search result as a title (title), and then send the title to the server in a message manner, and identify the type of the message as: a first type. The first type name is not limited in the embodiment of the present invention. For example, the first type of name may be: the cache _ breaker _ redis, where the data update server may be any server different from the present server, and the embodiment of the present invention does not limit the type and configuration of the data update server.
After receiving the first type of message sent by the data updating server, the server searches whether the cache effective duration of the search result of the title is set according to the title, and if the cache effective duration of the search result of the title is set, the cache effective duration of the search result of the title is reset as follows: default time length, and setting the cache expiration time length of the search result of the title as: a default duration; the default time length may be set according to the user requirement, which is not limited in the embodiment of the present invention. For example, the expiration duration may be: 1 hour, 2 hours, 3 hours, etc.
If not, according to the sequence of the obtained searched times from large to small, the effective cache duration of the search results of each search word in the first type of search words is set in sequence according to the principle that the duration is from short to long, and the expiration duration of the cache of the search results of the title is set to be equal to the effective cache duration.
To facilitate data maintenance and management, the search terms of the cached search results may be: search results are cached in search terms in the first database; the method may further comprise:
caching each search word in the first type of search words and the effective caching duration of the search result of the search word to a second database correspondingly;
and correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
The first database, the second database and the third database are all Key-value databases, the Key-value database is a database for storing data by Key-value pairs, and a common Key-value database includes: redis databases, Memcache databases, Berkeley databases, and the like. The embodiment of the present invention does not limit the specific forms of the first database, the second database, and the third database. For example, the first database, the second database, and the third database may all be redis server databases, may all be MySQL server databases, may also be redis server databases, may also be MySQL server databases, and the like.
Because redis is a memory-type database and can provide good read-write operation to the outside, in a specific implementation manner, the first database, the second database, and the third database are redis server databases, and the names of the first database, the second database, and the third database are not limited in the embodiment of the present invention.
For example, the first database, the second database, and the third database are redis server databases, and the names are: and cache _ redis and query _ redis, and cache _ breaker _ redis, wherein the key of the cache _ redis is as follows: identification of search request, value is: searching results; the query _ redis is used for storing the cache valid time, wherein the key of the query _ redis is as follows: query, i.e., search term; the value is: the effective caching duration of the search result corresponding to the query; the cache _ breaker _ redis is used for storing the expiration time of the cache, namely the query needing to update the cache immediately, wherein the key of the cache _ breaker _ redis is as follows: query, value is: and the cache expiration time of the search result corresponding to the query is long.
In order to facilitate setting of the cache expiration time, specifically, the step of sequentially setting the cache expiration time of the search result of each search term in the first type of search terms according to the principle that the time duration is from short to long in the order that the obtained times to be searched are from large to small may be:
determining the grade of each search term in the first type of search terms according to a preset grading strategy and the obtained searched times, wherein the grading strategy is as follows: the more times of searching the search word, the higher the level of the search word is divided;
and sequentially setting the cache expiration durations of the search results of the search words in the first type of search words according to the sequence of the grades of the search words in the first type of search words from high to low and the principle that the durations are from short to long, wherein the cache expiration durations of the search results of the search words belonging to the same level are equal.
Illustratively, N levels are set, the search cache expiration time of each level is T1, T2 and T3 … … Tn (T1< T2< T3< … … Tn), the levels are divided according to the search times, the search times are L1, L2 and L3 … … Ln-1(L1> L2> L3 … … Ln-1), if the searched time of a certain query is larger than L1, the search cache expiration time of the query is set to be 1 level, and the cache expiration time of the search result of the query is set to be T1; if the cache time is less than or equal to L1 and is greater than L2, the cache time is set to be level 2, and the cache expiration time of the search result of the query is set to be T2; … …, and so on, if it is smaller than Ln-1, it is set to n level, and the cache expiration time of the search result of the query is set to Tn.
In practical application, the query _ collection _ center process of the server may execute the step of setting the cache expiration time, and send the set cache expiration time of the search result of each search term to each service process receiving the search request in the form of a message, and identify the message type as: in the second type, the name of the second type is not limited in the embodiment of the present invention, for example, the name of the second type may be: and the query _ redis type is analyzed into key _ value type data by the service process after receiving the second type of message, namely the search word in the second type of message and the cache expiration time of the search result of the search word are obtained and correspondingly stored.
In order to solve the problem of low cache hit rate caused by incomplete cached data in the prior art, the embodiment of the invention also discloses a searching method, a searching device and electronic equipment.
Specifically, the application scenarios of the search method provided by the embodiment of the present invention may be as follows: the method comprises the steps that a server obtains a target search request, wherein the target search request carries target search words; and judging whether the search result of the target search word exists in the search results cached by the server, wherein the cached search results are as follows: caching the search results according to the search result caching method; if so, obtaining the final search result of the target search word according to the search result of the target search word in the cached search results, and further performing cache search in the server because the cached data in the server is more comprehensive, thereby realizing the improvement of the cache hit rate.
A search method provided by an embodiment of the present invention is described in detail below.
It should be noted that the searching method provided by the embodiment of the present invention is applied to an electronic device, wherein in a specific application, the electronic device may be a server or a terminal device, which is reasonable. In addition, the functional software for implementing the search method provided by the embodiment of the invention may be special search software, or may be a plug-in existing search software or other software with a search function.
Referring to fig. 3, fig. 3 is a schematic flowchart of a searching method according to an embodiment of the present invention, including the following steps:
s301, obtaining a target search request.
And the target search request carries the target search word.
In practical applications, the target search request may be sent by the target client to request the server for the search result of the target search term. The target client may be any server except the server, and the model and category of the target client are not limited in the embodiment of the present invention.
S302, judging whether the cached search results have the search results of the target search word, wherein the cached search results are as follows: caching the search results according to the search result caching method; if so, S303 is executed.
For example, the cached search results are: if the search result cached in the cache _ redis does not have the search result of the target search word, the step of determining whether the search result of the target search word exists in the cached search result may be: taking the target search word as a keyword (key), judging whether a search result corresponding to the key value can be found in the cache _ redis, and if so, judging that the cached search result is the search result with the target search word; if not, the cached search results are judged to be the search results without the target search word.
S303, obtaining the final search result of the target search word according to the search result of the target search word in the cached search results.
Therefore, by applying the searching method provided by the embodiment of the invention, the cached searching results are as follows: the search results are cached according to the search result caching method, so that the cached data in the server are more comprehensive, cache searching is carried out in the server, and the cache hit rate can be improved.
Since the cache expiration time length may be set for the search result in the case that the search result of the target search term exists in the cached search results, and there is a case that the search result is identified as unavailable because the cache expiration time length is exceeded, which results in that the search result cannot be effectively obtained, in order to ensure that the final search result is: in a specific embodiment, the step of obtaining a final search result of the target search term according to the search result of the target search term in the cached search results may include the following steps:
the first step, judging whether the target search result is set to be cached for an overdue time or not, wherein the target search result is as follows: caching the search result of the target search word in the search result; if so, executing the second step;
and secondly, obtaining a first ratio of the target cache expiration time to a preset value, and judging whether the first ratio is greater than the target cache time, wherein the target cache expiration time is as follows: the cache expiration time for which the target search result is set is as follows: the cache duration of the target search result;
it can be understood that the preset value can be set according to user requirements, and the specific numerical value of the preset value is not limited in the embodiment of the present invention. For example, the preset values may be: 1. 2, 3, 4, 5, etc. The caching duration of the target search result, which is the existing time of the search result, may be a difference between the current time and the initial time of caching the search result.
And if so, determining the target search result as a final search result of the target search word.
It can be seen that, for the case that the target search result has set the cache expiration time, it is only when the first target ratio is greater than the target cache expiration time that the target search result can be effectively obtained, so that the target search result can be used as the final search result of the target search term.
Further, in order to ensure that the final search result of the target search term can still be effectively obtained when the search result of the target search term does not exist in the cached search results, or the first ratio is less than or equal to the target caching duration, the method may further include:
forwarding the target search request to a search server, so that the search server performs searching according to the target search word to obtain a search result;
and receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
It should be noted that the search server can perform a search according to the search terms and obtain a search result. Specifically, the process of searching by the search server according to the search term and obtaining the search result belongs to the prior art, and the embodiment of the present invention is not described herein again.
In order to improve the comprehensiveness of the server cache data, after receiving the search result sent by the search server, the method may further include:
and caching the received search results.
Specifically, the manner of caching the received search results may be: the received search results are written to the first database and a cache expiration time for the search results is not set.
Since the target search result may have the cache validity duration set when the target search result is not set with the cache expiration duration, and there is a case that the content of the target search result is deleted because the cache validity duration is exceeded, so that the target search result cannot be effectively acquired, to avoid this, it is ensured that the final search result is: the method can further comprise the following steps:
step A, judging whether the effective caching duration of a target search result is set; if so, executing step B;
step B, obtaining a second ratio of the target cache effective duration to a preset value, and judging whether the second ratio is greater than the target cache duration, wherein the target cache effective duration is as follows: the effective caching duration of the target search result is set; if yes, executing step C; if not, executing step D;
step C, determining a target search result as a final search result of the target search word;
and step D, forwarding the target search request to the search server, so that the search server searches according to the target search word to obtain a search result, receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
Further, if the cache validity duration of the target search result is not set, the method may further include:
and determining the target search result as a final search result of the target search word.
The following presents a simplified summary of an embodiment of the invention by way of a specific example.
The searching method provided by the embodiment of the invention is applied to certain electronic equipment, 3 redis servers are built in the electronic equipment, namely cache _ redis and query _ redis and cache _ breaker _ redis respectively, and the searching result is cached by adopting the searching result caching method. The cache _ redis serves as a first database and is used for storing video search result cache, and the query _ redis serves as a second database and is used for storing cache effective time with query and video search results corresponding to the query; and the cache _ breaker _ redis serves as a third database and is used for storing the query of the video search result which is updated immediately.
As shown in fig. 4, after receiving a target search request sent by a target client, the electronic device uses an identifier (request) of the target search request as a key to search a first database, and determines whether a search result corresponding to the identifier exists in search results cached in the first database;
and if the target search word does not exist, forwarding the target search request to a search server, so that the search server searches according to the target search word carried in the target search request and obtains a search result, and the electronic equipment receives the search result sent by the search server, determines the received search result as a final search result of the target search word, and writes the final search result into a first database.
If the cache expiration time length exists, the search result corresponding to the identification is taken as a target search result, namely the first database is considered to be hit, the target search word is taken as a key to search a third database, and whether the cache expiration time length corresponding to the target search word exists in the third database or not is judged;
if the third database has the cache expiration time corresponding to the target search word, the third database is hit, and then a first ratio C of the cache expiration time A of the target search result to a preset value B is obtained, namely C is A/B, and whether C is greater than the cache time M of the target search result is judged;
if so, determining the target search result as a final search result of the target search word, and sending the final search result to the target client; if the target search result is smaller than or equal to the target search result, forwarding the target search request to a search server, enabling the search server to search according to the target search word carried in the target search request, and obtaining a search result, so that the electronic device receives the search result sent by the search server, and determines the received search result as a final search result of the target search word, and further, the electronic device can send the final search result to a target client.
If the cache expiration time corresponding to the target search word does not exist in the third database, namely the third database is not hit, the target search word is used as a key to search the second database, and whether the cache effective time corresponding to the target search word exists in the second database or not is judged;
if the cache effective duration corresponding to the target search word exists in the second database, the second database is hit, further, a first ratio F of the cache effective duration E of the target search result to a preset value B is obtained, namely F is E/B, and whether F is larger than the cache duration M of the target search result is judged;
if so, determining the target search result as a final search result of the target search term; and sending the final search result to the target client.
If the cache validity duration corresponding to the target search word is less than or equal to or does not exist in the second database, that is, the cache validity duration does not hit the second database, the target search request is forwarded to the search server, so that the search server searches according to the target search word carried in the target search request and obtains a search result, and therefore the electronic device receives the search result sent by the search server and determines the received search result as a final search result of the target search word, and further, the electronic device can send the final search result to the target client.
Therefore, by applying the search device provided by the embodiment of the present invention, since the cached search results are: the search results are cached according to the search result caching method, so that the cached data in the server are more comprehensive, cache searching is carried out in the server, and the cache hit rate can be improved.
Corresponding to the above embodiment of the search result caching method, the embodiment of the present invention further provides a search result caching apparatus.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a search result caching apparatus according to an embodiment of the present invention, where the apparatus includes:
a first obtaining module 501, configured to obtain the number of times that each search term in a first type of search terms is searched within a preset time duration, where the first type of search terms is: searching words searched within a preset time length in the searching words of the cached searching results;
a first setting module 502, configured to sequentially set, according to the obtained sequence of the number of times to be searched, a cache expiration time of a search result of each search term in the first type of search terms according to a principle that the time is from short to long; and determining whether to continue caching search results of each search word in the second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: and searching words of the search words of the cached search results, which are not searched within a preset time length.
It can be seen that, when the device provided by the embodiment of the present invention is applied to cache search results, for search terms that have been searched within a preset time period, the cache expiration time of the search results of the search terms with a large number of search times may be set to be shorter, the cache expiration time of the search results of the search terms with a small number of search times may be set to be longer, and for search terms that have not been searched within the preset time period, a preset elimination algorithm may be employed to determine whether to continue to cache the search results.
Wherein, the device can also include:
and the second setting module is used for setting the cache effective time length of the search result of each search word in the first type of search words to be equal to the cache expiration time length of the search result of the search word.
The search terms of the cached search results are: search results are cached in search terms in the first database; the apparatus may further include:
the first cache module is used for correspondingly caching each search word in the first type of search words and the cache effective duration of the search result of the search word to a second database;
the second cache module is used for correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database;
the first setting module 502 includes:
the first determining submodule is used for determining the grade of each search term in the first type of search terms according to a preset grading strategy and the obtained searched times, wherein the grading strategy is as follows: the more times of searching the search word, the higher the level of the search word is divided;
and the setting submodule is used for sequentially setting the cache expiration time lengths of the search results of the search words in the first type of search words according to the principle that the time lengths are from short to long according to the sequence of the grades of the search words in the first type of search words from high to low, wherein the cache expiration time lengths of the search results of the search words belonging to the same grade are equal.
Corresponding to the above search method embodiment, the embodiment of the present invention further provides a search apparatus.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a search apparatus according to an embodiment of the present invention, where the apparatus includes:
a second obtaining module 601, configured to obtain a target search request, where the target search request carries a target search term;
the determining module 602 is configured to determine whether a search result of the target search term exists in the cached search results, where the cached search result is: caching the search results according to the search result caching method;
a third obtaining module 603, configured to, when the determination result of the determining module 602 is yes, obtain a final search result of the target search term according to the search result of the target search term in the cached search results.
Therefore, by applying the search device provided by the embodiment of the present invention, since the cached search results are: the search results are cached according to the search result caching method, so that the cached data in the server are more comprehensive, cache searching is carried out in the server, and the cache hit rate can be improved.
The third obtaining module 603 includes:
the first judgment submodule is used for judging whether the target search result is set with the cache expiration time, wherein the target search result is as follows: caching the search result of the target search word in the search result;
the first obtaining submodule is used for obtaining a first ratio of the expiration time of the target cache to the preset value when the judgment result of the first judging submodule is yes, and judging whether the first ratio is greater than the expiration time of the target cache, wherein the expiration time of the target cache is as follows: the set cache expiration time of the target search result is as follows: the cache duration of the target search result;
and the second determining submodule is used for determining the target search result as the final search result of the target search word when the judgment result of the first obtaining submodule is yes.
When the determination result of the determining module 602 is negative, or when the determination result of the first obtaining sub-module is negative, the third obtaining module 603 further includes:
the first transceiving submodule is used for forwarding the target search request to a search server so that the search server searches according to the target search word to obtain a search result; and receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
Wherein, the third obtaining module 603 further includes:
and the cache submodule is used for caching the received search results.
In a case that the determination result of the first determining submodule is negative, the third obtaining module 603 further includes:
the second judgment submodule is used for judging whether the target search result is set with effective caching duration or not;
a second obtaining submodule, configured to, when a determination result of the second determining submodule is yes, obtain a second ratio of the target cache effective duration to the preset value, and determine whether the second ratio is greater than the target cache duration, where the target cache effective duration is: the effective caching duration of the target search result is set;
the third determining submodule is used for determining the target search result as the final search result of the target search word when the judgment result of the second obtaining submodule is yes;
and the second transceiving submodule forwards the target search request to the search server when the judgment result of the second obtaining submodule is negative, so that the search server searches according to the target search word to obtain a search result, receives the search result sent by the search server, and determines the received search result as the final search result of the target search word.
When the determination result of the second determining submodule is negative, the third obtaining module 603 further includes:
and the fourth determining submodule is used for determining the target search result as the final search result of the target search word.
An embodiment of the present invention further provides an electronic device, as shown in fig. 7, including a processor 701, a communication interface 702, a memory 703 and a communication bus 704, where the processor 701, the communication interface 702, and the memory 703 complete mutual communication through the communication bus 704,
a memory 703 for storing a computer program;
the processor 701 is configured to implement the search result caching method provided in the embodiment of the present invention when executing the program stored in the memory 703, and specifically, the search result caching method includes the following steps:
obtaining the searched times of each search word in the first type of search words within a preset time;
setting the cache expiration time of the search results of each search term in the first type of search terms in sequence according to the sequence of the obtained searched times from large to small and the principle of time length from short to long; and determining whether to continue caching the search results of each search word in the second type of search words by adopting a preset elimination algorithm.
Optionally, the method further includes:
setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
Optionally, the search terms of the cached search results are: search results are cached in search terms in the first database; the method further comprises the following steps:
caching each search word in the first type of search words and the effective caching duration of the search result of the search word to a second database correspondingly;
and correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
Optionally, the setting, according to the obtained sequence of the searched times from large to small, the cache expiration time of the search result of each search term in the first type of search terms in turn according to the principle that the time length is from short to long includes:
determining the grade of each search word in the first type of search words according to a preset grading strategy and the obtained searched times;
and sequentially setting the cache expiration durations of the search results of the search words in the first type of search words according to the sequence of the grades of the search words in the first type of search words from high to low and the principle that the durations are from short to long, wherein the cache expiration durations of the search results of the search words belonging to the same level are equal.
An embodiment of the present invention further provides an electronic device, as shown in fig. 8, which includes a processor 801, a communication interface 802, a memory 803, and a communication bus 804, where the processor 801, the communication interface 802, and the memory 803 complete mutual communication through the communication bus 804,
a memory 803 for storing a computer program;
the processor 801 is configured to implement the search method provided in the embodiment of the present invention when executing the program stored in the memory 803, and specifically, the search method includes the following steps:
obtaining a target search request;
judging whether a search result of the target search word exists in the cached search results;
if so, obtaining a final search result of the target search word according to the search result of the target search word in the cached search results.
Optionally, obtaining a final search result of the target search term according to the search result of the target search term in the cached search results, where the obtaining includes:
judging whether the target search result is set to have the cache expiration time or not;
if the first ratio is set, obtaining a first ratio of the expiration time of the target cache to a preset value, and judging whether the first ratio is greater than the target cache time;
if so, the target search result is determined to be the final search result for the target search term.
Optionally, if the search result of the target search term does not exist in the cached search results, or if the first ratio is less than or equal to the target caching duration, the method further includes:
forwarding the target search request to a search server, so that the search server performs searching according to the target search word to obtain a search result;
and receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
Optionally, the method further includes:
and caching the received search results.
Optionally, in a case that the target search result is not set to the cache expiration time, the method further includes:
judging whether the target search result is set with effective caching duration or not;
if the target cache duration is set, obtaining a second ratio of the target cache effective duration to a preset value, and judging whether the second ratio is greater than the target cache duration;
if so, determining the target search result as a final search result of the target search term;
and if not, forwarding the target search request to a search server, so that the search server searches according to the target search word to obtain a search result, receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
Optionally, if the cache validity duration of the target search result is not set, the method further includes:
and determining the target search result as a final search result of the target search word.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a network Processor (Ne word Processor, NP), and the like; the Integrated Circuit 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, a discrete Gate or transistor logic device, or a discrete hardware component.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute the above-mentioned search result caching method.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the above-described search method.
In yet another aspect of the present invention, the present invention further provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the above-mentioned search result caching method.
In yet another aspect of the present invention, the present invention also provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the above-mentioned search method.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the embodiments of the apparatus and the electronic device, since they are substantially similar to the embodiments of the method, the description is simple, and the relevant points can be referred to only in the partial description of the embodiments of the method.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (20)

1. A method for caching search results, the method comprising:
obtaining the searched times of each search term in a first type of search terms within a preset time, wherein the first type of search terms are as follows: searching words searched within the preset time length in the searching words of the cached searching results;
setting the cache expiration time of the search results of each search word in the first type of search words in sequence according to the sequence of the obtained searched times from large to small and the principle of time length from short to long; and determining whether to continue caching search results of each search word in a second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: searching words in the search words with cached search results are not searched within the preset time, the preset elimination algorithm is to obtain the latest used time of each search result aiming at the search results of each search word in the second type of search words, eliminate the search result with the latest used time being farthest from the current time, and continue to cache the rest search results, wherein each search word in the second type of search words is not set with cache expiration time;
the setting of the cache expiration time of the search results of each search term in the first type of search terms in sequence according to the obtained sequence of the searched times from large to small and according to the principle that the time length is from short to long comprises the following steps:
determining the grade of each search term in the first type of search terms according to a preset grading strategy and the obtained searched times, wherein the grading strategy is as follows: the more times of searching the search word, the higher the level of the search word is divided;
and sequentially setting the cache expiration durations of the search results of the search words in the first type of search words according to the sequence of the grades of the search words in the first type of search words from high to low and the principle that the durations are from short to long, wherein the cache expiration durations of the search results of the search words belonging to the same level are equal.
2. The method of claim 1, further comprising:
setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
3. The method of claim 2,
the search terms of the cached search results are: search results are cached in search terms in the first database;
the method further comprises the following steps:
correspondingly caching each search word in the first type of search words and the effective caching duration of the search result of the search word to a second database;
and correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
4. A method of searching, the method comprising:
obtaining a target search request, wherein the target search request carries target search words;
judging whether the search result of the target search word exists in the cached search results, wherein the cached search results are as follows: search results cached according to the method of any of claims 1-3;
if so, obtaining a final search result of the target search word according to the search result of the target search word in the cached search results.
5. The method of claim 4, wherein obtaining a final search result of the target search term according to the search result of the target search term in the cached search results comprises:
judging whether a target search result is set to be cached for an expired time or not, wherein the target search result is as follows: caching the search results of the target search words in the search results;
if the target cache expiration time is set, obtaining a first ratio of a target cache expiration time to a preset value, and judging whether the first ratio is greater than the target cache time, wherein the target cache expiration time is as follows: the cache expiration time for which the target search result has been set is: the cache duration of the target search result;
and if so, determining the target search result as a final search result of the target search word.
6. The method of claim 5, wherein if the search results for the target search term are not present in the cached search results, or if the first ratio is less than or equal to the target caching duration, the method further comprises:
forwarding the target search request to a search server, so that the search server performs searching according to the target search word to obtain a search result;
and receiving a search result sent by the search server, and determining the received search result as a final search result of the target search term.
7. The method of claim 6, further comprising:
and caching the received search results.
8. The method of any of claims 5-7, wherein in the event that the target search result is not set to a cache expiration duration, the method further comprises:
judging whether the effective caching duration of the target search result is set or not;
if the target cache effective duration is set, obtaining a second ratio of the target cache effective duration to a preset value, and judging whether the second ratio is greater than the target cache duration, wherein the target cache effective duration is as follows: the effective caching duration of the target search result is set;
if so, determining the target search result as a final search result of the target search word;
and if not, forwarding the target search request to a search server, so that the search server searches according to the target search word to obtain a search result, receiving the search result sent by the search server, and determining the received search result as a final search result of the target search word.
9. The method of claim 8, wherein if the target search result is not set to a cache validity duration, the method further comprises:
and determining the target search result as a final search result of the target search word.
10. A search result caching apparatus, the apparatus comprising:
the first obtaining module is used for obtaining the searched times of each search term in a first type of search terms within a preset time length, wherein the first type of search terms are as follows: searching words searched within the preset time length in the searching words of the cached searching results;
the first setting module is used for sequentially setting the cache expiration time of the search results of each search term in the first type of search terms according to the principle that the time length is from short to long according to the sequence of the obtained searched times from large to small; and determining whether to continue caching search results of each search word in a second type of search words by adopting a preset elimination algorithm, wherein the second type of search words is as follows: searching words in the search words with cached search results are not searched within the preset time, the preset elimination algorithm is to obtain the latest used time of each search result aiming at the search results of each search word in the second type of search words, eliminate the search result with the latest used time being farthest from the current time, and continue to cache the rest search results, wherein each search word in the second type of search words is not set with cache expiration time;
the first setup module includes:
a first determining sub-module, configured to determine, according to a preset ranking policy and according to the obtained number of times of being searched, a rank of each search term in the first category of search terms, where the ranking policy is: the more times of searching the search word, the higher the level of the search word is divided;
and the setting submodule is used for sequentially setting the cache expiration time lengths of the search results of the search words in the first type of search words according to the principle that the time lengths are from short to long according to the sequence of the grades of the search words in the first type of search words from high to low, wherein the cache expiration time lengths of the search results of the search words belonging to the same grade are equal.
11. The apparatus of claim 10, further comprising:
and the second setting module is used for setting the effective cache duration of the search result of each search word in the first type of search words to be equal to the overdue cache duration of the search result of the search word.
12. The apparatus of claim 11,
the search terms of the cached search results are: search results are cached in search terms in the first database;
the device further comprises:
the first cache module is used for correspondingly caching each search word in the first type of search words and the cache effective duration of the search result of the search word to a second database;
and the second cache module is used for correspondingly caching each search word in the first type of search words and the cache expiration time of the search result of the search word to a third database.
13. A search apparatus, characterized in that the apparatus comprises:
the second obtaining module is used for obtaining a target search request, wherein the target search request carries target search words;
a judging module, configured to judge whether a search result of the target search term exists in the cached search results, where the cached search result is: search results cached according to the method of any of claims 1-3;
and the third obtaining module is used for obtaining a final search result of the target search word according to the search result of the target search word in the cached search results when the judgment result of the judging module is yes.
14. The apparatus of claim 13, wherein the third obtaining module comprises:
the first judgment submodule is used for judging whether a target search result is set to have an expiration time, wherein the target search result is as follows: caching the search results of the target search words in the search results;
a first obtaining submodule, configured to, when a determination result of the first determining submodule is yes, obtain a first ratio of a target cache expiration time to a preset value, and determine whether the first ratio is greater than the target cache time, where the target cache expiration time is: the cache expiration time for which the target search result has been set is: the cache duration of the target search result;
and the second determining submodule is used for determining the target search result as the final search result of the target search word when the judgment result of the first obtaining submodule is yes.
15. The apparatus according to claim 14, wherein when the determination result of the determining module is negative, or when the determination result of the first obtaining sub-module is negative, the third obtaining module further comprises:
the first transceiving submodule is used for forwarding the target search request to a search server so that the search server searches according to the target search word to obtain a search result; and receiving a search result sent by the search server, and determining the received search result as a final search result of the target search term.
16. The apparatus of claim 15, wherein the third obtaining module further comprises:
and the cache submodule is used for caching the received search results.
17. The apparatus according to any one of claims 14-16, wherein in case that the judgment result of the first judgment sub-module is no, the third obtaining module further comprises:
the second judgment submodule is used for judging whether the target search result is set with effective caching duration or not;
a second obtaining sub-module, configured to, when a determination result of the second determining sub-module is yes, obtain a second ratio of a target cache effective duration to a preset value, and determine whether the second ratio is greater than the target cache duration, where the target cache effective duration is: the effective caching duration of the target search result is set;
a third determining sub-module, configured to determine, when a determination result of the second obtaining sub-module is yes, the target search result as a final search result of the target search term;
and the second transceiving submodule forwards the target search request to the search server when the judgment result of the second obtaining submodule is negative, so that the search server searches according to the target search word to obtain a search result, receives the search result sent by the search server, and determines the received search result as the final search result of the target search word.
18. The apparatus of claim 17, wherein when the determination result of the second determining sub-module is negative, the third obtaining module further comprises:
and the fourth determining submodule is used for determining the target search result as a final search result of the target search word.
19. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 3 when executing a program stored in the memory.
20. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 4 to 9 when executing a program stored in the memory.
CN201710433653.2A 2017-06-09 2017-06-09 Search result caching method and device and search method and device Active CN107301215B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710433653.2A CN107301215B (en) 2017-06-09 2017-06-09 Search result caching method and device and search method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710433653.2A CN107301215B (en) 2017-06-09 2017-06-09 Search result caching method and device and search method and device

Publications (2)

Publication Number Publication Date
CN107301215A CN107301215A (en) 2017-10-27
CN107301215B true CN107301215B (en) 2020-12-18

Family

ID=60135885

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710433653.2A Active CN107301215B (en) 2017-06-09 2017-06-09 Search result caching method and device and search method and device

Country Status (1)

Country Link
CN (1) CN107301215B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108470043A (en) * 2018-02-27 2018-08-31 阿里巴巴集团控股有限公司 A kind of acquisition methods and device of business result
CN110598138A (en) * 2018-06-12 2019-12-20 北京京东尚科信息技术有限公司 Cache-based processing method and device
CN108810139B (en) * 2018-06-12 2021-02-02 电子科技大学 Monte Carlo tree search-assisted wireless caching method
CN109190070B (en) * 2018-08-01 2021-10-15 北京奇艺世纪科技有限公司 Data processing method, device and system and application server
CN110472004B (en) * 2019-08-23 2022-07-08 国网山东省电力公司电力科学研究院 Method and system for multi-level cache management of scientific and technological information data
CN110489063B (en) * 2019-08-27 2023-12-19 北京奇艺世纪科技有限公司 Method and device for setting cache expiration time, electronic equipment and storage medium
CN112316416A (en) * 2020-11-13 2021-02-05 网易(杭州)网络有限公司 Data searching method and device, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1484796A (en) * 2000-11-17 2004-03-24 �Ҵ���˾ User specified parallel data fetching for optimized web access
CN101901249A (en) * 2009-05-26 2010-12-01 复旦大学 Text-based query expansion and sort method in image retrieval
CN103064852A (en) * 2011-10-20 2013-04-24 阿里巴巴集团控股有限公司 Website statistical information processing method and website statistical information processing system
CN104504158A (en) * 2015-01-19 2015-04-08 浪潮(北京)电子信息产业有限公司 Memory caching method and device for rapidly updating business
CN106708833A (en) * 2015-08-03 2017-05-24 腾讯科技(深圳)有限公司 Position information-based data obtaining method and apparatus

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8688674B2 (en) * 2008-02-14 2014-04-01 Beats Music, Llc Fast search in a music sharing environment
CN103729353B (en) * 2012-10-10 2017-05-31 阿里巴巴集团控股有限公司 The searching method and server of ticket information
CN103336849B (en) * 2013-07-24 2016-09-21 昆明理工大学 A kind of database retrieval system improves the method and device of retrieval rate
CN104794191B (en) * 2015-04-16 2018-05-15 北京京东尚科信息技术有限公司 A kind of method and apparatus for air ticket data update
US10650067B2 (en) * 2015-08-13 2020-05-12 Samsung Electronics Co., Ltd. Cloud-enabled architecture for on-demand native application crawling
CN106682197B (en) * 2016-12-29 2020-02-11 北京奇艺世纪科技有限公司 Search cache updating method and device
CN106649139B (en) * 2016-12-29 2020-01-10 北京奇虎科技有限公司 Data elimination method and device based on multiple caches

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1484796A (en) * 2000-11-17 2004-03-24 �Ҵ���˾ User specified parallel data fetching for optimized web access
CN101901249A (en) * 2009-05-26 2010-12-01 复旦大学 Text-based query expansion and sort method in image retrieval
CN103064852A (en) * 2011-10-20 2013-04-24 阿里巴巴集团控股有限公司 Website statistical information processing method and website statistical information processing system
CN104504158A (en) * 2015-01-19 2015-04-08 浪潮(北京)电子信息产业有限公司 Memory caching method and device for rapidly updating business
CN106708833A (en) * 2015-08-03 2017-05-24 腾讯科技(深圳)有限公司 Position information-based data obtaining method and apparatus

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
" 基于Nginx的在线教育平台架构优化研究";张康;《中国优秀硕士学位论文全文数据库 信息科技辑 》;20170315(第3期);I139-508页 *

Also Published As

Publication number Publication date
CN107301215A (en) 2017-10-27

Similar Documents

Publication Publication Date Title
CN107301215B (en) Search result caching method and device and search method and device
CN109299144B (en) Data processing method, device and system and application server
WO2021068488A1 (en) Blockchain-based log processing method and apparatus, computer device, and storage medium
AU2017389607B2 (en) Method and apparatus for updating search cache
KR20070117874A (en) Method for active controlling cache in mobile network system, recording medium and system thereof
CN109450969B (en) Method and device for acquiring data from third-party data source server and server
CN111782692B (en) Frequency control method and device
CN106649313B (en) Method and apparatus for processing cache data
CN106681995B (en) Data caching method, data query method and device
CN111782707A (en) Data query method and system
CN111381988A (en) Request speed limiting method and device, electronic equipment and storage medium
CN111597259A (en) Data storage system, method, device, electronic equipment and storage medium
JP5272428B2 (en) Predictive cache method for caching information with high access frequency in advance, system thereof and program thereof
CN108763458B (en) Content characteristic query method, device, computer equipment and storage medium
CN114138840A (en) Data query method, device, equipment and storage medium
CN113726341A (en) Data processing method and device, electronic equipment and storage medium
CN112597231A (en) Data processing method and device
WO2020199029A1 (en) Data processing method and apparatus therefor
CN103365897A (en) Fragment caching method supporting Bigtable data model
CN109951811B (en) Service number short message monitoring method, device and system
CN111444184A (en) Data storage method, storage scheduling server, electronic device and storage medium
CN110493643B (en) Video storage method and device
JP2020095434A (en) Communication device, communication method, and communication program
CN111427914B (en) Data acquisition method and device
CN113660277B (en) Crawler-resisting method based on multiplexing embedded point information and processing terminal

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
GR01 Patent grant
GR01 Patent grant