[Xapian-devel] Adding an external library to Xapian

Siddhant Mutha siddhantmutha at gmail.com
Sun Apr 13 16:16:09 BST 2014


We are using the --enable-maintainer-mode and will move to git soon.
The diff file is attached.

*Siddhant Mutha*
Undergraduate Student
Department of Computer Science and Engineering
IIT Madras
Chennai
http://www.siddhantmutha.com/ <http:/www.siddhantmutha.com/>


On Sun, Apr 13, 2014 at 8:26 PM, James Aylett <james-xapian at tartarus.org>wrote:

> On 13 Apr 2014, at 15:48, Pallavi Gudipati <pallavigudipati at gmail.com>
> wrote:
>
> > My code is not on Github. I am using the tarball as of now. The
> following it the error that occurred:
> > http://pastebin.com/cVJrjUZX
>
> Okay; looks like you've changed simpleexpand.cc to use features you've
> added to the main Xapian library. Three things:
>
> 1. did you use configure --enable-maintainer-mode? If not, changes to
> Makefile.mk (and other parts of the build system) won't be used, because
> the Makefile that drives the build system won't be regenerated.
>
> 2. if that doesn't help, I need a patch between the tarball source and
> yours to see what you've changed and help further.
>
> 3. I'd strongly recommend using version control, for various reasons. git
> is very common, has plenty of tutorial articles to get you going, and plays
> well with the way we develop Xapian. github is free to use, and convenient
> (and Xapian's source is on there), or some people prefer gitorious
> (Xapian's on there also).
>
> J
>
> --
>  James Aylett, occasional trouble-maker
>  xapian.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xapian.org/pipermail/xapian-devel/attachments/20140413/532117e4/attachment-0001.html>
-------------- next part --------------
diff -ur xapian-core-1.2.17-o/api/expanddecider.cc xapian-core-1.2.17/api/expanddecider.cc
--- xapian-core-1.2.17-o/api/expanddecider.cc	2014-01-29 08:28:01.000000000 +0530
+++ xapian-core-1.2.17/api/expanddecider.cc	2014-04-12 22:22:09.000000000 +0530
@@ -45,4 +45,10 @@
     return i == rejects.end();
 }
 
+bool
+ExpandDeciderQueryCompletion::operator()(const string &term) const
+{
+	return true;
+}
+
 }
diff -ur xapian-core-1.2.17-o/api/Makefile.mk xapian-core-1.2.17/api/Makefile.mk
--- xapian-core-1.2.17-o/api/Makefile.mk	2014-01-29 08:28:01.000000000 +0530
+++ xapian-core-1.2.17/api/Makefile.mk	2014-04-13 20:20:53.000000000 +0530
@@ -36,4 +36,5 @@
 	api/valueiterator.cc\
 	api/valuerangeproc.cc\
 	api/valuesetmatchdecider.cc\
-	api/version.cc
+	api/version.cc\
+	api/trie.cc
diff -ur xapian-core-1.2.17-o/api/omdatabase.cc xapian-core-1.2.17/api/omdatabase.cc
--- xapian-core-1.2.17-o/api/omdatabase.cc	2014-01-29 08:28:01.000000000 +0530
+++ xapian-core-1.2.17/api/omdatabase.cc	2014-04-13 17:56:04.000000000 +0530
@@ -43,6 +43,10 @@
 #include "ortermlist.h"
 #include "noreturn.h"
 
+// TODO remove later
+#include <iostream>
+#include <fstream>
+
 #include <cstdlib> // For abs().
 
 #include <cstring>
@@ -94,6 +98,18 @@
     LOGCALL_DTOR(API, "Database");
 }
 
+// LOG Function
+void
+Database::log(const std::string &query) {
+	cout << "In Database::log" << endl;
+	// For now usind DB's UUID to record logs
+	string logname = "../logs/" + this->get_uuid();
+	cout << "Log file: " << logname << "Query " << query << endl; 
+	std::ofstream logfile(logname.c_str(), ios::out | ios::app);
+	logfile << query << endl;
+    logfile.close();
+}
+
 void
 Database::reopen()
 {
diff -ur xapian-core-1.2.17-o/api/omenquire.cc xapian-core-1.2.17/api/omenquire.cc
--- xapian-core-1.2.17-o/api/omenquire.cc	2014-01-29 08:28:01.000000000 +0530
+++ xapian-core-1.2.17/api/omenquire.cc	2014-04-13 17:50:07.000000000 +0530
@@ -22,6 +22,10 @@
  * USA
  */
 
+// TODO remove it afterwards
+#include <iostream>
+#include <fstream>
+
 #include <config.h>
 #include "xapian/enquire.h"
 
@@ -650,7 +654,16 @@
 			    const MatchDecider *mdecider,
 			    const MatchDecider *matchspy_legacy) const
 {
-    LOGCALL(MATCH, MSet, "Enquire::Internal::get_mset", first | maxitems | check_at_least | rset | mdecider | matchspy_legacy);
+	/*
+	cout << "In Enquire::Internal::get_mset" << endl;
+	// For now usind DB's UUID to record logs
+	string logname = "../logs/" + db.get_uuid();
+	cout << "Log file: " << logname << "Query " << query.serialise() << endl; 
+	std::ofstream logfile(logname.c_str(), ios::out | ios::app);
+	logfile << query.serialise() << endl;
+    logfile.close();	
+    */
+	LOGCALL(MATCH, MSet, "Enquire::Internal::get_mset", first | maxitems | check_at_least | rset | mdecider | matchspy_legacy);
 
     if (percent_cutoff && (sort_by == VAL || sort_by == VAL_REL)) {
 	throw Xapian::UnimplementedError("Use of a percentage cutoff while sorting primary by value isn't currently supported");
@@ -701,6 +714,7 @@
                     const RSet & rset, int flags, double k,
 		    const ExpandDecider * edecider, Xapian::weight min_wt) const
 {
+	cout << "In Enquire::Internal::get_eset : 6 args" << endl;
     LOGCALL(MATCH, ESet, "Enquire::Internal::get_eset", maxitems | rset | flags | k | edecider | min_wt);
 
     if (maxitems == 0 || rset.empty()) {
@@ -1012,6 +1026,15 @@
 		  const MatchDecider *mdecider,
 		  const MatchDecider *matchspy) const
 {
+	cout << " In Enquire::get_mser" << endl;
+	// For now storing the logs in a file with the DB's UUID
+	/*
+	string logname = (internal->db).get_uuid();
+	std::ofstream logfile(logname, ios::out | ios::app);
+	Xapian::Query logquery = this->get_query();
+	// logfile << (get_query).serialise << endl;
+    logfile.close();	
+*/
     LOGCALL(API, Xapian::MSet, "Xapian::Enquire::get_mset", first | maxitems | check_at_least | rset | mdecider | matchspy);
 
     try {
@@ -1028,7 +1051,15 @@
 		  Xapian::doccount check_at_least, const RSet *rset,
 		  const MatchDecider *mdecider) const
 {
-    LOGCALL(API, Xapian::MSet, "Xapian::Enquire::get_mset", first | maxitems | check_at_least | rset | mdecider);
+	cout << "In Enquire::get_mset : 5 args" << endl;
+	// For now storing the logs in a file with the DB's UUID
+	/*
+	string logname = db.get_uuid();
+	ofstream logfile(logname, ios::out | ios::app);
+	logfile << (internal->get_query).serialise() << endl;
+    logfile.close();	
+    */
+	LOGCALL(API, Xapian::MSet, "Xapian::Enquire::get_mset", first | maxitems | check_at_least | rset | mdecider);
 
     try {
 	RETURN(internal->get_mset(first, maxitems, check_at_least, rset,
@@ -1043,6 +1074,7 @@
 Enquire::get_eset(Xapian::termcount maxitems, const RSet & rset, int flags,
 		  double k, const ExpandDecider * edecider) const
 {
+	cout << "In Enquire::Internal::get_eset : 5 args" << endl;
     LOGCALL(API, Xapian::ESet, "Xapian::Enquire::get_eset", maxitems | rset | flags | k | edecider);
 
     try {
@@ -1057,6 +1089,7 @@
 Enquire::get_eset(Xapian::termcount maxitems, const RSet & rset, int flags,
 		  double k, const ExpandDecider * edecider, Xapian::weight min_wt) const
 {
+	cout << "In Enquire::Internal::get_eset : 6 args" << endl;
     LOGCALL(API, Xapian::ESet, "Xapian::Enquire::get_eset", maxitems | rset | flags | k | edecider | min_wt);
 
     try {
diff -ur xapian-core-1.2.17-o/examples/simpleexpand.cc xapian-core-1.2.17/examples/simpleexpand.cc
--- xapian-core-1.2.17-o/examples/simpleexpand.cc	2014-01-29 08:27:44.000000000 +0530
+++ xapian-core-1.2.17/examples/simpleexpand.cc	2014-04-13 19:45:23.000000000 +0530
@@ -20,6 +20,8 @@
 
 #include <xapian.h>
 
+#include "/usr/local/WordNet-3.0/include/wn.h"
+
 #include <iostream>
 #include <string>
 
@@ -33,23 +35,29 @@
 try {
     // We require at least two command line arguments.
     if (argc < 3) {
-	int rc = 1;
-	if (argv[1]) {
-	    if (strcmp(argv[1], "--version") == 0) {
-		cout << "simpleexpand" << endl;
-		exit(0);
-	    }
-	    if (strcmp(argv[1], "--help") == 0) {
-		rc = 0;
-	    }
-	}
-	cout << "Usage: " << argv[0] << " PATH_TO_DATABASE QUERY [-- [DOCID...]]" << endl;
-	exit(rc);
-    }
+		int rc = 1;
+		if (argv[1]) {
+			if (strcmp(argv[1], "--version") == 0) {
+			cout << "simpleexpand" << endl;
+			exit(0);
+			}
+			if (strcmp(argv[1], "--help") == 0) {
+			rc = 0;
+			}
+		}
+		cout << "Usage: " << argv[0] << " PATH_TO_DATABASE QUERY [-- [DOCID...]]" 
+			 << endl;
+		exit(rc);
+    }
+	// Trying out WordNet stuff.
+	// cout << ALL_POS << ALLSENSES << endl;
+	// char *syns = findtheinfo(argv[2], ALL_POS, 23, ALLSENSES);
+	// cout << syns << endl;
 
     // Open the database for searching.
     Xapian::Database db(argv[1]);
 
+
     // Start an enquire session.
     Xapian::Enquire enquire(db);
 
@@ -59,18 +67,29 @@
     string query_string(argv[2]);
     argv += 3;
     while (*argv && strcmp(*argv, "--") != 0) {
-	query_string += ' ';
-	query_string += *argv++;
+		query_string += ' ';
+		query_string += *argv++;
     }
 
     // Create an RSet with the listed docids in.
     Xapian::RSet rset;
     if (*argv) {
-	while (*++argv) {
-	    rset.add_document(atoi(*argv));
-	}
+		while (*++argv) {
+			rset.add_document(atoi(*argv));
+		}
     }
 
+	// Log the query
+	db.log(query_string);
+	// DB syns
+	Xapian::TermIterator tmiter = db.synonyms_begin(query_string);
+	Xapian::TermIterator tmiterend = db.synonyms_end(query_string);
+	for(;tmiter != tmiterend; ++tmiter) {
+		cout << "hello" << endl;
+		cout << *tmiter << endl;
+	}
+
+	Xapian::Trie trie;
     // Parse the query string to produce a Xapian::Query object.
     Xapian::QueryParser qp;
     Xapian::Stem stemmer("english");
@@ -88,19 +107,19 @@
     cout << matches.get_matches_estimated() << " results found:" << endl;
 
     for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i) {
-	cout << i.get_rank() + 1 << ": " << i.get_percent() << "% docid=" << *i
-	     << " [" << i.get_document().get_data() << "]\n\n";
+		cout << i.get_rank() + 1 << ": " << i.get_percent() << "% docid=" << *i
+			 << " [" << i.get_document().get_data() << "]\n\n";
     }
 
     // If no relevant docids were given, invent an RSet containing the top 5
     // matches (or all the matches if there are less than 5).
     if (rset.empty()) {
-	int c = 5;
-	Xapian::MSetIterator i = matches.begin();
-	while (c-- && i != matches.end()) {
-	    rset.add_document(*i);
-	    ++i;
-	}
+		int c = 5;
+		Xapian::MSetIterator i = matches.begin();
+		while (c-- && i != matches.end()) {
+			rset.add_document(*i);
+			++i;
+		}
     }
 
     // Generate an ESet containing terms that the user might want to add to
@@ -110,7 +129,7 @@
     // List the terms.
     Xapian::ESetIterator t;
     for (t = eset.begin(); t != eset.end(); ++t) {
-	cout << *t << ": weight = " << t.get_weight() << endl;
+		cout << *t << ": weight = " << t.get_weight() << endl;
     }
 } catch (const Xapian::Error &e) {
     cout << e.get_description() << endl;
diff -ur xapian-core-1.2.17-o/expand/esetinternal.cc xapian-core-1.2.17/expand/esetinternal.cc
--- xapian-core-1.2.17-o/expand/esetinternal.cc	2014-01-29 08:28:01.000000000 +0530
+++ xapian-core-1.2.17/expand/esetinternal.cc	2014-04-13 17:38:14.000000000 +0530
@@ -21,6 +21,9 @@
 
 #include <config.h>
 
+// TODO Remove this afterwards.
+#include <iostream>
+
 #include "esetinternal.h"
 
 #include "xapian/enquire.h"
@@ -142,6 +145,7 @@
 		       const Xapian::Internal::ExpandWeight & eweight,
 		       Xapian::weight min_wt)
 {
+	cout << "In Eset::Internal::expand" << endl;
     LOGCALL_VOID(EXPAND, "ESet::Internal::expand", max_esize | db | rset | edecider | eweight);
     // These two cases are handled by our caller.
     Assert(max_esize);
@@ -168,7 +172,11 @@
 	string term = tree->get_termname();
 
 	// If there's an ExpandDecider, see if it accepts the term.
-	if (edecider && !(*edecider)(term)) continue;
+	if (edecider && !(*edecider)(term)) {
+		continue;
+	} else {
+	//	cout << term << endl;
+	}
 
 	++ebound;
 
diff -ur xapian-core-1.2.17-o/include/Makefile.mk xapian-core-1.2.17/include/Makefile.mk
--- xapian-core-1.2.17-o/include/Makefile.mk	2014-01-29 08:27:47.000000000 +0530
+++ xapian-core-1.2.17/include/Makefile.mk	2014-04-13 19:47:41.000000000 +0530
@@ -36,7 +36,8 @@
 	include/xapian/valueiterator.h\
 	include/xapian/valuesetmatchdecider.h\
 	include/xapian/visibility.h\
-	include/xapian/weight.h
+	include/xapian/weight.h\
+	include/xapian/trie.h
 
 nodist_xapianinclude_HEADERS =\
 	include/xapian/version.h
diff -ur xapian-core-1.2.17-o/include/xapian/database.h xapian-core-1.2.17/include/xapian/database.h
--- xapian-core-1.2.17-o/include/xapian/database.h	2014-01-29 08:27:47.000000000 +0530
+++ xapian-core-1.2.17/include/xapian/database.h	2014-04-13 17:55:59.000000000 +0530
@@ -119,6 +119,10 @@
 	 */
 	void operator=(const Database &other);
 
+	// LOGS
+	void log(const std::string &query);
+
+
 	/** Re-open the database.
 	 *
 	 *  This re-opens the database(s) to the latest available version(s).
diff -ur xapian-core-1.2.17-o/include/xapian/expanddecider.h xapian-core-1.2.17/include/xapian/expanddecider.h
--- xapian-core-1.2.17-o/include/xapian/expanddecider.h	2014-01-29 08:27:47.000000000 +0530
+++ xapian-core-1.2.17/include/xapian/expanddecider.h	2014-04-12 22:16:53.000000000 +0530
@@ -96,6 +96,14 @@
     virtual bool operator()(const std::string &term) const;
 };
 
+class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderQueryCompletion : 
+public ExpandDecider {
+
+  public:
+	// For now allow all terms.
+    virtual bool operator()(const std::string &term) const;
+};
+
 }
 
 #endif // XAPIAN_INCLUDED_EXPANDDECIDER_H
diff -ur xapian-core-1.2.17-o/include/xapian.h xapian-core-1.2.17/include/xapian.h
--- xapian-core-1.2.17-o/include/xapian.h	2014-01-29 08:27:47.000000000 +0530
+++ xapian-core-1.2.17/include/xapian.h	2014-04-13 19:09:25.000000000 +0530
@@ -84,6 +84,9 @@
 // ELF visibility annotations for GCC.
 #include <xapian/visibility.h>
 
+// Trie
+#include <xapian/trie.h>
+
 /// The Xapian namespace contains public interfaces for the Xapian library.
 namespace Xapian {
 
diff -ur xapian-core-1.2.17-o/Makefile.am xapian-core-1.2.17/Makefile.am
--- xapian-core-1.2.17-o/Makefile.am	2014-01-29 08:28:05.000000000 +0530
+++ xapian-core-1.2.17/Makefile.am	2014-04-13 14:47:21.000000000 +0530
@@ -125,10 +125,11 @@
 m4datadir = $(datadir)/aclocal
 dist_m4data_DATA = m4-macros/xapian.m4
 
+wordnet = -L/usr/local/WordNet-3.0/lib/ -lWN
 libxapian_la = libxapian.la
 lib_LTLIBRARIES = libxapian.la
 libxapian_la_SOURCES = $(lib_src)
-libxapian_la_LIBADD = $(XAPIAN_LIBS)
+libxapian_la_LIBADD =  $(wordnet) $(XAPIAN_LIBS)  
 libxapian_la_LDFLAGS = \
     $(XAPIAN_LDFLAGS) -no-undefined -version-info $(LIBRARY_VERSION_INFO)
 


More information about the Xapian-devel mailing list