Index |
Pregătiri Crearea unui tip de fișier personalizat Pictogramă Recunoașterea fișierelor Descriere Aplicația preferată Atribute extra Indexare Adăugarea datelor Interogarea bazei de date |
Seminar: Tipuri de fișiere, atribute, index și interogări
This is a workshop to show the use of Attributes, Queries, the Index and custom Filetypes. As an example, we build a database to keep track of our DVD library.
Pregătiri
Let's first decide what filetype and attributes would serve our needs. Originally, I planned to use a bookmark file with a link to the movie's IMdB page, but since Haiku didn't have a "bookmarkable" browser like BeOS' NetPositive at that time, I came up with this: The file itself will be a JPEG image for the movie cover.
With WebPositive, Haiku now has a browser using bookmark files again, so you could as well use a bookmark file instead of an image as basic filetype for our database files.
In any case, to these files we add a couple of attributes. Here we have to decide if we want to query it later (then we have to add it to the index) and if so, what type of attribute it should be. Numbers (int, float) can be evaluated differently than text (</=/> vs. is/contains/starts with).
Acestea sunt atributele pe care aș vrea să le văd pentru DVD-urile mele:
- Titlu film
- Gen
- URL către ex: IMdB
- Director/Actori
- Subiect
- Evaluarea mea de la 1 la 10
- Coordonatele pe raftul meu, adică A2, B3, ca să găsesc DVD-ul și în viața reală. :)
- Dacă așa e, atunci cine a împrumutat discul...
Crearea unui tip de fișier personalizat
Start the Filetypes preferences, and click on the button below the hierarchical list on the left. A small dialog opens and you specify in which MIME Group your new filetype will reside. You can also create a completely new group. Let's put it into "applications" and set the "Internal name" to DVDdb.
Un panou pentru noul tip de fișier DVDdb se deschide:
Pictogramă
Double-click the icon well to open Icon-O-Matic to design an icon for your filetype. You can also drag & drop an icon from the icon well of another type, maybe as starting point for a modified version.
Recunoașterea fișierelor
You can add suffixes like .txt, .jpg, .mp3 to recognize files by their extention. Useful when working with files from systems without MIME typing. We don't need that for our example.
Descriere
- Nume de tip - Apare de ex. în meniul Atribute al ferestrelor Tracker și în atributul „Tip” al unui fișier.
- Descriere - O descriere puțin mai detaliată.
Aplicația preferată
This pop-up menu shows a list of all applications that can handle this particular filetype. From here you can choose which program should open this specific file when it's double-clicked.
deschide un dialog de fișier unde alegeți aplicația de deschis cu acest tip de fișier. Aici vom stabili ShowImage ca să afișeze coperta DVD. | ||
deschide un dialog de fișier unde alegeți orice fișier care are deja stabilită aplicația preferată pe care o căutați. |
Atribute extra
Aici introducem toate atributele personalizate asupra cărora ne-am decis în pregătirile precedente. Clic pe butonul
deschide un panou pentru a introduce datele pentru atributul nou. Puteți edita un atribut existent cu dublu clic.Nume atribut - Apare de ex. ca titlul coloanei în ferestrele Tracker.
Nume intern - Este utilizat pentru indexarea și interogarea atributului.
- Type - Defines the value the attribute can hold and therefore how it can be queried.
- for normal text
- for binary data: 0 (false) or >=1 (true)
- : -128 to 127
- : -32,768 to 32,767
- : -2,147,483,648 to 2,147,483,647
- : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
for integer numbers with different ranges:
- for floating-point numbers, single precision
- for floating-point numbers, double precision
- for time and date format
- Visible - This checkbox determines if the attribute is visible in a Tracker window at all. Since the Tracker will be the interface to our DVD database, we check it and define its appearance with:
- - Can be used to show either one of two symbols, see below.
- - Shows an integer as 1/60, e.g. "90" becomes "1:30".
- - Shows a rating between 0 and 10 as star symbols.
- Leave on "Default" if the values are to be displayed according to the attribute's "Type" (e.g. string/integer/float etc.). The other options are:
- - Determines if the attribute shall be editable in Tracker.
- - Defines the two symbols used for a checkbox display. For example, "xo" will show a "x" for all values >0 and "o" for 0.
- - The default width of that attributes column in a Tracker window.
- - The attribute can be displayed left, center, or right aligned.
Acum introduceți toate informațiile pentru atribute:
Nume intern | Tip de atribut | indexat? | Descriere |
---|---|---|---|
DVDdb:title | text | da | Titlu film |
DVDdb:genre | text | da | Gen |
DVDdb:url | text | nu | URL |
DVDdb:cast | text | da | Director/Actori |
DVDdb:plot | text | nu | Subiect |
DVDdb:rating | int-32 | da | Evaluare 1 la 10 |
DVDdb:coord | text | nu | Raft |
DVDdb:lent | text | da | Împrumutat la |
Indexare
Before we start entering data in our little DVD database, we should add certain attributes to the Index. Only indexed attributes can use Haiku's fast Queries.
So, what will we be searching in the future? We probably won't ask "What's in the B4 coordinate in my shelf?" or "Does the IMdB URL or the plot of the movie contain the word 'pope-shenooda'?".
Aceasta lasă următoarele atribute:
Nume intern | Tip de atribut |
---|---|
DVDdb:title | text |
DVDdb:genre | text |
DVDdb:cast | text |
DVDdb:rating | int-32 |
Pentru a le indexa, deschidem un Terminal și adăugăm pur și simplu atributele unul după altul:
mkindex -t string DVDdb:title mkindex -t string DVDdb:genre mkindex -t string DVDdb:cast mkindex -t int DVDdb:rating
Opțiunea -t definește tipul de atribut, care e „string” pentru toate în afară de evaluare, care este un număr întreg.
Adăugarea datelor
Now, everything's set and we can begin putting some data into our base.
Since our basic file is a cover image, we go to some online resource like IMdB, look for our first movie and save the cover or movie poster in a new folder where we want to keep our DVDdb files.
Opening that folder we see a typical Tracker window with one JPEG in it. Right-clicking it, we change its filetype to application/DVDdb with the Filetype Addon. There's more info on this in the Filetypes document.
Now, we activate all our DVDdb attributes from the
menu of the Tracker window and rearrange the columns to our taste:By clicking on a yet empty attribute (or pressing ALT E) we enter editing mode and fill each attribute. With TAB and SHIFT TAB you can navigate between attributes.
In our example, we usually start with a downloaded JPG cover and change its type to applications/DVDdb. There's another elegant way to produce a file to work with. Just copy an empty file of our filetype to /boot/home/config/settings/Tracker/Tracker New Templates and rename it to DVDdb.
Right-clicking into a Tracker window, you'll find a new entry under
besides the default "New folder".Interogarea bazei de date
Several hours of grunt work later, we have a nice little database that you can query to find all your Christina Ricci movies that have a 7 rating… :)
You can assign a sensible attribute layout for query results of a specific filetype.
Open the folder containing your DVDdb files and arrange the attributes how you'd like to have query results presented. Copy this layout with .
Open /boot/home/config/settings/Tracker/DefaultQueryTemplates, create a new folder and rename it to group/filetype, replacing slashes with underscores; in our case "application_DVDdb".
Deschideți un dosar nou și lipiți aranjamentul cu
. Voilà: