Example #1
0
  public void testRun() throws Exception {
    String wsName = "test";
    DefaultCacheManager dcm = new DefaultCacheManager();
    Cache<String, Metadata> metaCache = dcm.getCache("meta");
    Cache<String, byte[]> dataCache = dcm.getCache("data");

    GridFilesystem gfs = new GridFilesystem(dataCache, metaCache);

    BuildContext bcontext =
        DirectoryBuilder.newDirectoryInstance(metaCache, dataCache, metaCache, wsName);
    bcontext.chunkSize(1024 * 1024);
    Directory directory = bcontext.create();
    Central central = CentralConfig.oldFromDir(directory).build();

    central.newIndexer().index(IndexJobs.create("/bleujin", 10));

    central.newSearcher().createRequest("").find().debugPrint();

    OutputStream output = gfs.getOutput("/test.data");
    IOUtil.copyNClose(new StringInputStream("hello bleujin"), output);

    Debug.line(IOUtil.toStringWithClose(gfs.getInput("/test.data")));

    central.newSearcher().createRequest("").find().debugPrint();

    File root = gfs.getFile("/");
    viewFile(root);

    dcm.stop();
  }
  public void testFileIndex() throws Exception {
    Central c = writeDocument(analyzer);

    Searcher searcher = c.newSearcher();
    long start = System.currentTimeMillis();

    SearchResponse response = searcher.search("bleujin");
    Debug.line(response.size(), System.currentTimeMillis() - start, response.getDocument());
  }
Example #3
0
 @Override
 public int size() {
   try {
     return central.newSearcher().search("*:*").totalCount();
   } catch (IOException e) {
     return 0;
   } catch (ParseException e) {
     return 0;
   }
 }
Example #4
0
  private MarshalledEntry _load(Object _key, boolean fetchValue, boolean fetchMetaValue) {
    try {
      TreeNodeKey key = (TreeNodeKey) _key;
      if (key.action() == Action.RESET || key.action() == Action.CREATE)
        return null; // if log, return

      if (key.getType().isStructure()) {
        List<ReadDocument> docs =
            central
                .newSearcher()
                .createRequest(new TermQuery(new Term(EntryKey.PARENT, key.fqnString())))
                .selections(IKeywordField.DocKey)
                .offset(1000000)
                .find()
                .getDocument();
        AtomicHashMap<String, Fqn> values = new AtomicHashMap<String, Fqn>();
        for (ReadDocument doc : docs) {
          Fqn fqn = Fqn.fromString(doc.idValue());
          values.put(fqn.name(), fqn);
        }
        InternalMetadata metadataBb = null;
        return ctx.getMarshalledEntryFactory().newMarshalledEntry(key, values, metadataBb);
      }

      ReadDocument findDoc =
          central
              .newSearcher()
              .createRequestByKey(key.idString())
              .selections(EntryKey.VALUE)
              .findOne();
      if (findDoc == null) {
        return null;
      }
      return entryFromDoc(key, findDoc);
    } catch (IOException e) {
      return null;
    } catch (ParseException ex) {
      return null;
    }
  }
  public void testApply() throws Exception {
    Central c = writeDocument(config, analyzer);

    Central newC =
        SimpleCentralConfig.createCentral(
            StorageFac.createToMongo("61.250.201.78", "search", "storageTest"));
    newC.newSearcher().search("bleujin").debugPrint();
    Debug.line('@', config.buildDir().getLockID(), newC.dir().getLockID());

    Indexer writer = c.newIndexer();
    writer.index(
        analyzer,
        new IndexJob<Void>() {
          public Void handle(IndexSession session) throws Exception {
            session.insertDocument(MyDocument.testDocument().keyword("name", "bleujin"));
            return null;
          }
        });

    newC.newSearcher().search("bleujin").debugPrint();
    Debug.line();
  }
Example #6
0
  /**
   * The base class implementation calls {@link #load(Object)} for this, we can do better because we
   * keep all keys in memory.
   */
  @Override
  public boolean contains(Object _key) {
    try {
      final TreeNodeKey key = (TreeNodeKey) _key;
      if (key.getType().isStructure()) return true;

      String id = key.getFqn().toString();
      return central.newSearcher().createRequestByKey(id).findOne() != null;
    } catch (IOException e) {
      return false;
    } catch (ParseException e) {
      return false;
    }
  }