lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syedfa <>
Subject Re: Creating an index from an XML file using Lucene in Java
Date Mon, 28 Jul 2008 17:31:47 GMT

Hi Karsten:

I have another follow-up question for you.  Once I create the index the way
you suggested, how would I modify my code to search it?

At present, I have the following code:

        Analyzer analyser = new StandardAnalyzer(); 
        Query parser=new QueryParser("LINES", analyser).parse(q); 
        long start=new Date().getTime(); 
        long end=new Date().getTime(); 
        QueryScorer scorer = new QueryScorer(parser); 

Which I am using in my search() method from my Searcher class.  This method
returns a List that holds javaBean objects which hold the results of each
hit.  The difference here is that I will be searching through another
element, whose attributes are slightly different, eg. if a hit is found in
the <SCENE-COMMENTARY> element, I won't be providing a reference to a
<SPEAKER>, but rather, just the Act, and the Scene.  I get the feeling that
based on the above code, that I would need to create another Query object to
hold the results found in the <SCENE-COMMENTARY> element.  Am I right, or is
there a way around this so that I could use the same Query object to
accomplish this?  Would I need to create a new JavaBean object to store
these results?  Finally, would I be able to display these results to the
user in order of strongest match, to least strongest?  At the moment my
results are created and presented to the user as follows:

for(int i=0; i<hits.length(); i++){ 
        Document doc=hits.doc(i); 
        String lns = doc.get("LINES"); 
        TokenStream lines = analyser.tokenStream("LINES", new
        CachingTokenFilter filter = new CachingTokenFilter(lines); 
        String highlightedLines = highlighter.getBestFragment(filter, lns); 
        String highlight = high.getBestFragment(filter, lns); 
        SearchResult resultBean = new SearchResult(); 

Thanks so much once again for your time and patience Karsten, I really do
appreciate it.

Take care.

Karsten F. wrote:
> Hi Fayyaz,
> again, this is about SAX-Handler not about lucene.
> My understanding of what you want:
> 1. one lucene document for each SPEECH-Element (already implemented)
> 2. one lucene document for each SCENE-COMMENTARY-Element (not implemented
> yet).
> correct?
> If yes, you can write
>                 if(qName.equals("SPEECH") ||
> qName.equals("SCENE-COMMENTARY")){
>                         doc=new Document();
>                 }
> and
> public void endElement(String uri, String localName, String qName) throws
> SAXException{
> ...
> else if(qName.equals("SCENE-COMMENTARY")){
>  Field lines = new Field(qName, elementBuffer.toString(), Field.Store.YES,
> Field.Index.TOKENIZED, Field.TermVector.YES);
>  doc.add(lines);
> }
> ...
> if(qName.equals("SPEECH") || qName.equals("SCENE-COMMENTARY")){
>   indexWriter.addDocument(doc);
> }
> (instead of "indexWriter.addDocument(doc);" in block of
> if(qName.equals("LINES")){ )
> Best regards
>   Karsten
> P.S.:
> If you want to learn java: 
> I really like 
> possible there is an english version somewhere?
> syedfa wrote:
>> I think I understand what you are saying, but I was hoping you could
>> clarify a little further.  in the start-element method, I have the
>> following:
>>                 if(qName.equals("SPEECH")){ 
>>                         doc=new Document(); 
>>                 }
>> are you saying that I should add an identical block of code for
>> <SCENE-COMMENTARY> as well, and include a similar clause in the
>> endElement method as well? i.e.
>>                          else if(qName.equals("SCENE-COMMENTARY")){ 
>>                                 Field lines = new Field(qName,
>> elementBuffer.toString(), Field.Store.YES, Field.Index.TOKENIZED,
>> Field.TermVector.YES); 
>>                                 lines.setBoost(1.0f); 
>>                                 doc.add(lines); 
>>                                 indexWriter.addDocument(doc);
>>                          } 
>> Does it also matter where in the if/else if clauses I mention the
>> "SCENE-COMMENTARY" tag?  ie. should I mention it first?  last?  or does
>> the order matter?
>> Just wondering.
>> Thanks again for your prompt reply.
>> Sincerely;
>> Fayyaz
>> P.S.  This is actually a personal project, as I have developed an
>> interest in Information Retrieval and simply wanted to work on a creative
>> project to help me develop my skills.  :-) 

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message