String concatenation is slow usually. Try with a string builder, or
better generate a List<>, then at the end of the loop use
Array.Join(List<>.ToArray()). I expect this will be faster.
GetDocument() can be slow, if this is a non-distributed system you will
be able to speed performance in a live system by caching recently
retrieved documents

On the Lucene side you could try using a custom HitCollector which
stores the List<> of IDs. This would mean you don't have to iterate hits
which would be marginally faster. However it will be marginal.

Presumably (I haven't tested this) the more Lucene fields you store with
your Document, the longer each GetDocument takes. Check that you are
only storing fields you need to store.

Yours,

Moray



--------------------------------------
Moray McConnachie
Director of IT
Oxford Analytica

+44 1865 261 600 http://www.oxan.com <http://www.oxan.com>  

> -----Original Message-----
> From: Trevor Watson [mailto:[email protected]
<mailto:[email protected]> ]
> Sent: 02 October 2009 15:40
> To: [email protected]
> Subject: Alternative to looping through Hits
>
> I am currently attempting to create a comma separated list of
> IDs from a given Hits collection.
>
> However, when we end up processing 6,000 or more hits, it
> takes 25-30 seconds per collection.  I've been trying to find
> a faster way to change the search results to the comma
> separated list.  Do any of you have any advice?  Thanks in advance.
>
> Trevor Watson
>
>
> My current code looks like
>
> Lucene.Net.Search.Searcher search = new
> Lucene.Net.Search.IndexSearcher(string.Format("c:\\sv_index\\"
 + jobId.ToString()));
>             Lucene.Net.Search.Hits hits = search.Search(query);
>
>             string docIds = "";
>             totalDocuments = hits.Length();
>
>           
>           // Test #1
>             Lucene.Net.Search.HitIterator hi =
> (Lucene.Net.Search.HitIterator)hits.Iterator();
>             while (hi.MoveNext())
>                 docIds +=
> ((Lucene.Net.Search.Hit)hi.Current).GetDocument().GetField("Do
cumentId").StringValue()
> + ", ";
>
>           // Test #2
>             for (int iCount = 0; iCount < totalDocuments; iCount++)
>             {
>                 Lucene.Net.Documents.Document docHit =
> hits.Doc(iCount);
>
>                 docIds +=
> docHit.GetField("DocumentId").StringValue() + ", ";
>             }
>
> 

Reply via email to