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!