You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ps...@apache.org on 2007/08/12 10:20:28 UTC

svn commit: r565018 - in /labs/pinpoint/trunk: ./ pinpoint-cli/src/main/java/org/apache/logging/pinpoint/ pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/ pinpoint-search/ pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/

Author: psmith
Date: Sun Aug 12 01:20:27 2007
New Revision: 565018

URL: http://svn.apache.org/viewvc?view=rev&rev=565018
Log:
Shell CLI client can now search, select an event, and show the event in context by time range.

Basic search results model class created that will be used for all UI implements (Web etc).


Added:
    labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ContextRange.java
    labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchResults.java
    labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
Modified:
    labs/pinpoint/trunk/TODO.txt
    labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java
    labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java
    labs/pinpoint/trunk/pinpoint-search/pom.xml
    labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java

Modified: labs/pinpoint/trunk/TODO.txt
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/TODO.txt?view=diff&rev=565018&r1=565017&r2=565018
==============================================================================
--- labs/pinpoint/trunk/TODO.txt (original)
+++ labs/pinpoint/trunk/TODO.txt Sun Aug 12 01:20:27 2007
@@ -1,6 +1,8 @@
 TODO
 
 * All POM's currently have their own copy of the properties that indicate which verion of jars are used.  This is because of the maven-eclipse plugin.  However I have not tested whether the latest stable dev version of the plugin works better.
+* I18n
+
 
 Pinpoint-sevice
 * Document how to use it in Daemon or non-daemon mode
@@ -34,7 +36,6 @@
 
 * try to work out the jline stuff a bit better
 * add support for customizing layout of presented events
-* deal with long lists more effectively
 
 pinpoint-web
 * Consider how to layout the screen properly (see Tref)

Modified: labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java?view=diff&rev=565018&r1=565017&r2=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java (original)
+++ labs/pinpoint/trunk/pinpoint-cli/src/main/java/org/apache/logging/pinpoint/Shell.java Sun Aug 12 01:20:27 2007
@@ -1,18 +1,27 @@
 /**
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
- * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
- * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- * for the specific language governing permissions and limitations under the License.
- */
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ **/
 package org.apache.logging.pinpoint;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 import jline.ArgumentCompletor;
@@ -35,11 +44,14 @@
 import org.apache.log4j.LogManager;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.pinpoint.analyser.DefaultAnalyzerFactory;
+import org.apache.logging.pinpoint.search.PinpointSearchResults;
+import org.apache.logging.pinpoint.search.PinpointSearchUtils;
 import org.apache.logging.pinpoint.search.PinpointSearcher;
+import org.apache.logging.pinpoint.store.EventStore;
 import org.apache.logging.pinpoint.store.SimpleEventStore;
 import org.apache.logging.pinpoint.utils.PinpointUtils;
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.queryParser.QueryParser.Operator;
@@ -47,6 +59,17 @@
 
 public class Shell {
 
+    private PinpointContext ctx;
+    private PinpointSearchResults currentResults;
+    private PinpointSearcher pinpointSearcher;
+    private EventStore eventStore;
+    private Analyzer analyzer;
+    private QueryParser queryParser;
+
+    public Shell(PinpointContext ctx) {
+        this.ctx = ctx;
+    }
+
     /**
      * @param args
      * @throws Exception
@@ -68,10 +91,11 @@
             }
             LogManager.getLoggerRepository().setThreshold(level);
             PinpointContext ctx = PinpointUtils.getContextFromCmdLine(cmdLine);
+            Shell shell = new Shell(ctx);
             if (cmdLine.hasOption('b')) {
-                browseContext(ctx);
+                shell.browseContext();
             } else if (cmdLine.hasOption('s')) {
-                searchContext(ctx);
+                shell.searchContext();
             } else {
                 throw new UnsupportedOperationException("Not implemented yet");
             }
@@ -87,13 +111,13 @@
      * 
      * @param ctx
      */
-    private static void browseContext(PinpointContext ctx) {
+    private void browseContext() {
         // TODO proper browse!
-        showContextInfo(ctx);
+        showContextInfo();
 
     }
 
-    private static void showContextInfo(PinpointContext ctx) {
+    private void showContextInfo() {
         Map<String, Collection<String>> values = PinpointContextUtils
                 .listContextPointValues(ctx);
         System.out.format("Context: %s\n", ctx.getContextRoot()
@@ -105,8 +129,7 @@
         }
     }
 
-    private static void searchContext(PinpointContext ctx) throws IOException,
-            ParseException {
+    private void searchContext() throws IOException, ParseException {
         ConsoleReader consoleReader = new ConsoleReader();
 
         Completor fieldNameCompletor = new PinpointContextCompleter(ctx);
@@ -115,10 +138,12 @@
          * this is one of the most confusing aspects of jLine.... I think these
          * names need to be in sorted order too...?
          */
-        consoleReader.addCompletor(new ArgumentCompletor(new Completor[] {
-                new SimpleCompletor(new String[] { "exit", "info", "search",
-                        "set", "quit" }), fieldNameCompletor,
-                new NullCompletor() }));
+        consoleReader.addCompletor(new ArgumentCompletor(
+                new Completor[] {
+                        new SimpleCompletor(new String[] { "exit", "info",
+                                "next", "previous", "search", "set",
+                                "showInContext", "quit" }), fieldNameCompletor,
+                        new NullCompletor() }));
 
         consoleReader
                 .setCompletionHandler(new CandidateListCompletionHandler());
@@ -132,27 +157,40 @@
          * prompt so it's important that at least jline 0.9.91 is used. I WASTED
          * OVER AN HOUR tracking that down.
          */
-        Analyzer analyzer = new StandardAnalyzer();
-        QueryParser queryParser = new QueryParser("message", analyzer);
+        analyzer = new DefaultAnalyzerFactory().createAnalyser();
+        queryParser = new QueryParser("message", analyzer);
         queryParser.setDefaultOperator(Operator.AND);
 
-        PinpointSearcher pinpointSearcher = new PinpointSearcher(ctx,
-                new SimpleEventStore(ctx.getSerializationFile()));
+        eventStore = new SimpleEventStore(ctx.getSerializationFile());
+        pinpointSearcher = new PinpointSearcher(ctx, eventStore);
+
+        currentResults = null;
         try {
             while (!Arrays.asList("exit", "quit").contains(
                     (input = consoleReader.readLine()))) {
                 try {
                     String[] cmd = StringUtils.split(input);
 
-                    if (StringUtils.equalsIgnoreCase("search", cmd[0])) {
-                        input = StringUtils.removeStart(input, cmd[0]);
+                    String arg = cmd[0];
+                    if (StringUtils.equalsIgnoreCase("search", arg)) {
+                        input = StringUtils.removeStart(input, arg);
                         Query query = queryParser.parse(input);
                         System.out.println(query);
-                        Iterable<LoggingEvent> iterable = pinpointSearcher
-                                .search(query);
-                        displayEvents(iterable);
-                    } else if (StringUtils.equalsIgnoreCase("info", cmd[0])) {
-                        showContextInfo(ctx);
+                        currentResults = pinpointSearcher.search(query);
+                        displayEvents();
+                    } else if (StringUtils.equalsIgnoreCase("next", arg)) {
+                        currentResults.nextPage();
+                        displayEvents();
+                    } else if (StringUtils.equalsIgnoreCase("previous", arg)) {
+                        currentResults.previousPage();
+                        displayEvents();
+                    } else if (StringUtils.equalsIgnoreCase("showInContext",
+                            arg)) {
+                        int selectedEvent = Integer.valueOf(cmd[1]);
+                        showInContext(selectedEvent);
+
+                    } else if (StringUtils.equalsIgnoreCase("info", arg)) {
+                        showContextInfo();
                     } else {
                         System.err.println("Unknown cmd: " + input);
                     }
@@ -170,15 +208,46 @@
 
     }
 
+    private void displayEvents() {
+        if (currentResults.size() == 0) {
+            System.out.println("No Results found");
+            return;
+        }
+        System.out.println(currentResults.size() + " results found. ");
+        System.out.println("Displaying events from page " +
+                currentResults.getCurrentPage());
+
+        List<LoggingEvent> pageEvents = new ArrayList<LoggingEvent>(
+                currentResults.getPageSize());
+        List<String> pageResults = currentResults.getPageResults();
+        for (String eventLocation : pageResults) {
+            pageEvents.add(eventStore.restore(eventLocation));
+        }
+        displayEvents(pageEvents);
+
+    }
+
+    private void showInContext(int eventIndexOnCurrentPage) throws IOException {
+        Iterable<LoggingEvent> contextEvents = PinpointSearchUtils
+                .showEventInContext(pinpointSearcher, eventStore,
+                        currentResults, eventIndexOnCurrentPage);
+        displayEvents(contextEvents);
+    }
+
     private static void displayEvents(Iterable<LoggingEvent> iterable) {
         if (!iterable.iterator().hasNext()) {
             System.out.println("No results found");
+            return;
         }
+
+        // TODO customized layout
         Layout layout = new PatternLayout(
                 "[%d{ISO8601} %-5p][%20.20c][%t] %m%n");
 
+        int counter = 1;
         for (LoggingEvent loggingEvent : iterable) {
-            System.out.print(layout.format(loggingEvent));
+            System.out.print(counter + ">" + layout.format(loggingEvent));
+            counter++;
         }
     }
 

Modified: labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java?view=diff&rev=565018&r1=565017&r2=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java (original)
+++ labs/pinpoint/trunk/pinpoint-core/src/main/java/org/apache/logging/pinpoint/converter/EventWriter.java Sun Aug 12 01:20:27 2007
@@ -40,6 +40,10 @@
 
 public class EventWriter {
 
+    public static final String FIELD_EVENT_TIME = "eventtime";
+
+    private static final String FIELD_EVENT_DATE = "eventdate";
+
     private static final Logger LOG = PinpointUtils
             .getLogger(EventWriter.class);
 
@@ -52,8 +56,10 @@
 
     private IndexWriter indexWriter;
 
-    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyyMMdd");
-    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HHmmss");
+    public static final DateTimeFormatter dateFormatter = DateTimeFormat
+            .forPattern("yyyyMMdd");
+    public static final DateTimeFormatter timeFormatter = DateTimeFormat
+            .forPattern("HHmmss");
 
     private boolean optimizeOnClose;
 
@@ -156,8 +162,12 @@
         String date = dateFormatter.print(timestamp);
         String time = timeFormatter.print(timestamp);
 
-        doc.add(new Field("eventdate", date, Store.YES, Index.UN_TOKENIZED));
-        doc.add(new Field("eventtime", time, Store.YES, Index.UN_TOKENIZED));
+        doc
+                .add(new Field(FIELD_EVENT_DATE, date, Store.YES,
+                        Index.UN_TOKENIZED));
+        doc
+                .add(new Field(FIELD_EVENT_TIME, time, Store.YES,
+                        Index.UN_TOKENIZED));
         //        
     }
 

Modified: labs/pinpoint/trunk/pinpoint-search/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/pom.xml?view=diff&rev=565018&r1=565017&r2=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-search/pom.xml Sun Aug 12 01:20:27 2007
@@ -37,6 +37,11 @@
       <version>3.8.2</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+    <groupId>joda-time</groupId>
+    <artifactId>joda-time</artifactId>
+    <version>1.4</version>
+	</dependency>
   </dependencies>
   <properties>
     <commonscli.version>1.0</commonscli.version>

Added: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ContextRange.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ContextRange.java?view=auto&rev=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ContextRange.java (added)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/ContextRange.java Sun Aug 12 01:20:27 2007
@@ -0,0 +1,40 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ **/
+package org.apache.logging.pinpoint.search;
+
+import org.joda.time.Interval;
+
+/**
+ * Designed to create standard Intervals that are used when displaying events in
+ * context.
+ * 
+ * @author psmith
+ * 
+ */
+public class ContextRange {
+
+    private static final int DEFAULT_WINDOW_SIZE = 5 * 1000; // 5 seconds
+
+    // window
+
+    public static Interval createDefaultContextRange(long timeStamp) {
+        long contextRange = (DEFAULT_WINDOW_SIZE / 2);
+        return new Interval(timeStamp - contextRange, timeStamp + contextRange);
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchResults.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchResults.java?view=auto&rev=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchResults.java (added)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchResults.java Sun Aug 12 01:20:27 2007
@@ -0,0 +1,128 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ **/
+package org.apache.logging.pinpoint.search;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.log4j.Logger;
+import org.apache.logging.pinpoint.store.EventStore;
+import org.apache.logging.pinpoint.utils.PinpointUtils;
+
+// TODO test cases for this, because I _alway_ screw up pagination
+
+/**
+ * Container bean that holds the event location keys for a given search result,
+ * with pagination support.
+ * 
+ * This class does not hold the events themselves, just the locations in the
+ * {@link EventStore} in the order in which they were returned from the search.
+ * 
+ */
+public class PinpointSearchResults {
+
+    private static Logger LOG = PinpointUtils
+            .getLogger(PinpointSearchUtils.class);
+
+    private static final int DEFAULT_PAGE_SIZE = 10;
+    private final List<String> results;
+    private int currentPage = 1;
+    private int pageSize = DEFAULT_PAGE_SIZE;
+    private int lastPage;
+
+    PinpointSearchResults(List<String> results) {
+        this.results = Collections.unmodifiableList(results);
+        calculateLastPage();
+    }
+
+    private void calculateLastPage() {
+
+        lastPage = (int) Math.ceil(results.size() / pageSize);
+    }
+
+    public final List<String> getResults() {
+        return results;
+    }
+
+    public final int getCurrentPage() {
+        return currentPage;
+    }
+
+    public final void setCurrentPage(int currentPage) {
+        this.currentPage = currentPage;
+        realignCurrentPage();
+    }
+
+    public final int getPageSize() {
+        return pageSize;
+    }
+
+    public final void setPageSize(int pageSize) {
+        this.pageSize = pageSize;
+        calculateLastPage();
+
+    }
+
+    public List<String> getPageResults() {
+        if (LOG.isDebugEnabled()) {
+            // TODO once debugged, change this to DEBUG or TRACE
+            LOG.debug(this);
+        }
+        realignCurrentPage();
+        int startOffset = pageSize * (currentPage - 1);
+        startOffset = startOffset < 0 ? 0 : startOffset;
+        int endOffset = startOffset + pageSize;
+        endOffset = endOffset < results.size() ? endOffset : results.size();
+        if (LOG.isDebugEnabled()) {
+            LOG.info("startOffset:" + startOffset + ", endOffset:" + endOffset);
+        }
+        return results.subList(startOffset, endOffset);
+    }
+
+    private void realignCurrentPage() {
+        if (currentPage > lastPage) {
+            currentPage = lastPage;
+        } else if (currentPage < 1) {
+            currentPage = 1;
+        }
+
+    }
+
+    public int size() {
+        return results.size();
+    }
+
+    public void previousPage() {
+        navigate(-1);
+    }
+
+    public void nextPage() {
+        navigate(1);
+    }
+
+    private void navigate(int vector) {
+        setCurrentPage(getCurrentPage() + vector);
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java?view=auto&rev=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java (added)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java Sun Aug 12 01:20:27 2007
@@ -0,0 +1,75 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ **/
+package org.apache.logging.pinpoint.search;
+
+import java.io.IOException;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.pinpoint.converter.EventWriter;
+import org.apache.logging.pinpoint.store.EventStore;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.RangeQuery;
+import org.joda.time.Interval;
+
+public class PinpointSearchUtils {
+    // TODO shoud the searcher and eventStore be fields, and this method not
+    // static? ie. should this helper class not be a static class
+
+    /**
+     * Returns an iterable item that shows all LoggingEvents around the chosen
+     * event using the default context time Interval
+     * 
+     * @param searcher
+     * @param eventStore
+     * @param results
+     * @param chosenEventOnCurrentPage
+     * @return
+     * @throws IOException
+     */
+    public static Iterable<LoggingEvent> showEventInContext(
+            PinpointSearcher searcher, EventStore eventStore,
+            PinpointSearchResults results, int chosenEventOnCurrentPage)
+            throws IOException {
+        // TODO confirm this is +1 based
+        String eventLocation = results.getPageResults().get(
+                chosenEventOnCurrentPage);
+
+        /*
+         * Grob the event from the store Create ContextRange from that event's
+         * timestamp Perform new search using that time range Display all events
+         */
+        LoggingEvent loggingEvent = eventStore.restore(eventLocation);
+        Interval interval = ContextRange.createDefaultContextRange(loggingEvent
+                .getTimeStamp());
+
+        // TODO check the interval spans the same day? Usual PinpointContext
+        // won't span.
+
+        Term startTerm = new Term(EventWriter.FIELD_EVENT_TIME,
+                EventWriter.timeFormatter.print(interval.getStartMillis()));
+        Term endTerm = new Term(EventWriter.FIELD_EVENT_TIME,
+                EventWriter.timeFormatter.print(interval.getEndMillis()));
+        Query query = new RangeQuery(startTerm, endTerm, true);
+
+        Iterable<LoggingEvent> iterable = searcher.iterate(query);
+        return iterable;
+    }
+
+    // TODO other methods that allow specific Context filters
+}

Modified: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java?view=diff&rev=565018&r1=565017&r2=565018
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java (original)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearcher.java Sun Aug 12 01:20:27 2007
@@ -16,14 +16,15 @@
 package org.apache.logging.pinpoint.search;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.logging.pinpoint.PinpointContext;
 import org.apache.logging.pinpoint.resolver.OffsetAndLength;
 import org.apache.logging.pinpoint.store.EventStore;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.Hit;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
@@ -38,7 +39,6 @@
 
     private final Sort defaultSort = new Sort(new SortField[] {
             new SortField("eventdate"), new SortField("eventtime") });
-    private Filter filter;
     private EventStore eventStore;
 
     private ReloadPolicy reloadPolicy = new ReloadPolicyAlways();
@@ -58,17 +58,44 @@
         // date/time?
     }
 
-    public Iterable<LoggingEvent> search(Query query) throws IOException {
+    public Iterable<LoggingEvent> iterate(Query query) throws IOException {
+        Hits hits = doSearch(query);
+        return new HitIteratable(hits);
+    }
+
+    private Hits doSearch(Query query) throws IOException {
+        checkReloadPolicy(query);
+        Hits hits = searcher.search(query, defaultSort);
+        return hits;
+    }
+
+    private void checkReloadPolicy(Query query) throws IOException {
         if (reloadPolicy.shouldReload(query)) {
             reload();
         }
-        if (filter == null) {
-            Hits hits = searcher.search(query, defaultSort);
-            return new HitIteratable(hits);
-        } else {
-            throw new UnsupportedOperationException(
-                    "ahh, filters not yet supported");
+    }
+
+    public PinpointSearchResults search(Query query) throws IOException {
+        Hits hits = doSearch(query);
+        return convertHitsToResults(hits);
+    }
+
+    private PinpointSearchResults convertHitsToResults(Hits hits) {
+        // TODO HIGH work out more efficient way of getting all the hits in
+        // sorted
+        // order.
+        List<String> results = new ArrayList<String>(hits.length());
+        for (Iterator iterator = hits.iterator(); iterator.hasNext();) {
+            Hit hit = (Hit) iterator.next();
+            try {
+                results.add(OffsetAndLength.resolveLocationFromDocument(hit
+                        .getDocument()));
+            } catch (Exception e) {
+                throw new RuntimeException("Failed to navigate to next hit: " +
+                        debugHit(hit), e);
+            }
         }
+        return new PinpointSearchResults(results);
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org