13.07.2015 Views

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

than one call to contains in the same query. Thus the lastargument of contains is an integer identifying the query, in this case"1". It is possible to get a relevance score out in the select list or in anORDER BY clause with the function score and an argumentidentifying from which contains call the score should be pulled.Oracle Text is one of the more difficult and complex Oracle RDBMSproducts to use. For example, if you want to be able to search <strong>for</strong> aphrase that occurs in either the one_line_summary or body andcombine the relevance score, you need to build a multi-column index:ctx_ddl.create_preference('content_multi','MULTI_COLUMN_DATASTORE');ctx_ddl.set_attribute('content_multi', 'COLUMNS','one_line_summary, body');create index content_texton content(modified_date)indextype is ctxsys.contextparameters('datastore content_multi');Notice that the index itself is built on the column modified_date,which is not itself indexed. The call to ctx_ddl.set_attribute inwhich the COLUMNS attribute is set is what determines whichcolumns get indexed.For an example of a system that tackles the challenge of indexing textfrom disparate Oracle tables, seehttp://philip.greenspun.com/seia/examples-search/site-wide-searchOracle Text also has the property that its default search mode isexact phrase matching. A user who types "zippy pinhead" into asearch engine will expect to find documents that contain the phrase"Zippy the Pinhead". This won't happy if your script passes the rawuser query right through to the Contains operator. More problematicis what happens when a user types a query string that containscharacters that Oracle Text treats specially. This can result in anerror being raised by the SQL query and a "Server Error 500"returned to the user if you don't catch the error in your proceduralscript. It would be nice if Oracle Text had a built-in procedure called"ProcessRawQueryFromWebForm" or something. But it doesn't, atleast not until the promised 9.2 version. The next best thing is aprocedure called pavtranslate, available fromhttp://technet.oracle.com/sample_code/products/text/htdocs/query_syntax_translators/query_syntax_translators.html.236and version_date = (select max(version_date)from content_versionswhere content_id = 5657and editorial_status ='approved')Is this guaranteed to return only one row? No! There is no uniqueconstraint on content_id, version_date. In theory two editorscould or authors could submit new versions of an item within thesame second. Remember that the date datatype in Oracle is preciseonly to within 1 second. Even more likely is that an editor doing arevision might click on an editing <strong>for</strong>m submit button twice with themouse or perhaps use the Reload command impatiently. Here's aslight improvement:select *from content_versionswhere content_id = 5657and editorial_status = 'approved'and version_id = (select max(version_id)from content_versionswhere content_id = 5657and editorial_status ='approved')The version_id column is constrained unique but we're relying onunstated knowledge of our application code, i.e., that version_id willbe larger <strong>for</strong> later versions.Some RDBMS implementations have extended the SQL language sothat you can ask <strong>for</strong> the first row returned by a query. A brief look atthe Oracle manual would lead one to tryselect *from content_versionswhere content_id = 5657and editorial_status = 'approved'and rownum = 1order by version_date descbut a deeper reading of the manual would reveal that the rownumpseudocolumn is set be<strong>for</strong>e the ORDER BY clause is processed. Anaccepted way to do this in one query is the nested SELECT:select *113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!