有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Google应用程序引擎搜索API赋予某些字段比其他字段更高的优先级

我只是在调查谷歌应用程序引擎的能力,对它的搜索api非常感兴趣。我喜欢你如何定义不同的字段来自动标记,并以不同的方式对搜索结果进行排序

我的问题是,你能以某种方式对结果进行排序,使某些字段比其他字段获得更高的优先级吗

例如:

有两个字段的文档,标题和正文。如果与标题匹配的搜索查询比与正文匹配的查询排名更高,这将是一个问题

这可能吗

干杯


共 (1) 个答案

  1. # 1 楼答案

    不幸的是,目前还不可能。从文件中:

    By default, search returns its results by descending rank. Also by default, the Search API sets the rank of each document to seconds since Jan 1st 2011. This results in the freshest documents being returned first. However, if you don’t need documents to be sorted by the time they were added, you can use rank for other purposes. Suppose you have a real estate application. What customers want most is sorting by price. For an efficient default sort, you could set the rank to the house price.

    If you need multiple sort orders such as price low-to-high and price high-to-low, you can create a separate index for each order. One index would have rank = price and the other rank = MAXINT-price (since rank must be positive).

    在您的用例中,您可以在一个查询中检索标题匹配的文档,然后在第二个查询中检索正文匹配的文档。显然,您可以指定不同的规则(甚至一组规则),例如:

    • 如果第一个查询返回的结果超过X个,则不要执行第二个查询
    • 按标题检索前20个文档,如果最后一个文档的日期小于A,则按正文检索前10个文档
    • 按标题检索最佳15个文档,按正文添加最佳5个文档

    等等。当然,规则取决于您的域以及您尝试对文档进行优先级排序的方式