quantranhong1999 commented on a change in pull request #524:
URL: https://github.com/apache/james-project/pull/524#discussion_r662923876



##########
File path: 
mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchGuessingAlgorithmImpl.java
##########
@@ -0,0 +1,108 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one     *
+ * or more contributor license agreements.  See the NOTICE file   *
+ * distributed with this work for additional information          *
+ * regarding copyright ownership.  The ASF licenses this file     *
+ * to you under the Apache License, Version 2.0 (the              *
+ * "License"); you may not use this file except in compliance     *
+ * with the License.  You may obtain a copy of the License at     *
+ *                                                                *
+ * http://www.apache.org/licenses/LICENSE-2.0                     *
+ *                                                                *
+ * Unless required by applicable law or agreed to in writing,     *
+ * software distributed under the License is distributed on an    *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY         *
+ * KIND, either express or implied.  See the License for the      *
+ * specific language governing permissions and limitations        *
+ * under the License.                                             *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.search;
+
+import java.util.Collections;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Mailbox;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.StoreRightManager;
+import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.mailbox.store.mail.MessageIdMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+
+import com.github.fge.lambdas.Throwing;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableSet;
+
+import reactor.core.publisher.Flux;
+
+public class SearchGuessingAlgorithmImpl implements SearchGuessingAlgorithm {
+    private final MessageSearchIndex index;
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private final StoreRightManager storeRightManager;
+
+    @Inject
+    public SearchGuessingAlgorithmImpl(MessageSearchIndex index, 
MailboxSessionMapperFactory mailboxSessionMapperFactory, StoreRightManager 
storeRightManager) {
+        this.index = index;
+        this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+        this.storeRightManager = storeRightManager;
+    }
+
+    @Override
+    public Flux<MailboxMessage> 
searchMailboxMessages(MultimailboxesSearchQuery expression, MailboxSession 
session, long limit, MessageMapper.FetchType fetchType) throws MailboxException 
{
+        MessageIdMapper messageIdMapper = 
mailboxSessionMapperFactory.getMessageIdMapper(session);
+
+        return searchMessageIds(expression, session, limit)
+            .flatMap(messageId -> 
messageIdMapper.findReactive(Collections.singletonList(messageId), fetchType));
+    }
+
+    @Override
+    public Flux<MessageId> searchMessageIds(MultimailboxesSearchQuery 
expression, MailboxSession session, long limit) throws MailboxException {
+        return getInMailboxIds(expression, session)
+            .filter(id -> !expression.getNotInMailboxes().contains(id))
+            .collect(Guavate.toImmutableSet())
+            .flatMapMany(Throwing.function(ids -> index.search(session, ids, 
expression.getSearchQuery(), limit)));

Review comment:
       That would be a loop: MailboxManager need ThreadIdGuessingAlgorithm and 
ThreadIdGuessingAlgorithm need MailboxManager




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to