Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Search system in .jwpub #106

Open
gokusander opened this issue Oct 26, 2024 · 12 comments
Open

Search system in .jwpub #106

gokusander opened this issue Oct 26, 2024 · 12 comments
Assignees
Labels
docs Problemas para mejorar o actualizar la documentación help wanted Extra attention is needed

Comments

@gokusander
Copy link
Contributor

Tipo de problema

Otro

Descripción

Me gustaría utilizar el sistema de búsqueda. no lo encontré en la wiki. Creé otro issue para estar separado.

@gokusander gokusander added the docs Problemas para mejorar o actualizar la documentación label Oct 26, 2024
@gokusander
Copy link
Contributor Author

Nothing?

@gokusander
Copy link
Contributor Author

@livrasand Do you know how work?

@livrasand livrasand self-assigned this Nov 8, 2024
@livrasand
Copy link
Owner

No me he fijado cómo funciona... pero investigaré en los próximos días, y haré un artículo en la wiki. Muchas gracias por esta buena función 👍🏻

@gokusander
Copy link
Contributor Author

No me he fijado cómo funciona... pero investigaré en los próximos días, y haré un artículo en la wiki. Muchas gracias por esta buena función 👍🏻

Esto es todo lo que falta en mi .jwpub personal, se ve hermoso. ajajaj

@orangethewell
Copy link

it seems that the Search... prefixed tables have some kind of blob that doesn't match with blobs from Document, Footnote or any other. From the code, it looks like a binary search, or something like this. You need to mess with all of then, from SearchIndexDocument to TextUnit and Word.

But yeah, I don't have so much clue about how it works, just that all these tables complement each other on JW search engine.

@gokusander
Copy link
Contributor Author

No me he fijado cómo funciona... pero investigaré en los próximos días, y haré un artículo en la wiki. Muchas gracias por esta buena función 👍🏻

any update?

@livrasand
Copy link
Owner

Hola @gokusander, aun no, no he tenido tiempo... he estado trabajando en otros proyectos.

it seems that the Search... prefixed tables have some kind of blob that doesn't match with blobs from Document, Footnote or any other. From the code, it looks like a binary search, or something like this. You need to mess with all of then, from SearchIndexDocument to TextUnit and Word.

But yeah, I don't have so much clue about how it works, just that all these tables complement each other on JW search engine.

That's right @orangethewell, they are encrypted with another method. You just have to re-encrypt new search queries.

@livrasand livrasand added the help wanted Extra attention is needed label Dec 16, 2024
@livrasand
Copy link
Owner

[progress]

This is the code responsible for processing searches.

package h.c.d.a.j;

import android.database.Cursor;
import h.c.e.b.a;
import java.util.ArrayList;
import java.util.Locale;
import org.sqlite.database.sqlite.SQLiteDatabase;

class c$f {
   private final a a;
   private final String b;
   private final String c;
   final c d;

   c$f(c var1, a var2, String var3, String var4) {
      this.d = var1;
      this.a = var2;
      this.b = var3;
      this.c = var4;
   }

   private byte[] e(int var1) {
      String var3 = String.format(Locale.US, "SELECT PositionalList FROM %s WHERE WordId=%d", this.b, var1);
      SQLiteDatabase var2 = this.a.i();

      byte[] var10;
      try {
         var10 = j.c(var2, var3);
      } catch (Throwable var9) {
         if (var2 != null) {
            try {
               var2.close();
            } catch (Throwable var8) {
               var9.addSuppressed(var8);
               throw var9;
            }
         }

         throw var9;
      }

      if (var2 != null) {
         var2.close();
      }

      return var10;
   }

   private byte[] f(int var1) {
      String var3 = String.format(Locale.US, "SELECT PositionalListIndex FROM %s WHERE WordId=%d", this.b, var1);
      SQLiteDatabase var2 = this.a.i();

      byte[] var10;
      try {
         var10 = j.c(var2, var3);
      } catch (Throwable var9) {
         if (var2 != null) {
            try {
               var2.close();
            } catch (Throwable var8) {
               var9.addSuppressed(var8);
               throw var9;
            }
         }

         throw var9;
      }

      if (var2 != null) {
         var2.close();
      }

      return var10;
   }

   private byte[] g(int var1) {
      String var3 = String.format(Locale.US, "SELECT ScopeParagraphData FROM %s WHERE TextUnitId=%d", this.c, var1);
      SQLiteDatabase var2 = this.a.i();

      byte[] var10;
      try {
         var10 = j.c(var2, var3);
      } catch (Throwable var9) {
         if (var2 != null) {
            try {
               var2.close();
            } catch (Throwable var8) {
               var9.addSuppressed(var8);
               throw var9;
            }
         }

         throw var9;
      }

      if (var2 != null) {
         var2.close();
      }

      return var10;
   }

   private void h(int var1, byte[][] var2) {
      String var4 = String.format(Locale.US, "SELECT TextPositions, TextLengths FROM %s WHERE TextUnitId=%d", this.c, var1);
      SQLiteDatabase var3 = this.a.i();

      label433: {
         Throwable var10000;
         Throwable var61;
         label434: {
            boolean var10001;
            Cursor var62;
            try {
               var62 = var3.rawQuery(var4, (String[])null);
            } catch (Throwable var60) {
               var10000 = var60;
               var10001 = false;
               break label434;
            }

            try {
               if (var62.moveToFirst()) {
                  var2[0] = var62.getBlob(0);
                  var2[1] = var62.getBlob(1);
               }
            } catch (Throwable var59) {
               var61 = var59;
               if (var62 != null) {
                  try {
                     var62.close();
                  } catch (Throwable var57) {
                     Throwable var63 = var57;

                     label415:
                     try {
                        var61.addSuppressed(var63);
                        break label415;
                     } catch (Throwable var56) {
                        var10000 = var56;
                        var10001 = false;
                        break label434;
                     }
                  }
               }

               try {
                  throw var61;
               } catch (Throwable var55) {
                  var10000 = var55;
                  var10001 = false;
                  break label434;
               }
            }

            label422:
            try {
               var62.close();
               break label433;
            } catch (Throwable var58) {
               var10000 = var58;
               var10001 = false;
               break label422;
            }
         }

         var61 = var10000;
         if (var3 != null) {
            try {
               var3.close();
            } catch (Throwable var54) {
               var61.addSuppressed(var54);
               throw var61;
            }
         }

         throw var61;
      }

      var3.close();
   }

   private byte[] i(int var1, int[] var2) {
      String var4 = String.format(Locale.US, "SELECT TextUnitCount, TextUnitIndices FROM %s WHERE WordId=%d", this.b, var1);
      SQLiteDatabase var3 = this.a.i();

      Throwable var77;
      Throwable var10000;
      label557: {
         Cursor var79;
         boolean var10001;
         try {
            var79 = var3.rawQuery(var4, (String[])null);
         } catch (Throwable var76) {
            var10000 = var76;
            var10001 = false;
            break label557;
         }

         byte[] var78;
         label558: {
            try {
               if (var79.moveToFirst()) {
                  var2[0] = var79.getInt(0);
                  var78 = var79.getBlob(1);
                  break label558;
               }
            } catch (Throwable var75) {
               var77 = var75;
               if (var79 != null) {
                  try {
                     var79.close();
                  } catch (Throwable var72) {
                     Throwable var80 = var72;

                     label531:
                     try {
                        var77.addSuppressed(var80);
                        break label531;
                     } catch (Throwable var71) {
                        var10000 = var71;
                        var10001 = false;
                        break label557;
                     }
                  }
               }

               try {
                  throw var77;
               } catch (Throwable var70) {
                  var10000 = var70;
                  var10001 = false;
                  break label557;
               }
            }

            try {
               var79.close();
            } catch (Throwable var74) {
               var10000 = var74;
               var10001 = false;
               break label557;
            }

            var3.close();
            var2[0] = 0;
            return null;
         }

         try {
            var79.close();
         } catch (Throwable var73) {
            var10000 = var73;
            var10001 = false;
            break label557;
         }

         var3.close();
         return var78;
      }

      var77 = var10000;
      if (var3 != null) {
         try {
            var3.close();
         } catch (Throwable var69) {
            var77.addSuppressed(var69);
            throw var77;
         }
      }

      throw var77;
   }

   public c.i a(int var1) {
      byte[] var5 = this.f(var1);
      byte[] var3 = this.e(var1);
      ArrayList var4 = new ArrayList();
      int var2 = 0;
      var1 = 0;

      int[] var6;
      while(var2 < var5.length) {
         var6 = new int[]{0};
         var2 += j.a(var5, var2, var6);
         var1 += var6[0];
         var4.add(var1);
      }

      ArrayList var7 = new ArrayList();
      var1 = 0;

      while(var1 < var3.length) {
         var6 = new int[]{0};
         var1 += j.a(var3, var1, var6);
         var7.add(var6[0]);
      }

      return new c.f.b(this, var4, var7);
   }

   public c.j b(int var1) {
      return new c.f.c(this, new h.c.d.a.j.a(this.g(var1), 0));
   }

   public c.n c(int var1) {
      byte[][] var3 = new byte[][]{null, null};
      this.h(var1, var3);
      byte[] var5 = var3[0];
      byte[] var7 = var3[1];
      ArrayList var4 = new ArrayList();
      int var2 = 0;
      var1 = 0;

      int[] var6;
      while(var2 < var5.length) {
         var6 = new int[]{0};
         var2 += j.a(var5, var2, var6);
         var1 += var6[0];
         var4.add(var1);
      }

      ArrayList var8 = new ArrayList();
      var1 = 0;

      while(var1 < var7.length) {
         var6 = new int[]{0};
         var1 += j.a(var7, var1, var6);
         var8.add(var6[0]);
      }

      return new c.f.d(this, var4, var8);
   }

   public c.p d(int var1, boolean var2) {
      int[] var9 = new int[]{0};
      byte[] var8 = this.i(var1, var9);
      int var7 = var9[0];
      int[] var10 = new int[var7];
      int var4 = 0;
      int var3 = 0;
      int var5 = 0;

      int var6;
      for(var1 = 0; var4 < var7; var1 = var6) {
         label15: {
            var9 = new int[]{0};
            var5 += j.a(var8, var5, var9);
            var6 = var1 + var9[0];
            if (var2) {
               var1 = var3;
               if (var6 >= 10000) {
                  break label15;
               }
            }

            var10[var3] = var6;
            var1 = var3 + 1;
         }

         ++var4;
         var3 = var1;
      }

      return new c.f.a(this, var3, var10);
   }
}

@livrasand
Copy link
Owner

@orangethewell , any ideas?

@livrasand livrasand changed the title Sistema de búsqueda in .jwpub Search system in .jwpub Dec 16, 2024
@livrasand
Copy link
Owner

[progress]

image

@gokusander
Copy link
Contributor Author

[progress]

image

hmmm how? jajajaj

@livrasand
Copy link
Owner

I don't know yet, I'm still researching the JW Library source code in my free time. But the answer must be in the code snippet I uploaded for this conversion. If you have the chance to study it, I would be very grateful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Problemas para mejorar o actualizar la documentación help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants