Raw field queries

58 views
Skip to first unread message

Charlie Choiniere

unread,
May 11, 2012, 11:40:03 PM5/11/12
to python-...@googlegroups.com
Is there anyway to disable the automagical _ and __ actions in the fields names?  I'm using a solr database that for whatever reason has _ and __ as delimiters in the field names and has sunburnt raising errors when trying to use the .query() method with them.  It's not my solr instance so I have no control over the field names.  I've reverted back using .search method which works fine, but doesn't allow me to pass in a constructor Object and also doesn't allow me to use additional methods like exclude and filter and so forth.  Are there any other work arounds besides using .search with raw queries?  

Thanks!

Mike Lissner

unread,
May 12, 2012, 8:22:04 PM5/12/12
to python-...@googlegroups.com, Charlie Choiniere
Hey Charlie,

I had to do something myself a while back, and essentially had to hack
Sunburnt into submission. My code is up at:

https://bitbucket.org/mlissner/search-and-awareness-platform-courtlistener/src/tip/alert/lib/sunburnt

Look for the raw_query function. I can't promise that it will really
work very well though. I'd LOVE to get this in Sunburnt properly, but
to do so I'd probably have to study the code a lot more than I have so
far.

Mike

Charlie Choiniere

unread,
May 15, 2012, 9:25:36 AM5/15/12
to python-...@googlegroups.com
Thanks Michael,

Is there any files I should take a look at specifically?  I was digging around a little bit and the raw query handling wasn't jumping out at me.  Thanks again!

Mike Lissner

unread,
May 15, 2012, 10:11:35 PM5/15/12
to python-...@googlegroups.com, Charlie Choiniere
Ah, OK. I did a bit more digging on this. Looks like I'm using raw_query, which *is* in Sunburnt itself (I think). Must have hacked something else, but at this point, I don't really remember.

This is roughly what my queries end up looking like:

                    # cd is short for "cleaned data" which is what Django forms create once
                    # they're validated. Basically though this is building and sending a dict
                    # called main_params.
                    main_params = search_utils.build_main_query(cd)
                    main_params['rows'] = '25'
                    main_params['start'] = '0'
                    main_params['hl.tag.pre'] = '<em><strong>'
                    main_params['hl.tag.post'] = '</strong></em>'
                    results = conn.raw_query(**main_params).execute()

Which then gives me a wicked variable called results that I can work with in various ways. What gets more complicated is if you want to do anything using facets, which means more queries to Solr for the facet counts, and then working through those values. It gets messy, and I'd be lying if I didn't say I'm considering switching over to a more low-level library for this kind of thing. For the most part, I don't use much of Sunburnt's magic...

Mike
Reply all
Reply to author
Forward
0 new messages