lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Miller <markrmil...@gmail.com>
Subject Re: Fine Tuning Lucene implementation
Date Wed, 25 Jul 2007 00:54:05 GMT
Are you sure you are using the same Searcher for every search? Don't 
open a new one unless you have modified the index. You are iterating 
over every hit with the Hits class. You don't ever want to do this. Use 
a HitCollector if you want to iterate over more than a hundred or so 
hits. You will find further info about this if you check out the Lucene 
webpage, the faq: http://wiki.apache.org/lucene-java/LuceneFAQ and the 
wiki: 
http://wiki.apache.org/lucene-java/FrontPage?action=show&redirect=FrontPageEN 
especially  http://wiki.apache.org/lucene-java/ImproveSearchingSpeed.

- Mark

Askar Zaidi wrote:
> Sure.
>
>  public float doBodySearch(Searcher searcher,String query, int id){
>
>                  try{
>                                 score = search(searcher, query,id);
>                      }
>                       catch(IOException io){}
>                       catch(ParseException pe){}
>
>                       return score;
>
>                 }
>
>  private float search(Searcher searcher, String queryString, int id) throws
> ParseException, IOException {
>
>         // Build a Query object
>
>         QueryParser queryParser = new QueryParser("contents", new
> KeywordAnalyzer());
>
>         queryParser.setDefaultOperator(QueryParser.Operator.AND);
>
>         Query query = queryParser.parse(queryString);
>
>         // Search for the query
>
>         Hits hits = searcher.search(query);
>         Document doc = null;
>
>         // Examine the Hits object to see if there were any matches
>         int hitCount = hits.length();
>
>                 for(int i=0;i<hitCount;i++){
>                 doc = hits.doc(i);
>                 String str = doc.get("item");
>                 int tmp = Integer.parseInt(str);
>                 if(tmp==id)
>                 score = hits.score(i);
>                 }
>
>         return score;
>     }
>
> I really need to optimize doBodySearch(...) as this takes the most time.
>
> thanks guys,
> Askar
>
> On 7/24/07, N. Hira <nhira@cognocys.com> wrote:
>   
>> Could you show us the relevant source from doBodySearch()?
>>
>> -h
>>
>> On Tue, 2007-07-24 at 19:58 -0400, Askar Zaidi wrote:
>>     
>>> I ran some tests and it seems that the slowness is from Lucene calls
>>>       
>> when I
>>     
>>> do "doBodySearch", if I remove that call, Lucene gives me results in 5
>>> seconds. otherwise it takes about 50 seconds.
>>>
>>> But I need to do Body search and that field contains lots of text. The
>>>       
>> field
>>     
>>> is <contents>. How can I optimize that ?
>>>
>>> thanks,
>>> Askar
>>>
>>>
>>>       
>>
>> ---------------------------------------------------------------------
>> 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