[MAGNOLIA-2708] Implement the jackrabbit spellchecker for the fulltext search Created: 30/Apr/09  Updated: 27/Nov/13  Resolved: 16/May/13

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Tom Wespi Assignee: Philipp Bärfuss
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File jackrabbit-spellchecker-1.5.3.jar     File lucene-spellchecker-2.2.0.jar    
Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

for workspace.xml:

<param name="spellCheckerClass" value="org.apache.jackrabbit.core.query.lucene.spell.LuceneSpellChecker$OneMinuteRefreshInterval" />

code for the template:

<%
String q = request.getParameter("query");
Query query = MgnlContext.getWebContext().getQueryManager("website")
.createQuery("/jcr:root[rep:spellcheck('"+q+"')]/(rep:spellcheck())", Query.XPATH);
RowIterator rows = ((QueryResultImpl)query.execute()).getJcrResult().getRows();
// the above query will always return one row no matter what string we check
Row r = rows.nextRow();
// get the result of the spell checking
Value v = r.getValue("rep:spellcheck()");
if (v == null) {
// no suggestion returned, the spelling is correct or the spell checker
// does not know how to correct it.
} else {
String suggestion = v.getString();
out.write("Did you mean <b>" + suggestion + "</b>?");
}
%>



 Comments   
Comment by Jan Haderka [ 30/Apr/09 ]

Tom, when I have shown this feature last week it was meant as a prototype/PoC. To implement this on its own and unrelated to the other search extensions (synonyms, excerpts, etc.) makes no sense. we need to put it together and provide concise and useful package of all the search goodies. And we also need to provide some flexible API so we can keep adding features as they come with minimal pain.
Definitively more then updating just search tag to hide the ugly code above I had in the template when showing the feature.
If we want ever decide to implement it on its own, it will likely be as an additional paragraph in STK.

Comment by Federico Grilli [ 09/May/09 ]

Hi, speaking of a search API against magnolia/jcr repositories. Here at OpenMind, I realized a Hibernate Criteria-like API to make it easier to programmatically create xpath queries. The idea crossed my mind when working at a project which involved several different search screens, each with lots of options (that is filters) diversely combined with AND/OR but which ultimately queried a DMS repository,
Here is an example of its usage:
{{
Calendar begin = Calendar.getInstance();
begin.set(2004, 0, 1);
Calendar end = Calendar.getInstance();
end.set(2008, 11, 1);

Collection<Content> pets = JCRCriteriaFactory.createMgnlCriteria("//dogs//*", MgnlContext.getQueryManager("website"), "mgnl:content").add(
Restrictions.contains("@name", "Nana")).add(
Restrictions.gt("@weight", new Float(10))).add(
Restrictions.between("@birthDate", begin, end).addOrder(
Order.desc("@jcr:score()")).list();
}}

will translate to

{{
//dogs//*[((jcr:contains(@name, 'Nana')) and (@weight>10.0) and (@birthDate >=xs:dateTime('2004-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2008-12-01T23:59:59.000+00:00')))] order by @jcr:score() descending
}}

But there's a lot more (see http://openutils.svn.sourceforge.net/viewvc/openutils/trunk/openutils-mgnlcriteria/src/site/apt/index.apt). The API is called openutils-mgnlcriteria and it's released under gplv3. The sources (no maven artifacts yet) can be downloaded from http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/trunk/openutils-mgnlcriteria. Perhaps it could become part of the official Magnolia API?

Generated at Mon Feb 12 03:39:19 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.