[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/kitten
From:       Jos van den Oever <jos () vandenoever ! info>
Date:       2006-06-07 15:44:46
Message-ID: 1149695086.348730.14219.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 549150 by vandenoever:

Show fragment of document in GUI

 M  +1 -1      rebuild.sh  
 M  +6 -2      src/daemon/interface.cpp  
 M  +3 -1      src/daemon/socketclient.cpp  
 M  +10 -0     src/daemon/socketserver.cpp  
 M  +3 -4      src/estraierindexer/estraierindexreader.cpp  
 M  +0 -1      src/luceneindexer/cluceneindexmanager.cpp  
 M  +16 -1     src/luceneindexer/cluceneindexreader.cpp  
 M  +8 -3      src/luceneindexer/cluceneindexwriter.cpp  
 M  +7 -3      src/searchclient/simplesearchgui.cpp  
 M  +0 -1      src/streamindexer/indexreader.cpp  
 M  +2 -1      src/streamindexer/indexreader.h  


--- trunk/playground/base/kitten/rebuild.sh #549149:549150
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 # directory with clucene binaries and header
-CLUCENESRCDIR=/tmp/clucene/src
+CLUCENESRCDIR=/tmp/clucene/clucene/src
 #CLUCENESRCDIR=.
 
 rm -rf autom4te.cache configure COPYING depcomp INSTALL install-sh Makefile.in \
--- trunk/playground/base/kitten/src/daemon/interface.cpp #549149:549150
@@ -11,9 +11,13 @@
     Query q(query);
     vector<IndexedDocument> docs = manager.getIndexReader()->query(q);
     Hits hits;
-    for (uint i=0; i < docs.size(); ++i) {
+    vector<IndexedDocument>::const_iterator i;
+    for (i = docs.begin(); i != docs.end(); ++i) {
         Hit h;
-        h.uri = docs[i].filepath;
+        h.uri = i->filepath;
+        h.fragment = i->fragment;
+        h.score = i->score;
+        h.properties = i->properties;
         hits.hits.push_back(h);
     }
     return hits;
--- trunk/playground/base/kitten/src/daemon/socketclient.cpp #549149:549150
@@ -107,9 +107,11 @@
     sendRequest(sd);
     readResponse(sd);
     close(sd);
-    for (uint i=0; i<response.size(); ++i) {
+    for (uint i=0; i+2<response.size(); i += 3) {
         Hit h;
         h.uri = response[i];
+        h.fragment = response[i+1];
+        h.score = atof(response[i+2].c_str());
         hits.hits.push_back(h);
     }
     return hits;
--- trunk/playground/base/kitten/src/daemon/socketserver.cpp #549149:549150
@@ -1,5 +1,6 @@
 #include "socketserver.h"
 #include "interface.h"
+#include <sstream>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -121,8 +122,17 @@
         ClientInterface::Hits hits = interface->query(request[1]);
         response.clear();
         vector<ClientInterface::Hit>::const_iterator i;
+        ostringstream score;
         for (i = hits.hits.begin(); i != hits.hits.end(); ++i) {
             response.push_back(i->uri);
+            if (i->fragment.length()) {
+                response.push_back(i->fragment);
+            } else {
+                response.push_back(" ");
+            }
+            score << i->score;
+            response.push_back(score.str());
+            score.str("");
         }
         return;
     }
--- trunk/playground/base/kitten/src/estraierindexer/estraierindexreader.cpp #549149:549150
@@ -75,9 +75,8 @@
 }
 string
 EstraierIndexReader::getFragment(int id, const Query& query) {
-    printf("--\n");
     ESTDOC* doc = est_db_get_doc(db, id, ESTGDNOATTR|ESTGDNOKWD);
-    char*f = est_doc_cat_texts(doc);
+    char* f = est_doc_cat_texts(doc);
     string fragment = f;
 //    printf("%s\n", f);
     free(f);
@@ -100,10 +99,10 @@
         if (uri) {
             IndexedDocument doc;
             doc.filepath = uri;
-            results.push_back(doc);
-            free(uri);
             doc.score = est_cond_score(cond, i);
             doc.fragment = getFragment(id, query);
+            results.push_back(doc);
+            free(uri);
         }
     }
     manager->deref();
--- trunk/playground/base/kitten/src/luceneindexer/cluceneindexmanager.cpp #549149:549150
@@ -108,7 +108,6 @@
 void
 CLuceneIndexManager::closeWriter() {
     if (indexwriter == 0) return;
-    indexwriter->optimize();
     indexwriter->close();
     delete indexwriter;
     indexwriter = 0;
--- trunk/playground/base/kitten/src/luceneindexer/cluceneindexreader.cpp #549149:549150
@@ -6,6 +6,7 @@
 using lucene::search::Hits;
 using lucene::search::IndexSearcher;
 using lucene::document::Document;
+using lucene::document::Field;
 using lucene::index::Term;
 using lucene::search::TermQuery;
 using lucene::search::BooleanQuery;
@@ -75,10 +76,24 @@
     STRCPY_AtoT(tf, "path", CL_MAX_DIR);
     for (int i = 0; i < s; ++i) {
         Document *d = &hits->doc(i);
-        const wchar_t *v = d->get(tf);
+        const TCHAR* v = d->get(tf);
         STRCPY_TtoA(path, v, CL_MAX_DIR);
         IndexedDocument doc;
         doc.filepath = path;
+        doc.score = hits->score(i);
+        Field* f = d->getField(_T("content"));
+        if (f) {
+            v = f->stringValue();
+            STRCPY_TtoA(path, v, CL_MAX_DIR);
+            // remove newlines
+            char *p = path;
+            while (true) {
+                if (*p == '\0') break;
+                if (*p == '\n' || *p == '\r') *p = ' ';
+                p++;
+            }
+            doc.fragment = path;
+        }
         results.push_back(doc);
     }
     delete hits;
--- trunk/playground/base/kitten/src/luceneindexer/cluceneindexwriter.cpp #549149:549150
@@ -71,10 +71,15 @@
         StringReader<char> sr(doc->content.c_str(), doc->content.length(),
             false);
         InputStreamReader streamreader(&sr);
-        Reader* reader = new Reader(&streamreader, false);
-        doc->doc.add( *Field::Text(L"content", reader) );
+        const wchar_t* data;
+        int32_t nread = streamreader.read(data, 10000000, 0);
+        if (nread > 0) {
+            wchar_t *naughty = (wchar_t*)(data);
+            naughty[nread-1] = '\0';
+            doc->doc.add(*Field::Text(L"content", naughty));
+        }
 #else
-        doc->doc.add(*Field::Text("content", doc->content.c_str()));
+        doc->doc.add(*Field::Text("content", doc->content.c_str());
 #endif
         lucene::index::IndexWriter* writer = manager->refWriter();
         try {
--- trunk/playground/base/kitten/src/searchclient/simplesearchgui.cpp #549149:549150
@@ -190,8 +190,9 @@
         QString html;
         if (hits.error.length() == 0) {
             itemview->setEnabled(true);
-            for (uint i=0; i<hits.hits.size(); ++i) {
-                QString path = hits.hits[i].uri.c_str();
+            vector<ClientInterface::Hit>::const_iterator i;
+            for (i = hits.hits.begin(); i != hits.hits.end(); ++i) {
+                QString path = i->uri.c_str();
                 QString name;
                 int l = path.lastIndexOf('/');
                 html += "<div><a href='"+path+"'>";
@@ -203,7 +204,10 @@
                 } else {
                     html += path;
                 }
-                html += "</a></div>";
+                html += "</a><br/>score: ";
+                html += QString::number(i->score) + "<br/><i>";
+                html += QString(i->fragment.c_str()).left(100).replace("<", "&lt;");
+                html += "</i></div>";
             }
         } else {
             html = "<h2>";html+=hits.error.c_str();html+="</h2>";
--- trunk/playground/base/kitten/src/streamindexer/indexreader.cpp #549149:549150
@@ -99,4 +99,3 @@
     if (p != '\0') p++;
     return p;
 }
-
--- trunk/playground/base/kitten/src/streamindexer/indexreader.h #549149:549150
@@ -8,7 +8,8 @@
 
 namespace jstreams {
 
-struct IndexedDocument {
+class IndexedDocument {
+public:
     IndexedDocument() :score(0) {}
     std::string filepath;
     std::string fragment;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic