コード例 #1
0
ファイル: TestComposite.java プロジェクト: bleujin/craken
  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();
  }
コード例 #2
0
  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());
  }
コード例 #3
0
ファイル: TestPolicy.java プロジェクト: bleujin/ISearcher
  private void executeTest(IWritePolicy policy)
      throws CorruptIndexException, LockObtainFailedException, IOException, InterruptedException,
          IndexException, ExecutionException {
    Central central = sampleTestDocument();

    FileCollector col = new FileCollector(getTestDirFile(), true);
    Indexer writer = central.newIndexer();

    NonBlockingListener adapterListener = getNonBlockingListener(writer);
    adapterListener.getDefaultIndexer().setWritePolicy(policy);

    col.addListener(adapterListener);
    col.addListener(new DefaultReporter(false));

    col.collect();
    adapterListener.waitForCompleted();
    central.close();
  }
コード例 #4
0
ファイル: CrakenStore.java プロジェクト: bleujin/craken
 @Override
 public int size() {
   try {
     return central.newSearcher().search("*:*").totalCount();
   } catch (IOException e) {
     return 0;
   } catch (ParseException e) {
     return 0;
   }
 }
コード例 #5
0
ファイル: CrakenStore.java プロジェクト: bleujin/craken
  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;
    }
  }
コード例 #6
0
ファイル: CrakenStore.java プロジェクト: bleujin/craken
  /**
   * 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;
    }
  }
コード例 #7
0
  private void indexSpeed(Directory dir) throws LockObtainFailedException, IOException {
    Central cram = SimpleCentralConfig.createCentral(dir);
    Indexer indexer = cram.newIndexer();

    final String readString =
        IOUtil.toString(
            new FileReader(
                new File("test/" + StringUtil.replace(this.getClass().getCanonicalName(), ".", "/"))
                    + ".java"));
    final String extString = IOUtil.toString(new FileReader(new File("build.xml")));
    indexer.index(
        new IndexJob<Void>() {

          public Void handle(IndexSession session) throws Exception {
            for (int i = 0; i < 1000; i++) {
              MyDocument doc = MyDocument.testDocument();
              doc.keyword("name", "bleujin");
              doc.text("file", extString);
              session.insertDocument(doc);
            }
            return null;
          }
        });
  }
コード例 #8
0
  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();
  }