gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] storm/org/nongnu/storm IndexedPool.java modules...


From: Benja Fallenstein
Subject: [Gzz-commits] storm/org/nongnu/storm IndexedPool.java modules...
Date: Thu, 22 May 2003 18:41:05 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Benja Fallenstein <address@hidden>      03/05/22 18:41:05

Modified files:
        org/nongnu/storm: IndexedPool.java 
        org/nongnu/storm/modules/gispmap: GispPeer.java 
        org/nongnu/storm/pointers: SetPointer.java TitleIndex.java 
        org/nongnu/storm/util: HTTPProxy.java 

Log message:
        first version of search, buggy

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/IndexedPool.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/modules/gispmap/GispPeer.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/pointers/SetPointer.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/pointers/TitleIndex.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/util/HTTPProxy.java.diff?tr1=1.34&tr2=1.35&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/IndexedPool.java
diff -u storm/org/nongnu/storm/IndexedPool.java:1.5 
storm/org/nongnu/storm/IndexedPool.java:1.6
--- storm/org/nongnu/storm/IndexedPool.java:1.5 Mon Apr 21 17:07:41 2003
+++ storm/org/nongnu/storm/IndexedPool.java     Thu May 22 18:41:05 2003
@@ -94,6 +94,16 @@
        public Mapping(BlockId b, String k, String v) { 
            block=b; key=k; value=v; 
        }
+       public boolean equals(Object o) {
+           if(!(o instanceof Mapping)) return false;
+           Mapping m = (Mapping)o;
+           return block.equals(m.block) && key.equals(m.key) &&
+               value.equals(m.value);
+       }
+       public int hashCode() {
+
+           return block.hashCode() ^ 3*key.hashCode() ^ -value.hashCode();
+       }
     }
 
     interface DB {
Index: storm/org/nongnu/storm/modules/gispmap/GispPeer.java
diff -u storm/org/nongnu/storm/modules/gispmap/GispPeer.java:1.8 
storm/org/nongnu/storm/modules/gispmap/GispPeer.java:1.9
--- storm/org/nongnu/storm/modules/gispmap/GispPeer.java:1.8    Tue May 13 
08:36:02 2003
+++ storm/org/nongnu/storm/modules/gispmap/GispPeer.java        Thu May 22 
18:41:05 2003
@@ -30,6 +30,7 @@
 import org.nongnu.storm.impl.*;
 import org.nongnu.storm.impl.p2p.*;
 import org.nongnu.storm.pointers.PointerIndex;
+import org.nongnu.storm.pointers.TitleIndex;
 import org.nongnu.storm.util.HTTPProxy;
 import org.nongnu.storm.util.HtmlLinkIndex;
 
@@ -57,6 +58,7 @@
        Set indexTypes = new HashSet();
        indexTypes.add(HtmlLinkIndex.type);
        indexTypes.add(PointerIndex.type);
+       indexTypes.add(TitleIndex.type);
 
        int i=0;
        while(i<argv.length) {
Index: storm/org/nongnu/storm/pointers/SetPointer.java
diff -u storm/org/nongnu/storm/pointers/SetPointer.java:1.5 
storm/org/nongnu/storm/pointers/SetPointer.java:1.6
--- storm/org/nongnu/storm/pointers/SetPointer.java:1.5 Wed May 21 20:14:08 2003
+++ storm/org/nongnu/storm/pointers/SetPointer.java     Thu May 22 18:41:05 2003
@@ -87,8 +87,12 @@
            target = new BlockId(argv[3]);
        }
 
+       String name = System.getProperty("setpointer.name");
+       if(argv.length > 4)
+           name = argv[4];
+
        PointerIndex idx = (PointerIndex)pool.getIndex(PointerIndex.uri);
-       idx.set(pointer, target, keys);
+       idx.set(pointer, target, keys, name);
 
        System.out.println("Set pointer");
        System.out.println(pointer);
Index: storm/org/nongnu/storm/pointers/TitleIndex.java
diff -u storm/org/nongnu/storm/pointers/TitleIndex.java:1.3 
storm/org/nongnu/storm/pointers/TitleIndex.java:1.4
--- storm/org/nongnu/storm/pointers/TitleIndex.java:1.3 Thu May 22 18:03:52 2003
+++ storm/org/nongnu/storm/pointers/TitleIndex.java     Thu May 22 18:41:05 2003
@@ -35,7 +35,7 @@
 
 public class TitleIndex {
     public static boolean dbg = false;
-    private static void p(String s) { System.out.println("PointerIndex:: "+s); 
}
+    private static void p(String s) { System.out.println("TitleIndex:: "+s); }
 
     public static final String uri =
        "http://fenfire.org/2003/05/pointer-title-index-0.1";;
@@ -44,9 +44,9 @@
 
     protected IndexedPool pool;
     protected IndexedPool.DB db;
-    protected PointerIndex pointerIndex;
 
     /** Returns a set of *current* pointer blocks.
+     *  XXX not async at all
      */
     public Set getPointers(String query) throws IOException {
        Iterator i=splitWords(query).iterator();
@@ -60,7 +60,7 @@
            IndexedPool.Mapping m = (IndexedPool.Mapping)i.next();
            try {
                PointerId id = new PointerId(m.value);
-               PointerBlock cur = pointerIndex.getPointerBlock(id);
+               PointerBlock cur = pointerIndex().getPointerBlock(id);
                if(cur.getBlockId().equals(m.block))
                    result.add(cur);
            } catch(Throwable _) {
@@ -81,7 +81,7 @@
 
        String s = "";
        for(int i=0; i<title.length(); i++) {
-           char c = s.charAt(i);
+           char c = title.charAt(i);
            if(Character.isLetterOrDigit(c))
                s += c;
            else {
@@ -137,10 +137,12 @@
        }
     }
 
+    protected final PointerIndex pointerIndex() {
+       return (PointerIndex)pool.getIndex(PointerIndex.uri);
+    }
+
     public TitleIndex(IndexedPool pool, IndexedPool.DB db) {
        this.pool = pool;
        this.db = db;
-       this.pointerIndex = 
-           (PointerIndex)pool.getIndex(PointerIndex.uri);
     }
 }
Index: storm/org/nongnu/storm/util/HTTPProxy.java
diff -u storm/org/nongnu/storm/util/HTTPProxy.java:1.34 
storm/org/nongnu/storm/util/HTTPProxy.java:1.35
--- storm/org/nongnu/storm/util/HTTPProxy.java:1.34     Wed May 21 20:17:39 2003
+++ storm/org/nongnu/storm/util/HTTPProxy.java  Thu May 22 18:41:05 2003
@@ -34,8 +34,7 @@
 import org.nongnu.storm.pointers.*;
 import java.io.*;
 import java.net.*;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
+import java.util.*;
 import java.security.*;
 
 /** An HTTP server serving blocks from a Storm pool. When started from command 
@@ -52,6 +51,7 @@
     protected String REWRITE;
     protected String URNPAC;
     protected String BACKLINKS;
+    protected String QUERY = "search?q=";
     protected HTTPServer server;
 
     protected boolean acceptPut = false;
@@ -108,6 +108,8 @@
 
                if(uri.equals(URNPAC))
                    return makePAC(req, resf);
+               if(uri.startsWith(QUERY))
+                   return query(req, resf, uri);
 
                String element;
                while(!uri.startsWith("urn:")) {
@@ -328,6 +330,38 @@
            return s;
        }
 
+       protected HTTPResponse query(HTTPRequest req, 
+                                    HTTPResponse.Factory resf,
+                                    String uri) throws IOException {
+           String query = uri.substring(QUERY.length());
+
+           TitleIndex idx =
+               (TitleIndex)pool.getIndex(TitleIndex.uri);
+
+           HTTPResponse resp = resf.makeResponse(200, "Ok");
+           resp.setField("Content-Type", "text/html;charset=UTF-8");
+
+           Writer w = new OutputStreamWriter(resp.getOutputStream(), 
+                                             "US-ASCII");
+           w.write("<html><head><title>"+query+"</title></head><body>\n");
+           w.write("<h1>Results for '"+query+"'</h1>\n\n");
+
+           Set pBlocks = idx.getPointers(query);
+
+           if(pBlocks.isEmpty()) w.write("<p>No results.</p>\n\n");
+
+           for(Iterator i=pBlocks.iterator(); i.hasNext();) {
+               PointerBlock p = (PointerBlock)i.next();
+               w.write("<p><b><a href=\""+p.getPointer().getURI()+"\">");
+               w.write(p.getName()+"</a></b><br />\n");
+               w.write("<small>"+p.getPointer().getURI()+"</small></p>\n\n");
+           }
+
+           w.write("</body></html>\n");
+           w.close();
+           return resp;
+       }
+
        protected HTTPResponse makePAC(HTTPRequest req, 
                                       HTTPResponse.Factory resf) 
            throws IOException {
@@ -429,8 +463,10 @@
     public static void main(String[] args) throws Exception {
        dbg = true;
        IndexedPool pool;
-       java.util.Set indexTypes = 
-           java.util.Collections.singleton(PointerIndex.type);
+       Set indexTypes = new HashSet();
+       indexTypes.add(HtmlLinkIndex.type);
+       indexTypes.add(PointerIndex.type);
+       indexTypes.add(TitleIndex.type);
        pool = new DirPool(new File(args[0]), indexTypes);
 
        if(args.length == 1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]