Contribute to the DSpace Development Fund

The newly established DSpace Development Fund supports the development of new features prioritized by DSpace Governance. For a list of planned features see the fund wiki page.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Background

For a presentation about AJAX I have modified DSpace so all search fields have autosuggest capability like Google suggest (http://www.google.com/webhp?complete=1&hl=en)

What it does

When the user starts to type in a search field (excluding advance search) a list of suggestions is displayed beneath the search field. This list contains the number of hits for the current collection and the number of hits and suggestions for a specific index, for example the author or title index. The user can select an item from this dropdown list to immediately search for that term in that index.

Try it at

A demo version is available at: http://dspacetest.leidenuniv.nl/dspace

For example start typing 'peter' or 'auto' or 'suggest'

How it works

Via Javascript an event handler for the keydown event is attached to all input fields with name 'query'. When something is typed in such an input field multiple AJAX http request are sent asynchronously to dspace. An AjaxSearchServlet handles those request and sends results back using JSON. Via javascript these results are displayed using the DOM in a dropdown list.
Which indexes are used and how many results are displayed is configurable.

Which DSpace version

The modifications I made were made to Dspace 1.3.2, but it should work with no extra work in another version of Dspace, or with Manakin.

How to install

It is relatively easy and non-invasive to install. Some files must be added and some changes to configuration must be made

Step 1: Adding AjaxSearchServlet

  • Download the files AjaxSearchServlet.java and json.jsp
  • The file AjaxSearchServlet.java must be added to src/org/dspace/app/webui/servlet/
  • The file json.jsp must be added to jsp/local/search/ (create the directory if necessary)
  • edit etc/dspace-web.xml and add the following:
  <servlet>
    <servlet-name>ajax-search</servlet-name>
    <servlet-class>org.dspace.app.webui.servlet.AjaxSearchServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>ajax-search</servlet-name>
    <url-pattern>/ajax-search</url-pattern>
  </servlet-mapping>

Step 2: Adding Javascript

  • Download the files autosuggest_search.js.jsp and ajax.js
  • The files must be added to the new directory ajax inside jsp
  • Include a reference to these files in the body of the page navbar-default.jsp (near line 121 will work). But you can also choose to include it less global so it only works on some pages, for example in the body of community-home.jsp. Anyway, include this:
  <script type="text/javascript" src="<%= request.getContextPath() %>/ajax/ajax.js"></script>
  <script type="text/javascript" src="<%= request.getContextPath() %>/ajax/autosuggest_search.js.jsp"></script>

Step 3: Configuring

  • edit dspace.cfg and include the following lines:
  ajax.autosuggest.index.1 = author
  ajax.autosuggest.index.2 = title
  ajax.autosuggest.index.3 = keyword
  ajax.autosuggest.pagesize = 100
  ajax.autosuggest.itemcount = 5

The first 3 lines indicate which indexes to search. You can add more indexes, or delete some indexes if you want. Be carefull that the numbering stays good. And that the indexes are configured with the same name, see the search.index.n keys of dspace.cfg

The ajax.autosuggest.pagesize key gives the maximum number of hits. If more are found than >99 is displayed instead of the actual number. If this is 0 (zero) or missing then no list of suggestions is displayed, affectively disabling 'Autosuggest+using+AJAX'.

The ajax.autosuggest.itemcount key gives the maximum number of suggestions for each index. If this is 0 (zero) or missing no suggestions are displayed.

  • edit language-packs/Messages.properties and include the following lines:
  jsp.ajax.types.author = authors
  jsp.ajax.types.title = titles
  jsp.ajax.types.keyword = keywords

These are the translations for the names of the indexes.

Step 4: build / install / restart

Do the stuff you normally do when deploying a new version of DSpace.

Contact me

If you need help, or have any comments, or you just want to inform me that you (are going to) use this, please contact me.

See inside the source files for my e-mail.

  • No labels