Saad Attieh
Saad Attieh

Reputation: 1486

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. 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

Upvotes: 0

Views: 139

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

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. 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).

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), e.g.:

  • if the first query returns more than X results, do not do the second query
  • 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
  • retrieve the best 15 documents by title and add the best 5 documents by body

and so on. The rules, of course, depend on your domain and the way you try to prioritize (rank) the documents.

Upvotes: 2

Related Questions