简体   繁体   English

Google App Engine搜索API赋予某些字段比其他字段更高的优先级

[英]Google App Engine Search API give certain fields more priority over others

Just investigating the abilities of Google App Engine and very interested in its search api. 只是研究Google App Engine的功能,并且对其搜索api非常感兴趣。 I love how you can define different fields to be automatically tokenised and sort the search results in different ways. 我喜欢您如何定义要自动标记的不同字段并以不同方式对搜索结果进行排序。

My question is can you have the results sorted in a way such that certain fields get more priority then others? 我的问题是,您能否以某种方式对结果进行排序,以使某些字段比其他字段具有更高的优先级?

Example: 例:

A document with two fields, title and body. 具有两个字段的文档,标题和正文。 It would be if search queries that matched titles were more highly ranked than querys that match the body. 如果匹配标题的搜索查询比匹配正文的查询的排名更高。

Is this possible? 这可能吗?

Cheers 干杯

Unfortunately, it's not possible at the moment. 不幸的是,目前尚不可能。 From the documentation: 从文档中:

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. 同样默认情况下,Search API将每个文档的排名设置为自2011年1月1日起的秒数。这将导致首先返回最新鲜的文档。 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). 一个指数的排名为价格,而另一个指数为MAXINT-price(因为排名必须为正)。

In your use case, you can retrieve documents that have a match in their title in one query, and then retrieve documents with a match in their body in a second query. 在您的用例中,您可以在一个查询中检索标题匹配的文档,然后在第二个查询中检索正文匹配的文档。 Obviously, you can specify different rules (or even a set of rules), eg: 显然,您可以指定不同的规则(甚至一组规则),例如:

  • if the first query returns more than X results, do not do the second query 如果第一个查询返回的结果超过X个,请不要执行第二个查询
  • retrieve the first 20 documents by title, and if the date of the last document is less than A, retrieve the first 10 documents by body 按标题检索前20个文档,如果最后一个文档的日期小于A,则按正文检索前10个文档
  • retrieve the best 15 documents by title and add the best 5 documents by body 按标题检索最佳的15个文档,并按正文添加最佳的5个文档

and so on. 等等。 The rules, of course, depend on your domain and the way you try to prioritize (rank) the documents. 当然,规则取决于您的域以及您尝试对文档进行优先级排序(排序)的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM