lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jagdish Vasani IN" <jvas...@in.Capitallegals.com>
Subject RE: Problem searching in the same sentence
Date Thu, 30 Sep 2010 06:13:25 GMT
For highlighting to work you need to store position information of each
token...
So while field creation you need to call following constructor..
 
	Field field = new Field(fieldName, validFieldValue,
			(store) ? Field.Store.YES : Field.Store.NO,
			(tokenize) ? Field.Index.ANALYZED :
Field.Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSET);

Hope this will solve your issue..

Thanks,
Jagdish
-----Original Message-----
From: Sirish Vadala [mailto:sirishreddy@gmail.com] 
Sent: Thursday, September 30, 2010 5:51 AM
To: java-user@lucene.apache.org
Subject: Re: Problem searching in the same sentence


Hello All:

I am performing the sentence specific phrase search, by adding sentence
by
sentence to the same field as suggested below. Everything works fine,
but
when I display my results, highlighter is not able to find the search
text
phrase.

The following is my code:

SentenceScanner sentenceScanner = new
SentenceScanner(doc.getText().replaceAll("\\s+", " "));
ArrayList<String> sentencesList = sentenceScanner.getAllSentences();
for (String sentence : sentencesList){
	addFieldToDocument(document, IFIELD_TEXT, sentence, true, true);
}

private void addFieldToDocument(Document document, String fieldName,
	String fieldValue, Boolean store, Boolean tokenize) {
	String validFieldValue = Utility.validateString(fieldValue);
	Field field = new Field(fieldName, validFieldValue,
			(store) ? Field.Store.YES : Field.Store.NO,
			(tokenize) ? Field.Index.ANALYZED :
Field.Index.NOT_ANALYZED);
	document.add(field);
}

My custom standard analyzer:

public class MyStandardAnalyzer extends StandardAnalyzer implements
IndexFields {
	public MyStandardAnalyzer(Version matchVersion) {
		super(matchVersion);
	}
	public int getPositionIncrementGap(String fieldName) {
		int incrementGap =
super.getPositionIncrementGap(fieldName);
		if (fieldName.equals(IFIELD_TEXT)) {
			incrementGap += 10;
		}
		return incrementGap;
	}
}

My highlighter code:

//analyzer instantiated as 'MyStandardAnalyzer' in the constructor
public String highlight(String text) {
   String highlightedText = "";
   TokenStream tokenStream =
analyzer.tokenStream(IndexFields.IFIELD_TEXT,
new StringReader(text));
   highlighter.setMaxDocCharsToAnalyze(Integer.MAX_VALUE);
   try {
	return highlighter.getBestFragments(tokenStream, text,
			maxFragments, delimiter);
   } catch (Exception e) {
	e.printStackTrace();
   } 
	return highlightedText;
}

Everything works fine except for the highlighter. Highlighter doesn't
return
me the text snippets while retrieving the results. Before this sentence
specific implementation, it worked well.

Any hints or help on this would be highly appreciated.
-- 
View this message in context:
http://lucene.472066.n3.nabble.com/Problem-searching-in-the-same-sentenc
e-tp1501269p1605904.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message