/// <summary> /// Records that you are now using this IndexSearcher. /// Always call this when you've obtained a possibly new /// <seealso cref="IndexSearcher"/>, for example from {@link /// SearcherManager}. It's fine if you already passed the /// same searcher to this method before. /// /// <p>this returns the long token that you can later pass /// to <seealso cref="#acquire"/> to retrieve the same IndexSearcher. /// You should record this long token in the search results /// sent to your user, such that if the user performs a /// follow-on action (clicks next page, drills down, etc.) /// the token is returned. /// </summary> public virtual long Record(IndexSearcher searcher) { EnsureOpen(); // TODO: we don't have to use IR.getVersion to track; // could be risky (if it's buggy); we could get better // bug isolation if we assign our own private ID: long version = ((DirectoryReader)searcher.IndexReader).Version; SearcherTracker tracker = Searchers[version]; if (tracker == null) { //System.out.println("RECORD version=" + version + " ms=" + System.currentTimeMillis()); tracker = new SearcherTracker(searcher); if (Searchers.AddIfAbsent(version, tracker) != null) { // Another thread beat us -- must decRef to undo // incRef done by SearcherTracker ctor: tracker.Dispose(); } } else if (tracker.Searcher != searcher) { throw new System.ArgumentException("the provided searcher has the same underlying reader version yet the searcher instance differs from before (new=" + searcher + " vs old=" + tracker.Searcher); } return(version); }