Chloe
Chloe

Reputation: 26264

How do I use AppEngine and Search API to search by the DocId?

I need to search by DocId because I have files in Drive that I am also searching, and need to merge the results. I also need to limit the results by other fields. I tried this query:

INFO: Searching with query:  DocId:(4842249208725504 5405199162146816 5510752278413312 5581121022590976 5827411627212800) 

However it found 0 results even though they exist. I also tried doc_id and id.

    log.info("Searching with query: " + q);
    try {
        Results<ScoredDocument> results = getIndex().search(q);

I will also need to filter by other fields, ex:

DocId:(123456789) year:(2012)

The other fields work during searching, but not DocId. In the Admin interface, it shows DocId as being one of the fields! http://localhost:8888/_ah/admin/search?subsection=searchIndex...

Imgur

Upvotes: 2

Views: 226

Answers (2)

Katedral Pillon
Katedral Pillon

Reputation: 14844

Inside each document have an atom field named docId and in that field pass in the doc id. Then you can do a search per normal (as you suggested).

Here is a quote from the documentation

While it is convenient to create readable, meaningful unique document identifiers, you cannot include the doc_id in a search. Consider this scenario: You have an index with documents that represent parts, using the part's serial number as the doc_id. It will be very efficient to retrieve the document for any single part, but it will be impossible to search for a range of serial numbers along with other field values, such as purchase date. Storing the serial number in an atom field solves the problem.

Upvotes: 3

Paul Collingwood
Paul Collingwood

Reputation: 9116

If you know the doc ID in advance, rather then searching for it why not just get it directly?

doc = index.get("AZ125")

https://developers.google.com/appengine/docs/python/search/#Python_Retrieving_documents_by_doc_ids

Upvotes: 1

Related Questions