FriendOfFriendResult process(int partition, List<Integer> friends) throws IOException { List<DocIdSet> docSets = new ArrayList<DocIdSet>(friends.size()); List<int[]> fids = _core.getFriendIds(partition, friends); System.out.println("find finds " + fids.size()); for (int[] ids : fids) { IntArrayDocIdSet intSet = new IntArrayDocIdSet(); intSet.addDocs(ids, 0, ids.length); docSets.add(intSet); } OrDocIdSet orSet = new OrDocIdSet(docSets); DocIdSetIterator iter = orSet.iterator(); List<Integer> res = new ArrayList<Integer>(); int docId = iter.nextDoc(); while (docId != DocIdSetIterator.NO_MORE_DOCS) { res.add(docId); docId = iter.nextDoc(); } int[] arr = new int[res.size()]; for (int i = 0; i < res.size(); ++i) { arr[i] = res.get(i); } FriendOfFriendResult result = new FriendOfFriendResult(); result.setRes(arr); return result; }
@Test public void testOrDocIdSetWithIntArrayPForDelta() throws Exception { // test OrDocIdSet with IntArrayDocIdSet and PForDeltaDocIdSet System.out.println("Running testOrDocIdSetWithIntArrayPForDelta() Test case..."); DocIdSet[] DocList; DocList = new DocIdSet[5]; int maxdoc = 100000; for (int i = 0; i < DocList.length; ++i) { IntArrayDocIdSet docset = new IntArrayDocIdSet(maxdoc); for (int k = 0; k < maxdoc; k++) { docset.addDoc(k); } DocList[i] = docset; } // PForDeltaOrDocIdSet orset = new PForDeltaOrDocIdSet(Arrays.asList(DocList)); OrDocIdSet orset = new OrDocIdSet(Arrays.asList(DocList)); DocIdSetIterator iter = orset.iterator(); int doc; while ((doc = iter.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {} System.out.println("--------completed-----------"); }