Hi Koji,
Thank you. I implemented a solution based on the FieldTermStackTest.java
and if I do a search like "iron ore" it matches iron or ore. The same is
true if I specify iron AND ore.
The termSetMap[0].value[0] = ore and termSetMap[0].value[1] = iron.
What am I missing in having a prhase match correctly?
Thanks,
Steve
------------------------------------------------------------------------
-------------------------------------------
FVH-based solution
------------------------------------------------------------------------
-------------------------------------------
public class FastVectorHitTermLocator {
private FastVectorHighlighter fvh = null;
private FieldQuery fq = null;
public FastVectorHitTermLocator(Query query) {
this.fvh = new FastVectorHighlighter(true,true);
this.fq = fvh.getFieldQuery(query);
}
public ArrayList<KeyValuePair<Integer,Integer>> getHitOffsets(
IndexReader reader, int docId, String fieldName) throws
IOException {
ArrayList<KeyValuePair<Integer,Integer>> hitOffsets =
new ArrayList<KeyValuePair<Integer,Integer>>();
FieldTermStack fts = new
FieldTermStack(reader,docId,fieldName,this.fq);
TermInfo ti = null;
while(!fts.isEmpty()) {
ti = fts.pop();
hitOffsets.add(
new KeyValuePair<Integer,Integer>(
ti.getStartOffset(),ti.getEndOffset()));
}
return hitOffsets;
}
}
------------------------------------------------------------------------
---------------------------------------
Calling code
------------------------------------------------------------------------
---------------------------------------
String queryString = "\"iron ore\"";
QueryParser parser = new QueryParser(Version.LUCENE_30,"content",new
StandardAnalyzer(Version.LUCENE_30)));
Query query = parser.parse("queryStr");
StringBuilder sbHitPos = new StringBuilder();
FastVectorHitTermLocator tagger = new
FastVectorHitTermLocator(query);
ArrayList<KeyValuePair<Integer,Integer>> tags =
tagger.getHitOffsets(this._midxSearcher.getIndexReader(), pintDocId,
fieldName);
-----Original Message-----
From: Koji Sekiguchi [mailto:[email protected]]
Sent: Saturday, April 24, 2010 5:18 AM
To: [email protected]
Subject: Re: Term offsets for highlighting
Hi Steve,
> is there a way to access a TermVector containing only matched terms,
> or is my previous approach still the
So you want to access FieldTermStack, I understand.
The way to access it, I wrote it at previous mail:
> You cannot access FieldTermStack from FVH, but I think you
> can create it by your own. To know how to do it, please refer to
> FieldTermStackTest.java. To instantiate FieldTermStack, FieldQuery
> object is needed. And FieldQuery object can be obtained from FVH.
>
>
Koji
--
http://www.rondhuit.com/en/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]