I found a possible clue.

I expanded

       result = database_matches_to_list(database_document.select(query, \
         orderBy=to_order_by))

to:

        database_matches = database_document.select(query, orderBy = \
          to_order_by)
        debug_log("Raw search results: " + str(database_matches))
        result = database_matches_to_list(database_matches)
        debug_log("Search results: " + str(result))

The output suggests that database_matches is not a database match but a built-up SQL query:

Raw search results: SELECT database_document.id, database_document.date_last_modified, database_document.date_last_viewed, database_document.field_permanent_id, database_document.field_text, database_document.field_title, database_document.field_version, database_document.relative_filename, database_document.section, database_document.text, database_document.tokenized FROM database_document WHERE EXISTS (SELECT database_document_keyword.id FROM database_document, database_document_keyword WHERE ((database_document.id = database_document_keyword.document_id) AND (database_document_keyword.word = 'test'))) ORDER BY database_document.date_last_viewed at 1132326661.36
Search results: [] at 1132326661.38

Is there anything I should be adding to get the results of the query I've built up?

On 11/18/05, Jonathan Hayward http://JonathansCorner.com < jonathan.hayward@pobox.com> wrote:


On 11/17/05, Ian Bicking <ianb@colorstudy.com> wrote:
"Jonathan Hayward http://JonathansCorner.com" wrote:
> database_matches_to_list creates a list of row objects, and is always
> returning 0 results (I created documents containing the word "test",
> and then searched for "test").
>
> Is there a reason I should be getting 0 results?

When this sort of thing happens, it's usually useful to see the SQL
queries leading up.  Append ?debug=t to your database URI, or just do
._connection.debug = True, and it will start printing out the SQL
queries as it runs them.

When I did this, it appeared that no SQL was being executed from the search. I had debugging output like:

       debug_log(tokenize(string.lower(get_cgi("query"))))

This is the tail end of the debugging output after it initialized and ran two queries for the word "test":

[SQLObject debug output]
 1/QueryOne:  SELECT document_filename, document_id, word, frequency, total FROM database_document_keyword WHERE id = 10152
 1/QueryR  :  SELECT document_filename, document_id, word, frequency, total FROM database_document_keyword WHERE id = 10152
 1/COMMIT  :  auto
['test'] at 1132301976.82
test at 1132301976.82
Search results: [] at 1132301976.82
['test'] at 1132302040.52
test at 1132302040.52
Search results: [] at 1132302040.53

The top SQLObject-generated lines appear to be from initialization; the bottom six lines are my own debugging output, and I would have expected that they be interspersed with SQL lines.

Does the following code need something else to actually look up the values?


      #query = sqlobject.sqlbuilder.Select(database_document, \
         #((database_document.q.section == restricted_section) | \
         #(restricted_section == None)))
       query = None
       debug_log(tokenize(string.lower(get_cgi("query"))))
       for keyword in tokenize(string.lower(get_cgi("query"))):
           debug_log(keyword)
           subquery =
sqlobject.sqlbuilder.EXISTS(sqlobject.sqlbuilder.Select(database_document_keyword.q
.id,
\
             (database_document.q.id == \
             database_document_keyword.q.document_id) & \
             (database_document_keyword.q.word == keyword)))
           if query:
               query = sqlobject.AND(query, subquery)
           else:
               query = subquery
       if get_cgi("format_choice") == "timestamp":
           to_order_by = database_document.q.date_last_modified
       elif get_cgi("format_choice") == "viewing_timestamp":
           to_order_by = database_document.q.date_last_viewed
       else:
           to_order_by = database_document.q.date_last_viewed
       result = database_matches_to_list(database_document.select(query, \
         orderBy=to_order_by))


--
Ian Bicking  /   ianb@colorstudy.com  /   http://blog.ianbicking.org



--

++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail ( gmail.com) account, please tell me!



--
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail ( gmail.com) account, please tell me!