Christoph Breidert schrieb:
Hi folks,

I have a nice javascript (I will be happy to provide) for autosuggestion of search terms.

For the search on my magnolia system I want to use this script to display search terms, that actually deliver a hit from the index. Therefore I need a method that lists all the search terms that actually provide a hit.

I couldn't quite figure out how this can be done and would be very thankful for any hints.

I am using Magnolia 2.1

Thx, Christoph


----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------


Hello folks,

I will answer my own question, which was "how to retrieve all search terms that deliver a hit in magnolia search". From looking at the JCR API you cannot list the search terms that actually deliver a hit.

However, in the jackrabbit-implementation of the JCR, internally a lucene index is used. The API of lucene does have this functionality. So, what I do is manually open the index and list all tokens for the indexed field "title" and "fulltext".

I am not sure whether this is a smart/elegant way to achieve this. I would have liked to discuss this with some of the users/developers out there, but unfortunately nobody bothered replying to my question.

Here is a code snippet for whom it may concern:

   private List getSearchTokens() {

String fileString = request.getSession().getServletContext().getRealPath("/")
       +"repositories/website/workspaces/default/index";
ArrayList result = new ArrayList();
       try{
           ArrayList result = new ArrayList();
           File[] fileArray = new File(fileString).listFiles();
           for (int i = 0; i < fileArray.length; i++) {
               File f = fileArray[i];
               if (f.isDirectory()){
                   IndexReader idxR = IndexReader.open(f);
                   TermEnum enum = idxR.terms();
                   while(enum.next()){
                       Term t = enum.term();
                       if(t.field().equals(TERM_FIELD_TITLE)
                               || t.field().equals(TERM_FIELD_TEXT)){
                           if(!result.contains(t.text())
&& t.text().length()>2 //only words between 2 && t.text().length()<11 // and 10 characters && t.text().indexOf("@")<0) //no email adresses
                               result.add(t.text());
                       }
                   }
               }
} }
       catch(Exception ex){
           ex.printStackTrace();
       }
return result; }


Cheers, Christoph

----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Reply via email to