package com.tencent.mm.plugin.fts.b;

import android.database.Cursor;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.fts.a.a.g;
import com.tencent.mm.plugin.fts.a.a.h;
import com.tencent.mm.plugin.fts.a.a.i;
import com.tencent.mm.plugin.fts.a.a.j;
import com.tencent.mm.plugin.fts.a.a.l;
import com.tencent.mm.plugin.fts.a.n;
import com.tencent.mm.plugin.fts.c.c;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

class c$g extends h {
    final /* synthetic */ c mGx;

    class a {
        int mDw;
        String mDx;
        long mEB;
        long timestamp;
        int type;

        private a() {
        }

        /* synthetic */ a(c$g c_g, byte b) {
            this();
        }
    }

    public c$g(c cVar, i iVar) {
        this.mGx = cVar;
        super(iVar);
    }

    public final void a(j jVar) {
        AppMethodBeat.i(136757);
        Ng("start");
        jVar.mDz = g.a(this.mEl.query, false, this.mGx.mGw);
        c cVar = this.mGx.mGp;
        String bAl = jVar.mDz.bAl();
        Cursor rawQuery = cVar.mBT.rawQuery(String.format("SELECT type, subtype, entity_id, aux_index, timestamp FROM %s NOT INDEXED JOIN %s ON (%s.docid = %s.rowid) WHERE %s MATCH '%s' AND status >= 0 ORDER BY timestamp desc;", new Object[]{cVar.bAf(), cVar.bAg(), cVar.bAf(), cVar.bAg(), cVar.bAg(), bAl}), null);
        ArrayList<a> arrayList = new ArrayList();
        HashSet hashSet = new HashSet();
        ArrayList arrayList2 = new ArrayList();
        while (rawQuery.moveToNext()) {
            String string = rawQuery.getString(3);
            if (hashSet.add(string)) {
                a aVar = new a(this, (byte) 0);
                aVar.type = rawQuery.getInt(0);
                aVar.mDw = rawQuery.getInt(1);
                aVar.mEB = rawQuery.getLong(2);
                aVar.mDx = rawQuery.getString(3);
                aVar.timestamp = rawQuery.getLong(4);
                arrayList.add(aVar);
                arrayList2.add(string);
            }
            if (arrayList.size() > this.mEl.mEt) {
                break;
            }
        }
        rawQuery.close();
        jVar.mEy = new LinkedList();
        Ng("findUsername");
        if (arrayList2.size() > 0) {
            Cursor a = this.mGx.mGp.a(jVar.mDz, arrayList2);
            HashMap hashMap = new HashMap();
            if (a.moveToNext()) {
                String[] split = a.getString(0).split(" ");
                for (int i = 0; i < split.length; i += 2) {
                    hashMap.put(split[i], Integer.valueOf(split[i + 1]));
                }
            }
            a.close();
            for (a aVar2 : arrayList) {
                l lVar = new l();
                lVar.type = aVar2.type;
                lVar.mDw = aVar2.mDw;
                lVar.mEB = aVar2.mEB;
                lVar.mDx = aVar2.mDx;
                lVar.timestamp = aVar2.timestamp;
                if (hashMap.containsKey(lVar.mDx)) {
                    lVar.userData = hashMap.get(lVar.mDx);
                } else {
                    lVar.userData = Integer.valueOf(1);
                }
                jVar.mEy.add(lVar);
            }
            Ng("findCount");
        }
        if (jVar.mDz.mEb.length > 1 && jVar.mEy.size() <= 3) {
            rawQuery = ((com.tencent.mm.plugin.fts.c.a) ((n) com.tencent.mm.kernel.g.M(n.class)).getFTSIndexStorage(3)).a(g.aO(jVar.mDz.mEb[0], true), null, com.tencent.mm.plugin.fts.a.c.mCl, com.tencent.mm.plugin.fts.a.c.mCp);
            if (rawQuery.moveToNext()) {
                l lVar2 = new l();
                lVar2.mDx = "create_talker_message​";
                jVar.mEy.add(lVar2);
            }
            rawQuery.close();
            Ng("findTalkerConversation");
        }
        AppMethodBeat.o(136757);
    }

    public final String getName() {
        return "SearchLimitGroupMessage";
    }

    public final int getId() {
        return 24;
    }
}
