incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Blur Wiki] Update of "BlurPlatform" by AaronMcCurry
Date Wed, 23 Jul 2014 02:09:56 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Blur Wiki" for change notification.

The "BlurPlatform" page has been changed by AaronMcCurry:
https://wiki.apache.org/blur/BlurPlatform?action=diff&rev1=1&rev2=2

  
  The point is that as a command implementor, you process a BlurIndex (which gives you full
access to IndexReader/Searcher/Writers); define how results should be merged together; and
how they should finally be returned.
  
+ Here's a potential client example:
+ {{{
+   public static void main(String[] args) {
+     BlurCommandServerInterface client = getClient("host:port");
+     String query = "field:term";
+     Long result = client.execute(new BlurCommand<Long, Long>(query) {
+       @Override
+       public Long execute(BlurIndex index) throws IOException {
+         IndexSearcherClosable searcher = index.getIndexSearcher();
+         String queryStr = getArgs(0);
+         QueryParser parser = new QueryParser(Version.LUCENE_43, "", new StandardAnalyzer(Version.LUCENE_43));
+         Query query;
+         try {
+           query = parser.parse(queryStr);
+         } catch (ParseException e) {
+           throw new IOException(e);
+         }
+         final AtomicLong count = new AtomicLong();
+         searcher.search(query, new Collector() {
+ 
+           @Override
+           public void collect(int doc) throws IOException {
+             count.incrementAndGet();
+           }
+ 
+           @Override
+           public void setScorer(Scorer scorer) throws IOException {
+ 
+           }
+ 
+           @Override
+           public void setNextReader(AtomicReaderContext context) throws IOException {
+ 
+           }
+ 
+           @Override
+           public boolean acceptsDocsOutOfOrder() {
+             return false;
+           }
+         });
+         return count.get();
+       }
+ 
+       @Override
+       public Long merge(Map<String, Long> results) throws IOException {
+         long total = 0;
+         for (Entry<String, Long> e : results.entrySet()) {
+           total += e.getValue();
+         }
+         return total;
+       }
+     });
+     System.out.println(result);
+   }
+ 
+ }}}
+ 

Mime
View raw message