상속: IDisposable
예제 #1
0
    public static void Main(string[] argv)
    {
        // We require at least two command line arguments.
        if (argv.Length < 2)
        {
            Console.Error.WriteLine("Usage: SimpleSearch PATH_TO_DATABASE QUERY");
            Environment.Exit(1);
        }

        try {
            // Open the database for searching.
            Xapian.Database database = new Xapian.Database(argv[0]);

            // Start an enquire session.
            Xapian.Enquire enquire = new Xapian.Enquire(database);

            // Combine the rest of the command line arguments with spaces
            // between them, so that simple queries don't have to be quoted at
            // the shell level.
            string query_string = argv[1];
            for (int i = 2; i < argv.Length; ++i)
            {
                query_string += ' ';
                query_string += argv[i];
            }

            // Parse the query string to produce a Xapian::Query object.
            Xapian.QueryParser qp      = new Xapian.QueryParser();
            Xapian.Stem        stemmer = new Xapian.Stem("english");
            qp.SetStemmer(stemmer);
            qp.SetDatabase(database);
            qp.SetStemmingStrategy(Xapian.QueryParser.stem_strategy.STEM_SOME);
            Xapian.Query query = qp.ParseQuery(query_string);
            Console.WriteLine("Parsed query is: " + query.GetDescription());

            // Find the top 10 results for the query.
            enquire.SetQuery(query);
            Xapian.MSet matches = enquire.GetMSet(0, 10);

            // Display the results.
            Console.WriteLine("{0} results found.", matches.GetMatchesEstimated());
            Console.WriteLine("Matches 1-{0}:", matches.Size());

            Xapian.MSetIterator m = matches.Begin();
            while (m != matches.End())
            {
                Console.WriteLine("{0}: {1}% docid={2} [{3}]\n",
                                  m.GetRank() + 1,
                                  m.GetPercent(),
                                  m.GetDocId(),
                                  m.GetDocument().GetData());
                ++m;
            }
        } catch (Exception e) {
            Console.Error.WriteLine("Exception: " + e.ToString());
            Environment.Exit(1);
        }
    }
예제 #2
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op, SWIGTYPE_p_std__vectorTXapian__Query_t subqs)
     : this(XapianPINVOKE.new_Query__SWIG_11((int)op, SWIGTYPE_p_std__vectorTXapian__Query_t.getCPtr(subqs)), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #3
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op, SWIGTYPE_p_std__vectorTstd__string_t subqs, uint param)
     : this(XapianPINVOKE.new_Query__SWIG_8((int)op, SWIGTYPE_p_std__vectorTstd__string_t.getCPtr(subqs), param), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #4
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op_, uint valno, string value)
     : this(XapianPINVOKE.new_Query__SWIG_7((int)op_, valno, value), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #5
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query copyme)
     : this(XapianPINVOKE.new_Query__SWIG_5(Query.getCPtr(copyme)), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #6
0
 public static Query Unserialise(string s, Registry registry)
 {
     Query ret = new Query(XapianPINVOKE.Query_Unserialise__SWIG_1(s, Registry.getCPtr(registry)), true);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
예제 #7
0
    public static void Main()
    {
        try {
        // Test the version number reporting functions give plausible
        // results.
        string v = "";
        v += Xapian.Version.Major();
        v += ".";
        v += Xapian.Version.Minor();
        v += ".";
        v += Xapian.Version.Revision();
        string v2 = Xapian.Version.String();
        if (v != v2) {
        System.Console.WriteLine("Unexpected version output (" + v + " != " + v2 + ")");
        System.Environment.Exit(1);
        }

        Xapian.Stem stem = new Xapian.Stem("english");
        Xapian.Document doc = new Xapian.Document();
        // Currently SWIG doesn't generate zero-byte clean code for
        // transferring strings between C# and C++.
        /*
        doc.SetData("a\0b");
        if (doc.GetData() == "a") {
        System.Console.WriteLine("GetData+SetData truncates at a zero byte");
        System.Environment.Exit(1);
        }
        if (doc.GetData() != "a\0b") {
        System.Console.WriteLine("GetData+SetData doesn't transparently handle a zero byte");
        System.Environment.Exit(1);
        }
        */
        doc.SetData("is there anybody out there?");
        doc.AddTerm("XYzzy");
        doc.AddPosting(stem.Apply("is"), 1);
        doc.AddPosting(stem.Apply("there"), 2);
        doc.AddPosting(stem.Apply("anybody"), 3);
        doc.AddPosting(stem.Apply("out"), 4);
        doc.AddPosting(stem.Apply("there"), 5);

        Xapian.WritableDatabase db = Xapian.InMemory.Open();
        db.AddDocument(doc);
        if (db.GetDocCount() != 1) {
        System.Environment.Exit(1);
        }

        if (doc.TermListCount() != 5) {
        System.Environment.Exit(1);
        }
        int count = 0;
        Xapian.TermIterator i = doc.TermListBegin();
        while (i != doc.TermListEnd()) {
        ++count;
        ++i;
        }
        if (count != 5) {
        System.Environment.Exit(1);
        }

        // Check exception handling for Xapian::DocNotFoundError.
        try {
        Xapian.Document doc2 = db.GetDocument(2);
        System.Console.WriteLine("Retrieved non-existent document: " + doc2.ToString());
        System.Environment.Exit(1);
        } catch (System.Exception e) {
        // We expect DocNotFoundError
        if (e.Message.Substring(0, 16) != "DocNotFoundError") {
            System.Console.WriteLine("Unexpected exception from accessing non-existent document: " + e.Message);
            System.Environment.Exit(1);
        }
        }

        // Check QueryParser parsing error.
        try {
        Xapian.QueryParser qp = new Xapian.QueryParser();
        qp.ParseQuery("test AND");
        System.Console.WriteLine("Successfully parsed bad query");
        System.Environment.Exit(1);
        } catch (System.Exception e) {
        if (e.Message != "QueryParserError: Syntax: <expression> AND <expression>") {
            System.Console.WriteLine("Exception string not as expected, got: '" + e.Message + "'");
            System.Environment.Exit(1);
        }
        }

        {
        Xapian.QueryParser qp = new Xapian.QueryParser();
        // FIXME: It would be better if the (uint) cast wasn't required
        // here.
        qp.ParseQuery("hello world", (uint)Xapian.QueryParser.feature_flag.FLAG_BOOLEAN);
        }

            if (Xapian.Query.MatchAll.GetDescription() != "Xapian::Query(<alldocuments>)") {
        System.Console.WriteLine("Unexpected Query.MatchAll.toString()");
        System.Environment.Exit(1);
            }

            if (Xapian.Query.MatchNothing.GetDescription() != "Xapian::Query()") {
        System.Console.WriteLine("Unexpected Query.MatchNothing.toString()");
        System.Environment.Exit(1);
            }

        // Check that OP_ELITE_SET works (in 0.9.6 and earlier it had the
        // wrong value in C#).
        try {
        Xapian.Query foo = new Xapian.Query(Xapian.Query.op.OP_OR, "hello", "world");
        Xapian.Query foo2 = new Xapian.Query(Xapian.Query.op.OP_ELITE_SET, foo, foo);
        foo = foo2; // Avoid "unused variable" warning.
        } catch (System.Exception e) {
        System.Console.WriteLine("Using OP_ELITE_SET cause exception '" + e.Message + "'");
        System.Environment.Exit(1);
        }

        // Feature test for MatchDecider.
        doc = new Xapian.Document();
        doc.SetData("Two");
        doc.AddPosting(stem.Apply("out"), 1);
        doc.AddPosting(stem.Apply("source"), 2);
        doc.AddValue(0, "yes");
        db.AddDocument(doc);

        Xapian.Query query = new Xapian.Query(stem.Apply("out"));
        Xapian.Enquire enquire = new Xapian.Enquire(db);
        enquire.SetQuery(query);
        Xapian.MSet mset = enquire.GetMSet(0, 10, null, new TestMatchDecider());
        if (mset.Size() != 1) {
        System.Console.WriteLine("MatchDecider found " + mset.Size().ToString() + " documents, expected 1");
        System.Environment.Exit(1);
        }
        if (mset.GetDocId(0) != 2) {
        System.Console.WriteLine("MatchDecider mset has wrong docid in");
        System.Environment.Exit(1);
        }

        mset = enquire.GetMSet(0, 10);
        for (Xapian.MSetIterator m = mset.Begin(); m != mset.End(); m++) {
        // In Xapian 1.2.6 and earlier, the iterator would become
        // eligible for garbage collection after being advanced.
        // It didn't actually get garbage collected often, but when
        // it did, it caused a crash.  Here we force a GC run to make
        // this issue manifest if it is present.
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        }

            // Test setting and getting metadata
            if (db.GetMetadata("Foo") !=  "") {
        System.Console.WriteLine("db.GetMetadata(\"Foo\") returned wrong value \"" + db.GetMetadata("Foo") + "\" - expected \"\"");
        System.Environment.Exit(1);
            }
            db.SetMetadata("Foo", "Foo");
            if (db.GetMetadata("Foo") !=  "Foo") {
        System.Console.WriteLine("db.GetMetadata(\"Foo\") returned wrong value \"" + db.GetMetadata("Foo") + "\" - expected \"Foo\"");
        System.Environment.Exit(1);
            }

        // Test OP_SCALE_WEIGHT and corresponding constructor
        Xapian.Query query4 = new Xapian.Query(Xapian.Query.op.OP_SCALE_WEIGHT, new Xapian.Query("foo"), 5.0);
        if (query4.GetDescription() != "Xapian::Query(5 * foo)") {
        System.Console.WriteLine("Unexpected query4.GetDescription()");
        System.Environment.Exit(1);
        }

        } catch (System.Exception e) {
        System.Console.WriteLine("Exception: " + e.ToString());
        System.Environment.Exit(1);
        }
    }
예제 #8
0
파일: Enquire.cs 프로젝트: kyeh/dormhost
 public Query GetQuery()
 {
     Query ret = new Query(XapianPINVOKE.Enquire_GetQuery(swigCPtr), false);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
예제 #9
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op_, Query q, double parameter)
     : this(XapianPINVOKE.new_Query__SWIG_13((int)op_, Query.getCPtr(q), parameter), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #10
0
 public void SetDefaultOp(Query.op default_op)
 {
     XapianPINVOKE.QueryParser_SetDefaultOp(swigCPtr, (int)default_op);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #11
0
 public Query ParseQuery(string query_string)
 {
     Query ret = new Query(XapianPINVOKE.QueryParser_ParseQuery__SWIG_2(swigCPtr, query_string), true);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
예제 #12
0
 public Query ParseQuery(string query_string, uint flags, string default_prefix)
 {
     Query ret = new Query(XapianPINVOKE.QueryParser_ParseQuery__SWIG_0(swigCPtr, query_string, flags, default_prefix), true);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
예제 #13
0
 public Query(Query.op op_, uint slot, string begin, string end)
     : this(XapianPINVOKE.new_Query__SWIG_10((int)op_, slot, begin, end), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #14
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op_, Query q)
     : this(XapianPINVOKE.new_Query__SWIG_12((int)op_, Query.getCPtr(q)), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #15
0
파일: Query.cs 프로젝트: kyeh/dormhost
 internal static HandleRef getCPtr(Query obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
예제 #16
0
    public static void Main(string[] argv)
    {
        // We require at least two command line arguments.
        if (argv.Length < 2)
        {
            Console.Error.WriteLine("Usage: SimpleExpand PATH_TO_DATABASE QUERY [-- [DOCID...]]");
            Environment.Exit(1);
        }

        try {
            // Open the database for searching.
            Xapian.Database database = new Xapian.Database(argv[0]);

            // Start an enquire session.
            Xapian.Enquire enquire = new Xapian.Enquire(database);

            // Create an RSet to add the listed docids to.
            Xapian.RSet rset = new Xapian.RSet();

            // Combine command line arguments up to "--" with spaces between
            // them, so that simple queries don't have to be quoted at the
            // shell level.
            string query_string = argv[1];
            for (int i = 2; i < argv.Length; ++i)
            {
                if (argv[i] == "--")
                {
                    while (++i < argv.Length)
                    {
                        rset.AddDocument(Convert.ToUInt32(argv[i]));
                    }
                    break;
                }
                query_string += ' ';
                query_string += argv[i];
            }

            // Parse the query string to produce a Xapian::Query object.
            Xapian.QueryParser qp      = new Xapian.QueryParser();
            Xapian.Stem        stemmer = new Xapian.Stem("english");
            qp.SetStemmer(stemmer);
            qp.SetDatabase(database);
            qp.SetStemmingStrategy(Xapian.QueryParser.stem_strategy.STEM_SOME);
            Xapian.Query query = qp.ParseQuery(query_string);
            Console.WriteLine("Parsed query is: " + query.GetDescription());

            // Find the top 10 results for the query.
            enquire.SetQuery(query);
            Xapian.MSet matches = enquire.GetMSet(0, 10, rset);

            // Display the results.
            Console.WriteLine("{0} results found.", matches.GetMatchesEstimated());
            Console.WriteLine("Matches 1-{0}:", matches.Size());

            Xapian.MSetIterator m = matches.Begin();
            while (m != matches.End())
            {
                Console.WriteLine("{0}: {1}% docid={2} [{3}]\n",
                                  m.GetRank() + 1,
                                  m.GetPercent(),
                                  m.GetDocId(),
                                  m.GetDocument().GetData());
                ++m;
            }

            // 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-- > 0 && i != matches.End())
                {
                    rset.AddDocument(i.GetDocId());
                    ++i;
                }
            }

            // Generate an ESet containing terms that the user might want to
            // add to the query.
            Xapian.ESet eset = enquire.GetESet(10, rset);

            Console.WriteLine(eset.Size());
            // List the terms.
            for (Xapian.ESetIterator t = eset.Begin(); t != eset.End(); ++t)
            {
                Console.WriteLine("{0}: weight = {1}",
                                  t.GetTerm(), t.GetWeight());
            }
        } catch (Exception e) {
            Console.Error.WriteLine("Exception: " + e.ToString());
            Environment.Exit(1);
        }
    }
예제 #17
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op_, Query left, Query right)
     : this(XapianPINVOKE.new_Query__SWIG_3((int)op_, Query.getCPtr(left), Query.getCPtr(right)), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #18
0
파일: Enquire.cs 프로젝트: kyeh/dormhost
 public void SetQuery(Query query)
 {
     XapianPINVOKE.Enquire_SetQuery__SWIG_1(swigCPtr, Query.getCPtr(query));
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #19
0
파일: Query.cs 프로젝트: kyeh/dormhost
 public Query(Query.op op_, string left, string right)
     : this(XapianPINVOKE.new_Query__SWIG_4((int)op_, left, right), true)
 {
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
 }
예제 #20
0
    public static void Main()
    {
        try {
            // Test the version number reporting functions give plausible
            // results.
            string v = "";
            v += Xapian.Version.Major();
            v += ".";
            v += Xapian.Version.Minor();
            v += ".";
            v += Xapian.Version.Revision();
            string v2 = Xapian.Version.String();
            if (v != v2)
            {
                System.Console.WriteLine("Unexpected version output (" + v + " != " + v2 + ")");
                System.Environment.Exit(1);
            }

            Xapian.Stem     stem = new Xapian.Stem("english");
            Xapian.Document doc  = new Xapian.Document();
            // Currently SWIG doesn't generate zero-byte clean code for
            // transferring strings between C# and C++.

            /*
             * doc.SetData("a\0b");
             * if (doc.GetData() == "a") {
             *  System.Console.WriteLine("GetData+SetData truncates at a zero byte");
             *  System.Environment.Exit(1);
             * }
             * if (doc.GetData() != "a\0b") {
             *  System.Console.WriteLine("GetData+SetData doesn't transparently handle a zero byte");
             *  System.Environment.Exit(1);
             * }
             */
            doc.SetData("is there anybody out there?");
            doc.AddTerm("XYzzy");
            doc.AddPosting(stem.Apply("is"), 1);
            doc.AddPosting(stem.Apply("there"), 2);
            doc.AddPosting(stem.Apply("anybody"), 3);
            doc.AddPosting(stem.Apply("out"), 4);
            doc.AddPosting(stem.Apply("there"), 5);

            Xapian.WritableDatabase db = Xapian.InMemory.Open();
            db.AddDocument(doc);
            if (db.GetDocCount() != 1)
            {
                System.Environment.Exit(1);
            }

            if (doc.TermListCount() != 5)
            {
                System.Environment.Exit(1);
            }
            int count             = 0;
            Xapian.TermIterator i = doc.TermListBegin();
            while (i != doc.TermListEnd())
            {
                ++count;
                ++i;
            }
            if (count != 5)
            {
                System.Environment.Exit(1);
            }

            // Check exception handling for Xapian::DocNotFoundError.
            try {
                Xapian.Document doc2 = db.GetDocument(2);
                System.Console.WriteLine("Retrieved non-existent document: " + doc2.ToString());
                System.Environment.Exit(1);
            } catch (System.Exception e) {
                // We expect DocNotFoundError
                if (e.Message.Substring(0, 16) != "DocNotFoundError")
                {
                    System.Console.WriteLine("Unexpected exception from accessing non-existent document: " + e.Message);
                    System.Environment.Exit(1);
                }
            }

            // Check QueryParser parsing error.
            try {
                Xapian.QueryParser qp = new Xapian.QueryParser();
                qp.ParseQuery("test AND");
                System.Console.WriteLine("Successfully parsed bad query");
                System.Environment.Exit(1);
            } catch (System.Exception e) {
                if (e.Message != "QueryParserError: Syntax: <expression> AND <expression>")
                {
                    System.Console.WriteLine("Exception string not as expected, got: '" + e.Message + "'");
                    System.Environment.Exit(1);
                }
            }

            {
                Xapian.QueryParser qp = new Xapian.QueryParser();
                // FIXME: It would be better if the (uint) cast wasn't required
                // here.
                qp.ParseQuery("hello world", (uint)Xapian.QueryParser.feature_flag.FLAG_BOOLEAN);
            }

            if (Xapian.Query.MatchAll.GetDescription() != "Xapian::Query(<alldocuments>)")
            {
                System.Console.WriteLine("Unexpected Query.MatchAll.toString()");
                System.Environment.Exit(1);
            }

            if (Xapian.Query.MatchNothing.GetDescription() != "Xapian::Query()")
            {
                System.Console.WriteLine("Unexpected Query.MatchNothing.toString()");
                System.Environment.Exit(1);
            }

            // Check that OP_ELITE_SET works (in 0.9.6 and earlier it had the
            // wrong value in C#).
            try {
                Xapian.Query foo  = new Xapian.Query(Xapian.Query.op.OP_OR, "hello", "world");
                Xapian.Query foo2 = new Xapian.Query(Xapian.Query.op.OP_ELITE_SET, foo, foo);
                foo = foo2; // Avoid "unused variable" warning.
            } catch (System.Exception e) {
                System.Console.WriteLine("Using OP_ELITE_SET cause exception '" + e.Message + "'");
                System.Environment.Exit(1);
            }

            // Feature test for MatchDecider.
            doc = new Xapian.Document();
            doc.SetData("Two");
            doc.AddPosting(stem.Apply("out"), 1);
            doc.AddPosting(stem.Apply("source"), 2);
            doc.AddValue(0, "yes");
            db.AddDocument(doc);

            Xapian.Query   query   = new Xapian.Query(stem.Apply("out"));
            Xapian.Enquire enquire = new Xapian.Enquire(db);
            enquire.SetQuery(query);
            Xapian.MSet mset = enquire.GetMSet(0, 10, null, new TestMatchDecider());
            if (mset.Size() != 1)
            {
                System.Console.WriteLine("MatchDecider found " + mset.Size().ToString() + " documents, expected 1");
                System.Environment.Exit(1);
            }
            if (mset.GetDocId(0) != 2)
            {
                System.Console.WriteLine("MatchDecider mset has wrong docid in");
                System.Environment.Exit(1);
            }


            // Test setting and getting metadata
            if (db.GetMetadata("Foo") != "")
            {
                System.Console.WriteLine("db.GetMetadata(\"Foo\") returned wrong value \"" + db.GetMetadata("Foo") + "\" - expected \"\"");
                System.Environment.Exit(1);
            }
            db.SetMetadata("Foo", "Foo");
            if (db.GetMetadata("Foo") != "Foo")
            {
                System.Console.WriteLine("db.GetMetadata(\"Foo\") returned wrong value \"" + db.GetMetadata("Foo") + "\" - expected \"Foo\"");
                System.Environment.Exit(1);
            }

            // Test OP_SCALE_WEIGHT and corresponding constructor
            Xapian.Query query4 = new Xapian.Query(Xapian.Query.op.OP_SCALE_WEIGHT, new Xapian.Query("foo"), 5.0);
            if (query4.GetDescription() != "Xapian::Query(5 * foo)")
            {
                System.Console.WriteLine("Unexpected query4.GetDescription()");
                System.Environment.Exit(1);
            }
        } catch (System.Exception e) {
            System.Console.WriteLine("Exception: " + e.ToString());
            System.Environment.Exit(1);
        }
    }
예제 #21
0
 public static Query Unserialise(string s)
 {
     Query ret = new Query(XapianPINVOKE.Query_Unserialise__SWIG_0(s), true);
     if (XapianPINVOKE.SWIGPendingException.Pending) throw XapianPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }