سؤال

hello i am working on java and i am using lucene for the indexing purpose. i am storing data there but how to check that what lucene data contain?

i am tried with this to check data on lucene. public static void main(String[] args) throws Exception {

    File indexDir = new File("/path/to/solr/data/index/");
    int hits = 100;

    SimpleSearcher searcher = new SimpleSearcher();
    searcher.searchIndex(indexDir, args[0], hits);
}

private void searchIndex(File indexDir, String queryStr, int maxHits)
        throws Exception {

    Directory directory = FSDirectory.open(indexDir);

    IndexSearcher searcher = new IndexSearcher(directory);
    QueryParser parser = new QueryParser(Version.LUCENE_35,
     "title", new SimpleAnalyzer());
    Query query = parser.parse(queryStr);

    TopDocs topDocs = searcher.search(query, maxHits);

    ScoreDoc[] hits = topDocs.scoreDocs;
    for (int i = 0; i < hits.length; i++) {
        int docId = hits[i].doc;
        Document d = searcher.doc(docId);
        List<Fieldable> fields = d.getFields();

        System.out.println( (i+1) + ". ==========================================================");
        for ( Fieldable field : fields ) {
           if (field.isStored()) {
             System.out.println(" >> " + field.name() + " - " + d.get(field.name()));
           }
        }
    }

    System.out.println("Found " + hits.length);
}

is there any tool available to download it??

هل كانت مفيدة؟

المحلول

yes you can see this you hava to just download the lucene client

http://code.google.com/p/luke/downloads/detail?name=lukeall-3.4.0_1.jar&can=2&q

just give your index folder as its path to index directory and you can see it on UI also you can add,delete or update using this.

نصائح أخرى

You can use Luke which will do the same as code above and even more.

If you're using Lucene version which is greater than 4.0, Luke has to be downloaded elsewhere. One of the possible places to get relevant fork binaries is here: https://github.com/DmitryKey/luke/releases/tag/4.6.0

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top