~barry/ubuntu/raring/python-whoosh/hg1423

« back to all changes in this revision

Viewing changes to docs/build/html/_sources/querylang.txt

  • Committer: Barry Warsaw
  • Date: 2013-01-23 16:36:20 UTC
  • mfrom: (1.2.20)
  • Revision ID: barry@python.org-20130123163620-wmrpb5uhvx68bo4x
* Pull from upstream Mercurial r1423 for Python 3.3 support.
* d/control:
  - Add B-D and B-D-I on python3-* packages.
  - Added X-Python3-Version: >= 3.2
  - Added python3-whoosh binary package.
* d/patches, d/patches/fix-setup.patch: Fix typo in setup.py and remove
  --pep8 flag from [pytest] section of setup.cfg since it doesn't work.
* d/*.install: Added python3-whoosh.install and updated paths.
* d/rules:
  - Add appropriate targets for Python 3 build.
  - Add get-{packaged-}orig-source for grabbing from upstream Mercurial.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
==========================
2
 
The default query language
3
 
==========================
4
 
 
5
 
.. highlight:: none
6
 
 
7
 
Overview
8
 
========
9
 
 
10
 
A query consists of *terms* and *operators*. There are two types of terms: single
11
 
terms and *phrases*. Multiple terms can be combined with operators such as
12
 
*AND* and *OR*.
13
 
 
14
 
Whoosh supports indexing text in different *fields*. You must specify the
15
 
*default field* when you create the :class:`whoosh.qparser.QueryParser` object.
16
 
This is the field in which any terms the user does not explicitly specify a field
17
 
for will be searched.
18
 
 
19
 
 
20
 
Individual terms and phrases
21
 
============================
22
 
 
23
 
Find documents containing the term ``render``::
24
 
 
25
 
    render
26
 
 
27
 
Find documents containing the phrase ``all was well``::
28
 
 
29
 
    "all was well"
30
 
 
31
 
Note that a field must store Position information for phrase searching to work in
32
 
that field.
33
 
 
34
 
 
35
 
Boolean operators
36
 
=================
37
 
 
38
 
Find documents containing ``render`` *and* ``shading``::
39
 
 
40
 
    render AND shading
41
 
 
42
 
Note that AND is the default relation between terms, so this is the same as::
43
 
 
44
 
    render shading
45
 
 
46
 
Find documents containing ``render``, *and* also either ``shading`` *or*
47
 
``modeling``::
48
 
 
49
 
    render AND shading OR modeling
50
 
 
51
 
Find documents containing ``render`` but *not* modeling::
52
 
 
53
 
    render NOT modeling
54
 
 
55
 
Find documents containing ``alpha`` but not either ``beta`` or ``gamma``::
56
 
 
57
 
    alpha NOT (beta OR gamma)
58
 
 
59
 
Note that when no boolean operator is specified between terms, the parser will
60
 
insert one, by default AND. So this query::
61
 
 
62
 
    render shading modeling
63
 
 
64
 
is equivalent (by default) to::
65
 
 
66
 
    render AND shading AND modeling
67
 
 
68
 
See :doc:`customizing the default parser <parsing>` for information on how to
69
 
change the default operator to OR.
70
 
 
71
 
Group operators together with parentheses. For example to find documents that
72
 
contain both ``render`` and ``shading``, or contain ``modeling``::
73
 
 
74
 
    (render AND shading) OR modeling
75
 
 
76
 
 
77
 
Fields
78
 
======
79
 
 
80
 
Find the term ``ivan`` in the ``name`` field::
81
 
 
82
 
    name:ivan
83
 
 
84
 
The ``field:`` prefix only sets the field for the term it directly precedes, so
85
 
the query::
86
 
 
87
 
    title:open sesame
88
 
 
89
 
Will search for ``open`` in the ``title`` field and ``sesame`` in the *default*
90
 
field.
91
 
 
92
 
To apply a field prefix to multiple terms, group them with parentheses::
93
 
 
94
 
    title:(open sesame)
95
 
 
96
 
This is the same as::
97
 
 
98
 
    title:open title:sesame
99
 
 
100
 
Of course you can specify a field for phrases too::
101
 
 
102
 
    title:"open sesame"
103
 
 
104
 
 
105
 
Inexact terms
106
 
=============
107
 
 
108
 
Use "globs" (wildcard expressions using ``?`` to represent a single character
109
 
and ``*`` to represent any number of characters) to match terms::
110
 
 
111
 
    te?t test* *b?g*``
112
 
 
113
 
Note that a wildcard starting with ``?`` or ``*`` is very slow. Note also that
114
 
these wildcards only match *individual terms*. For example, the query::
115
 
 
116
 
    my*life
117
 
 
118
 
will **not** match an indexed phrase like::
119
 
 
120
 
    my so called life
121
 
 
122
 
because those are four separate terms.
123
 
 
124
 
 
125
 
Ranges
126
 
======
127
 
 
128
 
You can match a range of terms. For example, the following query will match
129
 
documents containing terms in the lexical range from ``apple`` to ``bear``
130
 
*inclusive*. For example, it will match documents containing ``azores`` and
131
 
``be`` but not ``blur``::
132
 
 
133
 
    [apple TO bear]
134
 
 
135
 
This is very useful when you've stored, for example, dates in a lexically sorted
136
 
format (i.e. YYYYMMDD)::
137
 
 
138
 
    date:[20050101 TO 20090715]
139
 
 
140
 
The range is normally *inclusive* (that is, the range will match all terms
141
 
between the start and end term, *as well as* the start and end terms
142
 
themselves). You can specify that one or both ends of the range are *exclusive*
143
 
by using the ``{`` and/or ``}`` characters::
144
 
 
145
 
    [0000 TO 0025}
146
 
    {prefix TO suffix}
147
 
 
148
 
You can also specify *open-ended* ranges by leaving out the start or end term::
149
 
 
150
 
    [0025 TO]
151
 
    {TO suffix}
152
 
 
153
 
 
154
 
Boosting query elements
155
 
=======================
156
 
 
157
 
You can specify that certain parts of a query are more important for calculating
158
 
the score of a matched document than others. For example, to specify that
159
 
``ninja`` is twice as important as other words, and ``bear`` is half as
160
 
important::
161
 
 
162
 
    ninja^2 cowboy bear^0.5
163
 
 
164
 
You can apply a boost to several terms using grouping parentheses::
165
 
 
166
 
    (open sesame)^2.5 roc
167
 
 
168
 
 
169
 
Making a term from literal text
170
 
===============================
171
 
 
172
 
If you need to include characters in a term that are normally treated specially
173
 
the by the parser, such as spaces, colons, or brackets, you can enclose the term
174
 
in single quotes::
175
 
 
176
 
    path:'MacHD:My Documents'
177
 
    'term with spaces'
178
 
    title:'function()'
179
 
 
180
 
 
181