简体   繁体   中英

Read Lucene FSDirectory from WebApi

I am using FSDirectory to query a previously built (and also static) Lucene index.

I would like to use the query from a WebApi, that's stateless and at the moment instantiate a new FSDirectory for each call received.

I am not sure if this is the best approach of if it's better to pool the FSDirectory. I expect that this "issue" is already covered by the framework, but I am new to this tool and don't know how to proceed.

There can be a lot of overhead to opening the index and getting it warmed as it will need to build caches, for example FieldCache. Further, both the IndexReader class and the IndexWriter classes are thread safe.

So the typical best practice for a WebAPI, or any use for that mater, would be to use a single IndexReader or a single IndexWriter to service all threads and this can be done by your code easily since both of those classes are thread safe.

So typically when the system starts up it will instantiate one of those, lets say a IndexWriter and it will place that where all WebAPI calls can get access to it. They may use the IndexWriter for writing or use a reader obtained from IndexWriter.GetReader() for reading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM