Question

I'm trying to search indexed documents with this query, and it is turning up 0 results, even though the items exist. Why?

Keyword search on the description field and search by year works. 'sbu' is an atom field.

Log

INFO: Searching with query:  year:( 2013  )  sbu:(Special Bictums Unit) 
Oct 31, 2013 8:36:17 PM com.mwv.pic.service.SearchService search
INFO: results.size:0

INFO: Searching with query:  year:( 2013  )  sbu:("Special Bictums Unit") 
INFO: results.size:0

INFO: Searching with query:  sbu:("Special Bictums Unit") 
INFO: results.size:0

INFO: Searching with query:  sbu:"Special Bictums Unit" 
INFO: results.size:0

INFO: Searching with query:  year:( 2013  ) 
INFO: results.size:3

Code

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

Indexes in Admin Console

Imgur

Reference

https://developers.google.com/appengine/docs/java/search/query_strings

Indexing values

Nov 04, 2013 5:55:44 PM com.mwv.pic.service.SearchService indexStudy
INFO: add field sbu:'Special Bictums Unit'

builder.addField(Field.newBuilder().setName("sbu").setAtom(sbu));
log.info("add field sbu:'"+sbu+"'");
Was it helpful?

Solution

Searching for atom fields with blanks in them currently does not work on the Java dev server; but I believe it works in production, and on the Python dev server.

The recommended query syntax is: [sbu:"Special Bictums Unit"] (without the square brackets).

OTHER TIPS

I'm not familiar with the platform, but the documentation seems to suggest that brackets are only included around values if you are using OR or AND to search for multiple values. Try using year: 2013 instead of year:( 2013 ), or sbu: "Special Bictums Unit" instead of sbu:("Special Bictums Unit").

Also, there seem to be additional spaces around your search queries. I don't suspect that is a problem, but you can call trim() on the string to return a version without these, i.e. q = q.trim();.

From the documentation:

If you are searching for an atom field that contains whitespace or special characters, enclose the value in quotes.

To search for an ampersand, it would seem you would need to enclose it in quotes, e.g. "&". However, you cannot search for just a part of an atom field:

The only valid relational operator for atom fields is the equality operator. The complete contents of an atom field must match the query value.

If you want to find all fields containing an ampersand somewhere in them, they must be text or HTML fields. Presumably the rule about special characters and quotes applies to these as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top