0

how to deal with highligter when i use lucene +zk?

asked 2009-02-20 14:05:30 +0800

comxuhua gravatar image comxuhua
54

how to deal with highligter when i use lucene +zk?
eg:<label value="hello,word"/>
how can i make the color of hello red?

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2009-02-21 04:00:50 +0800

flyworld gravatar image flyworld
155 3

you can take a look the style guide
http://www.zkoss.org/doc/styleguide/

link publish delete flag offensive edit

answered 2009-02-23 08:05:38 +0800

comxuhua gravatar image comxuhua
54

eg:When i search ZK in http://www.zkoss.org/forum/index.zul#path%3Dindex%3B ,the result is like this:
ZK button doesnt look appropriate ,
the ZK is highlighter word,it's background color is yellow.

The fellow is my code
Search.java
public List<String> searchIndex(String keywords) throws Exception {
String[] FIELD = { "title", "details" };
String QUERY = keywords;
String paht="d:/index";
List<String> results=new ArrayList<String>();
Analyzer analyzer = new PaodingAnalyzer();
FSDirectory directory = FSDirectory.getDirectory(path);
IndexReader reader = IndexReader.open(directory);
String queryString = QUERY;
BooleanClause.Occur[] flags = new BooleanClause.Occur[] {
BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(queryString, FIELD, flags,
analyzer);

Searcher searcher = new IndexSearcher(directory);
query = query.rewrite(reader);
System.out.println("Searching for: " + query.toString());
Hits hits = searcher.search(query);
String highLightText = "";

for (int i = 0; i < hits.length(); i++) {

Document doc = hits.doc;
String title1 = doc.get("title");
String contents1 = doc.get("details");

SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter(
"<font color=red>", "</font>");

Highlighter highlighter = new Highlighter(simpleHTMLFormatter,
new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(200));

if (contents1 != null) {
TokenStream tokenStream = analyzer.tokenStream("details",
new StringReader(contents1));
highLightText = highlighter.getBestFragment(tokenStream,
contents1);
results.add(highLightText);
}

}
reader.close();
return results;
}

zul:
<window title="Live Grid" border="normal">
<zscript>
Search search=new Search();
List<String> results= search.searchIndex("ZK");
ListModel strset = new SimpleListModel(results);
</zscript>
<grid width="100px" height="100px" model="${strset}">
<columns>
<column label="options"/>
</columns>
</grid></window>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-02-20 14:05:30 +0800

Seen: 164 times

Last updated: Feb 23 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More