Skip to content

Commit bf2e5cc

Browse files
authored
Merge pull request #31 from ascribe/update-metadata-documentation
update documenation
2 parents 6d0db91 + aec0ae9 commit bf2e5cc

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

docs/source/searches.rst

+55-1
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,26 @@ The result is a list of hits:
4444
[
4545
{'dist': 0.0,
4646
'id': u'AVM37oZq0osmmAxpPvx7',
47+
'metadata': None,
4748
'path': u'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg',
4849
'score': 7.937254},
4950
{'dist': 0.22095170140933634,
5051
'id': u'AVM37nMg0osmmAxpPvx6',
52+
'metadata': None,
5153
'path': u'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg',
5254
'score': 0.28797293},
5355
{'dist': 0.42557196987336648,
5456
'id': u'AVM37p530osmmAxpPvx9',
57+
'metadata': None,
5558
'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg',
5659
'score': 0.0499953}
5760
]
5861
5962
``dist`` is the normalized distance, like we computed above. Hence, lower numbers
6063
are better with ``0.0`` being a perfect match. ``id`` is an identifier assigned by
6164
the database. ``score`` is computed by Elasticsearch, and higher numbers are
62-
better here. ``path`` is the original path (url or file path).
65+
better here. ``path`` is the original path (url or file path). ``metadata`` is
66+
an optional field used for storing extra information about the image (see below).
6367

6468
Notice all three Mona Lisa images appear in the results, with the identical
6569
image being a perfect (``'dist': 0.0``) match. If we search instead for the
@@ -76,6 +80,7 @@ You get:
7680
[
7781
{'dist': 0.0,
7882
'id': u'AVMyXQFw0osmmAxpPvxz',
83+
'metadata': None,
7984
'path': u'https://upload.wikimedia.org/wikipedia/commons/e/e0/Caravaggio_-_Cena_in_Emmaus.jpg',
8085
'score': 7.937254}
8186
]
@@ -97,10 +102,12 @@ Which now returns only the unmodified, catless Mona Lisas:
97102
[
98103
{'dist': 0.0,
99104
'id': u'AVMyXOz30osmmAxpPvxy',
105+
'metadata': None,
100106
'path': u'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg',
101107
'score': 7.937254},
102108
{'dist': 0.23889600350807427,
103109
'id': u'AVMyXMpV0osmmAxpPvxx',
110+
'metadata': None,
104111
'path': u'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg',
105112
'score': 0.28797293}
106113
]
@@ -125,14 +132,17 @@ returns
125132
[
126133
{'dist': 0.15454905655638429,
127134
'id': u'AVM37oZq0osmmAxpPvx7',
135+
'metadata': None,
128136
'path': u'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg',
129137
'score': 1.6818419},
130138
{'dist': 0.24980626832071956,
131139
'id': u'AVM37nMg0osmmAxpPvx6',
140+
'metadata': None,
132141
'path': u'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg',
133142
'score': 0.16198477},
134143
{'dist': 0.43387141782958921,
135144
'id': u'AVM37p530osmmAxpPvx9',
145+
'metadata': None,
136146
'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg',
137147
'score': 0.031996995}
138148
]
@@ -150,3 +160,47 @@ Searching for this image will return no results, unless you search with
150160
ses.search_image('http://i.imgur.com/T5AusYd.jpg', all_orientations=True)
151161
152162
Then you get the expected matches.
163+
164+
Adding metadata
165+
^^^^^^^^^^^^^^^
166+
Sometimes you want to store information with your images independent of the
167+
reverse image search functionality. You can do that with the ``metadata=``
168+
field in the ``add_image`` function.
169+
170+
Let's add one of the images again, with some extra data:
171+
172+
.. code-block:: python
173+
174+
ses.add_image('https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg', metadata={'things': 'stuff!'})
175+
176+
In general, any JSON-like data should work with ``metadata=``. Now we can search for the image:
177+
178+
.. code-block:: python
179+
180+
ses.search_image('https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg')
181+
182+
Returns our previous results along with a new one:
183+
184+
.. code-block:: python
185+
186+
[
187+
{'dist': 0.0,
188+
'id': u'AVYhQYhEDpLcdyATKuy-',
189+
'metadata': None,
190+
'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg',
191+
'score': 7.64685},
192+
{'dist': 0.0,
193+
'id': u'AVYhRvoWDpLcdyATKuzE',
194+
'metadata': {u'things': u'stuff!'},
195+
'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg',
196+
'score': 2.435569},
197+
...
198+
]
199+
200+
Where we can see a little extra info. ``image-match`` doesn't provide anyway to query
201+
the metadata directly, but the user can use Elasticsearch's QL, for example with:
202+
203+
.. code-block:: python
204+
205+
ses.es.search('images', body={'query': {'match': {'metadata.things': 'stuff!'}}})
206+

0 commit comments

Comments
 (0)