Skip to content

Instantly share code, notes, and snippets.

@fission6
Forked from toastdriven/optional_boost.py
Created January 28, 2012 17:39
Show Gist options
  • Save fission6/1695206 to your computer and use it in GitHub Desktop.
Save fission6/1695206 to your computer and use it in GitHub Desktop.
For fission6...
>>> from haystack.inputs import Raw
>>> from haystack.query import SearchQuerySet, SQ
>>> sqs = SearchQuerySet().filter(content='python')
>>> sqs2 = SearchQuerySet().filter(SQ(content='python') | (SQ(content='python') & SQ(content=Raw('pycon^10'))))
>>>
>>> sqs.count()
16
>>> sqs2.count()
16
>>>
>>> sqs
[<SearchResult: feeds.feedentry (pk=u'2770')>, <SearchResult: feeds.feedentry (pk=u'2783')>, <SearchResult: feeds.feedentry (pk=u'2767')>, <SearchResult: feeds.feedentry (pk=u'2765')>, <SearchResult: feeds.feedentry (pk=u'2755')>, <SearchResult: feeds.feedentry (pk=u'2757')>, <SearchResult: feeds.feedentry (pk=u'2788')>, <SearchResult: feeds.entryitem (pk=u'2545')>, <SearchResult: feeds.feedentry (pk=u'2771')>, <SearchResult: feeds.feedentry (pk=u'2773')>, <SearchResult: feeds.feedentry (pk=u'2766')>, <SearchResult: feeds.entryitem (pk=u'2548')>, <SearchResult: feeds.feedentry (pk=u'2768')>, <SearchResult: feeds.feedentry (pk=u'2778')>, <SearchResult: feeds.entryitem (pk=u'2544')>, <SearchResult: feeds.feedentry (pk=u'2769')>]
>>>
>>> sqs2
[<SearchResult: feeds.feedentry (pk=u'2755')>, <SearchResult: feeds.feedentry (pk=u'2783')>, <SearchResult: feeds.feedentry (pk=u'2767')>, <SearchResult: feeds.feedentry (pk=u'2770')>, <SearchResult: feeds.feedentry (pk=u'2765')>, <SearchResult: feeds.entryitem (pk=u'2545')>, <SearchResult: feeds.feedentry (pk=u'2757')>, <SearchResult: feeds.feedentry (pk=u'2788')>, <SearchResult: feeds.feedentry (pk=u'2771')>, <SearchResult: feeds.feedentry (pk=u'2768')>, <SearchResult: feeds.feedentry (pk=u'2773')>, <SearchResult: feeds.feedentry (pk=u'2766')>, <SearchResult: feeds.entryitem (pk=u'2548')>, <SearchResult: feeds.feedentry (pk=u'2778')>, <SearchResult: feeds.entryitem (pk=u'2544')>, <SearchResult: feeds.feedentry (pk=u'2769')>]
>>>
>>> sqs[0].score, sqs[1].score, sqs[2].score, sqs[3].score, sqs[4].score
(0.4796222, 0.31147015, 0.27666408, 0.2334467, 0.19563106)
>>> sqs2[0].score, sqs2[1].score, sqs2[2].score, sqs2[3].score, sqs2[4].score
(0.3408122, 0.29142436, 0.1574226, 0.020727906, 0.008377838)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment