Ticket #473: querypostingsource.patch

File querypostingsource.patch, 9.1 KB (added by Richard Boulton, 15 years ago)

Old (probably non-functional) patch to implement this

  • xapian-core/include/xapian/querypostingsource.h

     
     1/** @file querypostingsource.h
     2 *  @brief A posting source based on a query.
     3 */
     4/* Copyright (C) 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or modify
     7 * it under the terms of the GNU General Public License as published by
     8 * the Free Software Foundation; either version 2 of the License, or
     9 * (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#ifndef XAPIAN_INCLUDED_QUERYPOSTINGSOURCE_H
     22#define XAPIAN_INCLUDED_QUERYPOSTINGSOURCE_H
     23
     24#include <xapian/postingsource.h>
     25
     26#include <string>
     27
     28namespace Xapian {
     29
     30class Database;
     31class Query;
     32class RSet;
     33class Weight;
     34
     35/// A posting source which returns all documents matching a query.
     36class XAPIAN_VISIBILITY_DEFAULT QueryPostingSource : public PostingSource {
     37  public:
     38    // Declaration of Internal has to be public, so that the friend
     39    // declaration in Query::Internal works.
     40    class Internal;
     41  private:
     42
     43    Internal * internal;
     44  public:
     45    /** Construct a QueryPostingSource from a given query.
     46     *
     47     *  @param q The query to construct the posting source from.
     48     */
     49    QueryPostingSource(Xapian::Database db,
     50                       const Xapian::Query & q,
     51                       const Xapian::RSet & rset,
     52                       const Xapian::Weight * wt_factory);
     53
     54    ~QueryPostingSource();
     55
     56    Xapian::doccount get_termfreq_min() const;
     57    Xapian::doccount get_termfreq_est() const;
     58    Xapian::doccount get_termfreq_max() const;
     59
     60    Xapian::weight get_maxweight() const;
     61    Xapian::weight get_weight() const;
     62
     63    void next(Xapian::weight min_wt);
     64    void skip_to(Xapian::docid did, Xapian::weight min_wt);
     65    bool check(Xapian::docid did, Xapian::weight min_wt);
     66
     67    bool at_end() const;
     68
     69    Xapian::docid get_docid() const;
     70
     71    void reset();
     72
     73    std::string get_description() const;
     74};
     75
     76}
     77
     78#endif // XAPIAN_INCLUDED_QUERYPOSTINGSOURCE_H
  • xapian-core/include/xapian/query.h

    Property changes on: xapian-core/include/xapian/querypostingsource.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
    2929#include <vector>
    3030
    3131#include <xapian/base.h>
     32#include <xapian/querypostingsource.h>
    3233#include <xapian/types.h>
    3334#include <xapian/termiterator.h>
    3435#include <xapian/visibility.h>
     
    278279    friend class ::MultiMatch;
    279280    friend class ::QueryOptimiser;
    280281    friend struct ::SortPosName;
     282    friend class Xapian::QueryPostingSource::Internal;
    281283    friend class Query;
    282284    public:
    283285        static const int OP_LEAF = -1;
  • xapian-core/include/xapian/enquire.h

     
    2727#include <string>
    2828
    2929#include <xapian/base.h>
     30#include <xapian/querypostingsource.h>
    3031#include <xapian/sorter.h>
    3132#include <xapian/types.h>
    3233#include <xapian/termiterator.h>
     
    10161017    friend class Enquire; // So Enquire can clone us
    10171018    friend class ::RemoteServer; // So RemoteServer can clone us - FIXME
    10181019    friend class ::ScaleWeight;
     1020    friend class QueryPostingSource::Internal;
    10191021    public:
    10201022        class Internal;
    10211023    protected:
  • xapian-core/include/Makefile.mk

     
    2525        include/xapian/postingsource.h\
    2626        include/xapian/query.h\
    2727        include/xapian/queryparser.h\
     28        include/xapian/querypostingsource.h\
    2829        include/xapian/replication.h\
    2930        include/xapian/sorter.h\
    3031        include/xapian/stem.h\
  • xapian-core/include/xapian.h

     
    4848#include <xapian/postingsource.h>
    4949#include <xapian/query.h>
    5050#include <xapian/queryparser.h>
     51#include <xapian/querypostingsource.h>
    5152#include <xapian/sorter.h>
    5253#include <xapian/valuesetmatchdecider.h>
    5354
  • xapian-core/api/Makefile.mk

     
    2424        api/omtermlistiterator.cc\
    2525        api/postingsource.cc\
    2626        api/postlist.cc\
     27        api/querypostingsource.cc\
    2728        api/replication.cc\
    2829        api/sortable-serialise.cc\
    2930        api/sorter.cc\
  • xapian-core/api/querypostingsource.cc

     
     1/** @file querypostingsource.cc
     2 *  @brief A posting source based on a query.
     3 */
     4/* Copyright (C) 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#include <config.h>
     22
     23#include "xapian/database.h"
     24#include "xapian/enquire.h"
     25#include "xapian/error.h"
     26#include "xapian/querypostingsource.h"
     27
     28#include "matcher/localmatch.h"
     29
     30namespace Xapian {
     31
     32class QueryPostingSource::Internal
     33{
     34    public:
     35        Database db;
     36        Query q;
     37        RSet rset;
     38        const Weight * wt_factory;
     39
     40        termcount qlen;
     41
     42        LocalSubMatch * matcher;
     43
     44        Internal(Database db_, const Query & q_, const RSet & rset_,
     45                 const Weight * wt_factory_);
     46        ~Internal();
     47
     48        void reset();
     49        bool at_end() const;
     50};
     51
     52QueryPostingSource::Internal::Internal(Database db_, const Query & q_,
     53                                       const RSet & rset_,
     54                                       const Weight * wt_factory_)
     55        : db(db_),
     56          q(q_),
     57          rset(rset_),
     58          wt_factory(NULL),
     59          qlen(q_.get_length()),
     60          matcher(NULL)
     61{
     62    if (wt_factory_ == NULL) {
     63        wt_factory = new BM25Weight();
     64    } else {
     65        wt_factory = wt_factory_->clone();
     66    }
     67    if (db.internal.size() != 1) {
     68        throw InvalidOperationError("QueryPostingSource needs to be passed a single database");
     69    }
     70    q.internal->validate_query();
     71}
     72
     73QueryPostingSource::Internal::~Internal()
     74{
     75    delete matcher;
     76    delete wt_factory;
     77}
     78
     79void
     80QueryPostingSource::Internal::reset()
     81{
     82    delete matcher;
     83
     84    if (q.internal.get() == 0) {
     85        matcher = NULL;
     86        return;
     87    }
     88
     89    matcher = new LocalSubMatch(db.internal[0].get(),
     90                                q.internal.get(),
     91                                qlen, rset,
     92                                wt_factory);
     93}
     94
     95
     96QueryPostingSource::QueryPostingSource(Database db,
     97                                       const Query & q,
     98                                       const RSet & rset,
     99                                       const Weight * wt_factory)
     100        : internal(new Internal(db, q, rset, wt_factory))
     101{
     102}
     103
     104QueryPostingSource::~QueryPostingSource()
     105{
     106    delete internal;
     107}
     108
     109doccount
     110QueryPostingSource::get_termfreq_min() const
     111{
     112}
     113
     114doccount
     115QueryPostingSource::get_termfreq_est() const
     116{
     117}
     118
     119doccount
     120QueryPostingSource::get_termfreq_max() const
     121{
     122}
     123
     124weight
     125QueryPostingSource::get_maxweight() const
     126{
     127}
     128
     129weight
     130QueryPostingSource::get_weight() const
     131{
     132}
     133
     134void
     135QueryPostingSource::next(weight min_wt)
     136{
     137}
     138
     139void
     140QueryPostingSource::skip_to(docid min_docid,
     141                            weight min_wt)
     142{
     143}
     144
     145bool
     146QueryPostingSource::check(docid min_docid,
     147                          weight min_wt)
     148{
     149}
     150
     151bool
     152QueryPostingSource::at_end() const
     153{
     154    return internal->at_end();
     155}
     156
     157docid
     158QueryPostingSource::get_docid() const
     159{
     160}
     161
     162void
     163QueryPostingSource::reset()
     164{
     165    internal->reset();
     166}
     167
     168std::string
     169QueryPostingSource::get_description() const
     170{
     171    return "Xapian::QueryPostingSource(" +
     172            internal->db.get_description() + ", " +
     173            internal->q.get_description() + ")";
     174}
     175
     176}