Tip:
Highlight text to annotate it
X
Hi everybody.
I hope this stream is working.
My name is Nicolas Garnier.
I'm a developer advocate working on Google
Drive here in Zurich.
So this is the first time we're trying this live
broadcasting set up.
Hopefully everything will be live.
If it's not, please complain on the YouTube comment, and
I'll try to have a look during this web cast.
So during the session, today we're going to have a look at
how the search feature inside Google Drive is working and
basically, as a developer, what you have to do to make
your file searchable.
And, basically, have a very nice integration between your
app and Google Drive and have all sorts of files.
We'll see in details how that works searchable through
Google Drive.
So first, let's see a bit how Google Drive search works,
today, for the basic use cases.
So let me switch to my drive here.
So this is my drive.
This is one of my test accounts.
It doesn't have many files in it.
But what I want to show you is the search feature, which you
can use using the search bar here on top.
Whenever you're going to upload a file to Google Drive,
Google Drive is, usually, going to index that file.
Basically, read the content of that file and index it so that
your file can be easily searchable using that future.
So this is true for, basically, all
the common file types.
So let's say you upload a text document, or an HTML
document, or PDF.
Basically, every very, very common file types.
Google Drive is going to automatically be able to read
the content because Google Drive knows that file type and
is going to be able to read and index that file content.
So I have prepared a little bit of code here.
Let me switch to my eclipse.
That first little code sample here is actually using our
Java Quick Start, which I took from our documentation.
I just modified it a bit so I don't have to go through all
the authorization part of that Quick Start.
It's already authorized.
What it's going to do is, it's simply going to go upload a
text file, which I call document.text.
Here I can show you.
This is the text file, very simple text file, with only a
little word in it.
Test one, two, three.
So we can use that to try to search it later on.
What that's going to do here is, that's simply going to
upload that text file.
So let me do this.
I run that little script.
Test command file upload.
The code is running.
And when it's done here, basically, the output tells me
that the insert was successful.
Now, let me go back to my drive.
And we see the text file here.
So just to show you that the indexing is working properly,
if I try to search for test123, which is the content
of that text file, that works well.
The file is found.
Everything works as expected.
So if you, as a developer, upload any types of very, very
common file types.
As I said, PDF, HTML, text files, that sort of files.
Google Drive is going to automatically index it.
So if you're working with common files types, you don't
really have anything else to do than simply uploading the
text files, as usual.
It also works with images.
So here is an image that I uploaded earlier.
It's an image of a little Android logo here.
Google Drive also have some image recognition logic.
And basically, it's going to index all the images and then
try to detect a bunch of patterns or known--
for example, known buildings, or anything like that.
Or here it's going to recognize that it's a little
Android doll.
And it's going to index that file against that search
query, which is, for example, Android here.
So if I search for Android, I'm going to find that image
even though the word Android wasn't used in any of the
metadata for that file.
It's not in the title.
It's not in the description.
So just recognize it's an Android doll.
That's going to work for all the images automatically.
You have nothing special to do here.
If you upload an image, the user will be able to search
for it, and it will automatically recognize its
contents, usually.
That works pretty nicely.
A quick note, you also should be able to use that
feature in the API.
So you can use our full text search feature in the API.
And you'll get--
for example, if you search for Android, you'll
actually get that file.
So this is all working pretty nicely.
Let me go back to my actual files.
Now I actually want to show you what you can do as a
developer for uncommon file types.
If you upload file types that are not very
common, let's say--
Here, I have prepared another file, which I'm going to give
that very, very long name.
And I'm going to give it a very weird MimeType.
The MimeType for that file is going to be myown/mime.type.
So it's an uncommon MimeType, I would say.
Google Drive is not going to try to index that file, as we
are going to see in a minute.
So let me just upload it.
OK, here.
My script is uploading that file.
That file is actually the same text file that we've seen
before that contains test123.
three.
Except that because the MimeType type set for that
file is not plain slash text, Google Drive is not going to
try to read the files contents.
And as we can see when I go back to my Drive here.
OK, my file is uploaded here.
This file content is not automatically indexed because
it has an uncommon MimeType.
That's the name I gave to my file.
And if I search for test123 again, I'm only going to see
the first file that I've uploaded.
Not the second one, which has the special MimeType.
So now we're going to see what you can do, guys.
As developers, when you upload uncommon file types inside
Google Drive, what you can do to have the content of the
file indexed by Google Drive.
So there is two ways to have the
content of the file indexed.
Basically, you have to think in which case am I. Let me
switch back to me here.
Hi guys, again.
Is the content of the file readable?
If the content of your file is text--
for example, you're using XML as a data
format for your file.
Basically, you would think, A, it's going to be very easy for
Google Drive to simply read that file content and index it
as it would for a regular XML file or an HTML file, except I
have my own specific MimeType.
Or, let's say, the other case you could be in is, I'm
uploading, for example, binary data.
Or I'm using a shortcut file.
We'll see what a shortcut file is in
Google Drive in a moment.
So if you're opening binary data, basically data that
Google cannot read, that's another case here.
And there is ways for you to indicate
what type of content--
I mean how Google Drive should index the
content of that file.
So let me switch back to my eclipse here.
I've prepared, again, some more code sample for you here.
So this is the first case here.
We have a special feature that you can set to tell Google
Drive that-- let me show you my eclipse--
that basically tells Google Drive my thought is actually
text based or XML based.
You can actually read the content of that
file and index it.
You can do that by simply setting that little flag here
when you upload the file to Google Drive that I've
highlighted.
Very simply, you set use content as
indexable text true.
If you're using the original [INAUDIBLE]
library or if you're using the protocol directly, you could
use your parameter content as indexable equal true when you
do the upload request to Google Drive.
So when you do that, Google Drive is actually going to try
to read the file content as if it was text
and index its content.
So let me run that little code sample here.
So the sample is uploading the file.
Here, it's done.
If I go back to my Drive, let me see all items.
This is here.
My new file just appeared.
This content is automatically indexed because we tell Google
Drive to do so.
If you search for the content that's inside that text file,
which has a specific MimeType type which is not plain dot
slash text.
Google Drive have actually found it because that's what
setting that little URL parameter does.
Google Drive just reads it as if it was a text file.
So you can do that if your specific file type is any
types of plain text or XML or JSON based.
Basically, anything that you guys can read pretty easily.
That's your first case.
Now, the second case is, let's say your file type is
basically binary.
Basically, Google Drive is never going to be able to
actually read it.
It's your custom binary file format you've come up with.
Or it's like an encrypted file that
you've encrypted customly.
Google Drive is never going to be able to read the
content of that file.
What you want to do, in that case, is
use our other feature.
Let me show you.
Here.
Basically, you want to set the indexable text.
That's part of the file metadata.
When you upload the file, you can pass indexable text.
That's a write-only field.
You're not going to be able to read it back.
The user is never going to be able to see that field.
We're only going to use all the words that are in that
field to index your file.
And your file is going to be searchable.
So let's say you came up with your own encrypted file or
it's a binary file format.
You have a drawing app, and it's drawing data.
But the user adds a few text inside the drawing.
You could, for example, set the text that is inside the
file content.
Pass it in the
setIndexableText function here.
These words are going to be indexed for the file to be
searched against.
So let me try to upload that file again.
This is, again, our custom file.
I haven't set the little flag that say to
read the file content.
I'm going to use only that setIndexableText feature here.
And I'm going to pass, again, test123 as
the text to be indexed.
So let's run this now.
Here.
Again, my script is uploading the file.
That's done.
Let me go back to my Chrome.
Let's look at the recent file.
Let's wait a bit.
Here we go.
This is my file here.
No, actually.
Which name did I give it?
Very sorry.
Going back here.
OK.
This is the one here on top.
This file content is not automatically indexed.
Google Drive is not going to index the file content per se,
but it's going to index the value that were passed in the
indexable text field.
So if I search for test123 again, this is the file here.
It's showing up in search.
Again, that's search query because we've passed it in the
indexable text data basically when we uploaded the file.
Now there is one last use case when there is no
content for the file.
You have uploaded no content for the file.
That's actually called shortcut
files in Google Drive.
We have the special types of file which are
called shortcut files.
So you don't have to upload any content when you're
integrating with Google Drive.
You could upload only kind of like a placeholder.
It looks like a file to the user.
It's only a placeholder in Google Drive.
You haven't uploaded any actual binary or any actual
file content.
Simply the file metadata.
So the title, description, MimeType, et cetera.
So this is the code here to upload such shortcut file.
So typically, applications would upload shortcut files
when they want to keep the data on the server.
Or let's say they don't have an actual specific file
format, or it doesn't make sense for their data to be
bundled in a file, or they don't want to do that.
They want to keep total control of the data.
Keep that in their own database, but they still want
a nice integration with Google Drive.
So they upload, simply, a shortcut that when the user is
going to click, the user is going to be automatically
redirected to this application's website.
And you can load your data that you have stored locally
on your own database.
So that's the use case here for that type of file that
doesn't have any content on Google Drive.
Though, in that case, you can still set the indexable text.
We really ask you to do this.
Otherwise, you're going to miss out on the search feature
for Google Drive.
Because we don't have any content uploaded at all on
Google Drive, you should really tell us what's inside
your document and what we should index for the search to
work on that file.
So here is another code snippet that I'm going to run.
OK, I'm uploading my shortcut file.
As you can see here, we don't actually pass any real file to
be uploaded.
Only metadata for the file is uploaded to Google Drive.
And when I go to Google Drive, again, let's look at the
recent file.
This is it.
This file has no content, but we set the indexable text.
So if I search again for test123, the file shows up.
So that was here using the indexable text
for shortcut files.
So again, really, really use that feature if you're
uploading binary data or if you're using shortcut files
inside Google Drive.
And for the other use case, in case your file is actually
text based--
let me switch back again.
Hello again.
If the format of your file is actually text based and you're
uploading, for example, using XML or JSON again--
just a reminder--
you could actually, very simply, use the other feature,
which is simply setting a little Boolean, a little flag
telling us that it's actually safe to read the file content.
It's not binary.
It's not crap, basically.
Google Drive can read the file.
And it's going to try to read it as text and index that.
And, basically, that's it.
That was Google Drive Search and how you could
integrate with this.
Thanks again for following along.
And, again, a warm hi from Zurich.
We don't very often do these live demos here, these
Hangouts here.
So hi everybody, and I hope to see you another time.
All right, bye-bye.