Invenio 0.99x offers the option to control which output formats are enabled in searches and collections. For instance, if we take a look at the advanced search screen inside of the particular collections of my Invenio instance (more precisely, ‘Trabajos Académicos’), you’ll see this:
Why are these output formats being showed, and why in that order? Because in Websearch module, I made those formats (and just those) available in my ‘Trabajos Académicos’ collection and ordered them in that way:
To this point, everything works as expected.
But let’s go further and perform a search using that advanced search screen in the ‘Trabajos Académicos’ collection. Let’s search for any term. For demonstration purposes, I’ll search ‘water’. This is the screen I get. Note the output formats available now…
Every format available is being shown! Not just the output formats we defined at Websearch…. Why’s that?
If you take a look at the code, you’ll notice that first output (advanced search within a particular collection) is being produced by create_formatoptions function defined at websearch_webcoll.py. This create_formatoptions function is called from create_searchfor_advanced (also defined at websearch_webcoll.py). This is the snippet of code that produces that output (first image in this post):
569 def create_formatoptions(self, ln=CFG_SITE_LANG): 570 "Produces 'Output format options' portal box." 571 572 # load the right message language 573 _ = gettext_set_language(ln) 574 575 box = "" 576 values = [] 577 query = """SELECT f.code,f.name FROM format AS f, collection_format AS cf 578 WHERE cf.id_collection=%d AND cf.id_format=f.id AND f.visibility='1' 579 ORDER BY cf.score DESC, f.name ASC""" % self.id 580 res = run_sql(query) 581 if res: 582 for row in res: 583 values.append({'value' : row[0], 'text': row[1]}) 584 else: 585 values.append({'value' : 'hb', 'text' : "HTML %s" % _("brief")}) 586 box = websearch_templates.tmpl_select( 587 fieldname = 'of', 588 css_class = 'address', 589 values = values 590 ) 591 return box |
The second output, the one corresponding to search results, is produced by create_search_box at search_engine.py. This function is called from function tmpl_search_box (defined at websearch_templates.py). Here is the snippet of code from search_engine.py that produces that output (third image in this post) along with the corresponding lines at search_engine.py:
742 def create_search_box(cc, colls, p, f, rg, sf, so, sp, rm, of, ot, as, 743 ln, p1, f1, m1, op1, p2, f2, m2, op2, p3, f3, 744 m3, sc, pl, d1y, d1m, d1d, d2y, d2m, d2d, dt, jrec, ec, 745 action=""): 746 747 """Create search box for 'search again in the results page' functionality.""" 748 ... 806 formats = [] 807 query = """SELECT code,name FROM format WHERE visibility='1' ORDER BY name ASC""" 808 res = run_sql(query) 809 if res: 810 # propose found formats: 811 for code, name in res: 812 formats.append({ 'value' : code, 813 'text' : name 814 }) 815 else: 816 formats.append({'value' : 'hb', 817 'text' : _("HTML brief") 818 }) |
So now we know why the outputs differ.
Every output format is stored at ‘format’ table in your database:
mysql> SELECT code,name FROM format WHERE visibility='1' ORDER BY name ASC; +--------+------------------------------------+ | code | name | +--------+------------------------------------+ | hx | BibTeX | | xd | Dublin Core | | xe | EndNote | | hb | HTML brief | | hbgeol | HTML Brief Geol | | hcs | HTML citesummary | | hd | HTML detailed | | hlight | HTML Light (invocaciones externas) | | hm | MARC | | xm | MARCXML | | mets | METS | | xn | NLM | | hc | photo captions ONLY | | hp | portfolio | | premis | PREMIS | | xw | RefWorks | | untld | Untitled | | untld2 | Untitled | +--------+------------------------------------+ 18 ROWS IN SET (0.00 sec) |
This table is quite simple. There is this interesting parameter called ‘visibility’:
mysql> DESC format; +--------------+-----------------------+------+-----+---------+----------------+ | FIELD | TYPE | NULL | KEY | DEFAULT | Extra | +--------------+-----------------------+------+-----+---------+----------------+ | id | mediumint(9) UNSIGNED | NO | PRI | NULL | AUTO_INCREMENT | | name | VARCHAR(255) | NO | | NULL | | | code | VARCHAR(6) | NO | UNI | NULL | | | description | VARCHAR(255) | YES | | | | | content_type | VARCHAR(255) | YES | | | | | visibility | tinyint(4) | NO | | 1 | | +--------------+-----------------------+------+-----+---------+----------------+ 6 ROWS IN SET (0.01 sec) |
If you set a format’s visibility to ’0′ then that format won’t be outputed. I’ll be setting to ’0′ some values to exlude those formats from visualization, just for demonstration purposes:
mysql> SELECT * FROM format WHERE visibility = 0; +----+--------------------+--------+--------------------------------------------------------------------------+----------------------+------------+ | id | name | code | description | content_type | visibility | +----+--------------------+--------+--------------------------------------------------------------------------+----------------------+------------+ | 11 | Excel | excel | Excel csv output | application/ms-excel | 0 | | 12 | HTML similarity | hs | Very short HTML output FOR similarity box (<i>people also viewed..</i>). | text/html | 0 | | 13 | RSS | xr | RSS. | text/xml | 0 | | 14 | OAI DC | xoaidc | OAI DC. | text/xml | 0 | | 15 | File mini-panel | hdfile | Used TO SHOW fulltext files IN mini-panel OF detailed record pages. | text/html | 0 | | 16 | Actions mini-panel | hdact | Used TO display actions IN mini-panel OF detailed record pages. | text/html | 0 | | 17 | REFERENCES tab | hdref | Display record REFERENCES IN REFERENCES tab. | text/html | 0 | +----+--------------------+--------+--------------------------------------------------------------------------+----------------------+------------+ 7 ROWS IN SET (0.01 sec) mysql> UPDATE format SET visibility=0 WHERE id='hbgeol'; Query OK, 0 ROWS affected (0.00 sec) ROWS matched: 0 Changed: 0 Warnings: 0 |
After setting some of the output format visibility to 0, these are the ones who have visibility=1:
mysql> SELECT * FROM format WHERE visibility=1 ORDER BY name; +----+------------------+--------+--------------------------------------------------------------+--------------+------------+ | id | name | code | description | content_type | visibility | +----+------------------+--------+--------------------------------------------------------------+--------------+------------+ | 8 | BibTeX | hx | BibTeX. | text/html | 1 | | 4 | Dublin Core | xd | XML Dublin Core. | text/xml | 1 | | 9 | EndNote | xe | XML EndNote. | text/xml | 1 | | 1 | HTML brief | hb | HTML brief output format, used FOR SEARCH results pages. | text/html | 1 | | 18 | HTML citesummary | hcs | HTML cite summary format, used FOR SEARCH results pages. | text/html | 1 | | 2 | HTML detailed | hd | HTML detailed output format, used FOR Detailed record pages. | text/html | 1 | | 3 | MARC | hm | HTML MARC. | text/html | 1 | | 5 | MARCXML | xm | XML MARC. | text/xml | 1 | | 22 | METS | mets | Formato METS. | text/xml | 1 | | 10 | NLM | xn | XML NLM. | text/xml | 1 | | 24 | PREMIS | premis | PREMIS | text/xml | 1 | | 19 | RefWorks | xw | RefWorks. | text/xml | 1 | +----+------------------+--------+--------------------------------------------------------------+--------------+------------+ 12 ROWS IN SET (0.00 sec) |
And the corresponding output for search results (as a result of performing a search):
So, what to do if you want to have ALWAYS just the output formats defined for some collection, no matter if it is the “advanced search screen” or the “search results screen”. Just edit search_engine.py from this:
query = """SELECT code,name FROM format WHERE visibility='1' ORDER BY name ASC""" res = run_sql(query) if res: # propose found formats: for code, name in res: formats.append({ 'value' : code, 'text' : name }) else: formats.append({'value' : 'hb', 'text' : _("HTML brief") }) |
To this:
#query que saca solo los output formats propios de la coleccion... (miguel) query = """SELECT f.code,f.name FROM format AS f, collection_format AS cf WHERE cf.id_collection=%d AND cf.id_format=f.id AND f.visibility='1' ORDER BY cf.score DESC, f.name ASC""" % cc_colID #query que saca todos los formatos de salida, sean o no de la coleccion (original de invenio) #query = """SELECT code,name FROM format WHERE visibility='1' ORDER BY name ASC""" res = run_sql(query) if res: # propose found formats: for code, name in res: formats.append({ 'value' : code, 'text' : name }) else: formats.append({'value' : 'hb', 'text' : _("HTML brief") }) |
And remember to run inveniocfg –update-all and then restart your Apache server:
[root@zaguan invenio]# sudo -u apache inveniocfg --update-all; /etc/init.d/httpd restart |
And lets see the changes produced at the search results screen…
Hope this was useful!!
The post CDS Invenio: format templates box in advanced search and search results screen [SOLVED] appeared first on Lecciones Prácticas.