cancel
Showing results for 
Search instead for 
Did you mean: 

Display search result context (Google like)

egabbud
Champ in-the-making
Champ in-the-making
Hello!

I'm performing searches on the repository with the API (through WS).
I would like to display results like Google, including snippet of the documents where it matched.
- Is this information given by Lucene?
- If yes, I guess I could enhance the Alfresco repository API so that the information is availabe to the web client.
- If not, what would be the simplest solution to implement that?

I dont' think that fetching each document content and parsing it through a custom algorithm would be very efficient…

Any idea?
Thanks.
6 REPLIES 6

sam69
Champ in-the-making
Champ in-the-making
Hi !
I am also interested by this functionality.
The resume and highlighting keyword on the result is on the todo list of Alfresco.
So I guess once it will be available on alfresco, it will be also available via webservices. But I don't know when…
Cheers,
Samuel

egabbud
Champ in-the-making
Champ in-the-making
Hi Sam!

I couldn't wait till these feature will be incorportated into Alfresco, so I have implemented the code below. This code is part of a custom web application that accesses the Alfresco repository through web services. The code below needs two parameter:
- value: the content of your file (the text you want to highlight)
- queryString: the query from the user

You will need to include the Lucene libraries into your project: lucene-core.jar, lucene-highlighter.jar, lucene-analyzers.jar.

Hope it helps.

   private static final String HIGH_LIGHT_OPEN = "<b style=\"color:black;background-color:#ffff66\">";
   private static final String HIGH_LIGHT_CLOSE = "</b>";
   
   public static String highLight(String value, String queryString) throws IOException {
      
      if (!(value != null && value.trim().length()>0 && queryString !=null && queryString.trim().length()>0)){
         return value;
      }
      TermQuery query = new TermQuery(new Term("h", queryString));
      QueryScorer scorer = new QueryScorer(query);
      SimpleHTMLFormatter formatter = new
      SimpleHTMLFormatter(HIGH_LIGHT_OPEN, HIGH_LIGHT_CLOSE);
      Highlighter highlighter = new Highlighter(formatter, scorer);
      Fragmenter fragmenter = new SimpleFragmenter(200);
      highlighter.setTextFragmenter(fragmenter);
      TokenStream tokenStream = new CJKAnalyzer().tokenStream("h",new StringReader(value));
      return highlighter.getBestFragments(tokenStream, value, 5, "…");
   }

i am new to alfresco.  to implement hit highlight , please give your full code or help. actually  no any idea about part of code

sam69
Champ in-the-making
Champ in-the-making
Thanks egabbud !
It's looks simple.
Currently, in my app, I don't need to read  the content of the results files, so it's a little heavy just to have the highlighting.
But maybe later 😉

mliwski
Champ in-the-making
Champ in-the-making
Hi egabbud do you have an example of method calling???

Best Regards.

Matías.

janaka1984
Star Contributor
Star Contributor


can i know how to implement hit highlight using javascript on alfresco