Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
Update sample_facets.py
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg committed Apr 3, 2014
1 parent 9806e6d commit 25c299e
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions docs/samples/sample_facets.py
Expand Up @@ -85,40 +85,64 @@

print s.facet_counts()
# Pretty-printed output:
# {u'product': [
# {u'count': 5, u'term': u'Firefox'},
# {u'count': 3, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Boot2Gecko'}
# ]}
# {u'product': {
# u'_type': u'terms',
# u'total': 9,
# u'terms': [
# {u'count': 5, u'term': u'Firefox'},
# {u'count': 3, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Boot2Gecko'}
# ],
# u'other': 0,
# u'missing': 0
# }}

# Let's do a query for 'cookie' and do a facet count.
print s.query(title__text='cookie').facet_counts()
# Pretty-printed output:
# {u'product': [
# {u'count': 1, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Firefox'}
# ]}
# {u'product': {
# u'_type': u'terms',
# u'total': 2,
# u'terms': [
# {u'count': 1, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Firefox'}
# ],
# u'other': 0,
# u'missing': 0
# }}

# Note that the facet_counts are affected by the query.

# Let's do a filter for 'flash' in the topic.
print s.filter(topics='flash').facet_counts()
# Pretty-printed output:
# {u'product': [
# {u'count': 5, u'term': u'Firefox'},
# {u'count': 3, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Boot2Gecko'}
# ]}
# {u'product': {
# u'_type': u'terms',
# u'total': 9,
# u'terms': [
# {u'count': 5, u'term': u'Firefox'},
# {u'count': 3, u'term': u'Firefox for mobile'},
# {u'count': 1, u'term': u'Boot2Gecko'}
# ],
# u'other': 0,
# u'missing': 0
# }}

# Note that the facet_counts are NOT affected by filters.

# Let's do a filter for 'flash' in the topic, and specify
# filtered=True.
print s.facet('product', filtered=True).filter(topics='flash').facet_counts()
# Pretty-printed output:
# {u'product': [
# {u'count': 1, u'term': u'Firefox'}
# ]}
# {u'product': {
# u'_type': u'terms',
# u'total': 1,
# u'terms': [
# {u'count': 1, u'term': u'Firefox'}
# ],
# u'other': 0,
# u'missing': 0
# }}

# Using filtered=True causes the facet_counts to be affected by the
# filters.
Expand All @@ -128,17 +152,23 @@
# field that is analyzed.
print basic_s.facet('topics').facet_counts()
# Pretty-printed output:
# {u'topics': [
# {u'count': 3, u'term': u'privacy'},
# {u'count': 3, u'term': u'cookies'},
# {u'count': 2, u'term': u'basic'},
# {u'count': 1, u'term': u'websites'},
# {u'count': 1, u'term': u'user'},
# {u'count': 1, u'term': u'tips'},
# {u'count': 1, u'term': u'search'},
# {u'count': 1, u'term': u'interface'},
# {u'count': 1, u'term': u'flash'}
# ]}
# {u'topics': {
# u'_type': u'terms',
# u'total': 14,
# u'terms': [
# {u'count': 3, u'term': u'privacy'},
# {u'count': 3, u'term': u'cookies'},
# {u'count': 2, u'term': u'basic'},
# {u'count': 1, u'term': u'websites'},
# {u'count': 1, u'term': u'user'},
# {u'count': 1, u'term': u'tips'},
# {u'count': 1, u'term': u'search'},
# {u'count': 1, u'term': u'interface'},
# {u'count': 1, u'term': u'flash'}
# ],
# u'other': 0,
# u'missing': 0
# }}

# Note how the facet counts shows 'user' and 'interface' as two
# separate terms even though they're a single topic for document with
Expand Down

0 comments on commit 25c299e

Please sign in to comment.