|
a/src/python/recoll/pyrecoll.cpp |
|
b/src/python/recoll/pyrecoll.cpp |
|
... |
|
... |
1626 |
// Return a python unicode object
|
1626 |
// Return a python unicode object
|
1627 |
return PyUnicode_Decode(abstract.c_str(), abstract.size(),
|
1627 |
return PyUnicode_Decode(abstract.c_str(), abstract.size(),
|
1628 |
"UTF-8", "replace");
|
1628 |
"UTF-8", "replace");
|
1629 |
}
|
1629 |
}
|
1630 |
|
1630 |
|
|
|
1631 |
PyDoc_STRVAR(doc_Db_termMatch,
|
|
|
1632 |
"termMatch(match_type='wildcard|regexp|stem', expr, field='', "
|
|
|
1633 |
"maxlen=-1, casesens=False, diacsens=False, lang='english')"
|
|
|
1634 |
" returns the expanded term list\n"
|
|
|
1635 |
"\n"
|
|
|
1636 |
"Expands the input expression according to the mode and parameters and "
|
|
|
1637 |
"returns the expanded term list.\n"
|
|
|
1638 |
);
|
|
|
1639 |
static PyObject *
|
|
|
1640 |
Db_termMatch(recoll_DbObject* self, PyObject *args, PyObject *kwargs)
|
|
|
1641 |
{
|
|
|
1642 |
LOGDEB(("Db_termMatch\n"));
|
|
|
1643 |
static const char *kwlist[] = {"type", "expr", "field", "maxlen",
|
|
|
1644 |
"casesens", "diacsens", "lang", NULL};
|
|
|
1645 |
char *tp = 0;
|
|
|
1646 |
char *expr = 0; // needs freeing
|
|
|
1647 |
char *field = 0; // needs freeing
|
|
|
1648 |
int maxlen = -1;
|
|
|
1649 |
PyObject *casesens = 0;
|
|
|
1650 |
PyObject *diacsens = 0;
|
|
|
1651 |
char *lang = 0; // needs freeing
|
|
|
1652 |
|
|
|
1653 |
PyObject *ret = 0;
|
|
|
1654 |
int typ_sens = 0;
|
|
|
1655 |
Rcl::TermMatchResult result;
|
|
|
1656 |
|
|
|
1657 |
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ses|esiOOes",
|
|
|
1658 |
(char**)kwlist,
|
|
|
1659 |
&tp, "utf-8", &expr, "utf-8", &field,
|
|
|
1660 |
&maxlen, &casesens,
|
|
|
1661 |
&diacsens, "utf-8", &lang))
|
|
|
1662 |
return 0;
|
|
|
1663 |
|
|
|
1664 |
if (self->db == 0 || the_dbs.find(self->db) == the_dbs.end()) {
|
|
|
1665 |
LOGERR(("Db_termMatch: db not found %p\n", self->db));
|
|
|
1666 |
PyErr_SetString(PyExc_AttributeError, "db");
|
|
|
1667 |
goto out;
|
|
|
1668 |
}
|
|
|
1669 |
|
|
|
1670 |
if (!strcasecmp(tp, "wildcard")) {
|
|
|
1671 |
typ_sens = Rcl::Db::ET_WILD;
|
|
|
1672 |
} else if (!strcasecmp(tp, "regexp")) {
|
|
|
1673 |
typ_sens = Rcl::Db::ET_REGEXP;
|
|
|
1674 |
} else if (!strcasecmp(tp, "stem")) {
|
|
|
1675 |
typ_sens = Rcl::Db::ET_STEM;
|
|
|
1676 |
} else {
|
|
|
1677 |
PyErr_SetString(PyExc_AttributeError, "Bad type arg");
|
|
|
1678 |
goto out;
|
|
|
1679 |
}
|
|
|
1680 |
|
|
|
1681 |
if (casesens != 0 && PyObject_IsTrue(casesens)) {
|
|
|
1682 |
typ_sens |= Rcl::Db::ET_CASESENS;
|
|
|
1683 |
}
|
|
|
1684 |
if (diacsens != 0 && PyObject_IsTrue(diacsens)) {
|
|
|
1685 |
typ_sens |= Rcl::Db::ET_DIACSENS;
|
|
|
1686 |
}
|
|
|
1687 |
|
|
|
1688 |
if (!self->db->termMatch(typ_sens, lang ? lang : "english",
|
|
|
1689 |
expr, result, maxlen, field ? field : "")) {
|
|
|
1690 |
LOGERR(("Db_termMatch: db termMatch error\n"));
|
|
|
1691 |
PyErr_SetString(PyExc_AttributeError, "rcldb termMatch error");
|
|
|
1692 |
goto out;
|
|
|
1693 |
}
|
|
|
1694 |
ret = PyList_New(result.entries.size());
|
|
|
1695 |
for (unsigned int i = 0; i < result.entries.size(); i++) {
|
|
|
1696 |
PyList_SetItem(ret, i,
|
|
|
1697 |
PyUnicode_FromString(
|
|
|
1698 |
Rcl::strip_prefix(result.entries[i].term).c_str()));
|
|
|
1699 |
}
|
|
|
1700 |
|
|
|
1701 |
out:
|
|
|
1702 |
PyMem_Free(expr);
|
|
|
1703 |
PyMem_Free(field);
|
|
|
1704 |
PyMem_Free(lang);
|
|
|
1705 |
return ret;
|
|
|
1706 |
}
|
|
|
1707 |
|
1631 |
static PyObject *
|
1708 |
static PyObject *
|
1632 |
Db_needUpdate(recoll_DbObject* self, PyObject *args, PyObject *kwds)
|
1709 |
Db_needUpdate(recoll_DbObject* self, PyObject *args, PyObject *kwds)
|
1633 |
{
|
1710 |
{
|
1634 |
char *udi = 0; // needs freeing
|
1711 |
char *udi = 0; // needs freeing
|
1635 |
char *sig = 0; // needs freeing
|
1712 |
char *sig = 0; // needs freeing
|
|
... |
|
... |
1735 |
},
|
1812 |
},
|
1736 |
{"makeDocAbstract", (PyCFunction)Db_makeDocAbstract, METH_VARARGS,
|
1813 |
{"makeDocAbstract", (PyCFunction)Db_makeDocAbstract, METH_VARARGS,
|
1737 |
"makeDocAbstract(Doc, Query) -> string\n"
|
1814 |
"makeDocAbstract(Doc, Query) -> string\n"
|
1738 |
"Build and return 'keyword-in-context' abstract for document\n"
|
1815 |
"Build and return 'keyword-in-context' abstract for document\n"
|
1739 |
"and query."
|
1816 |
"and query."
|
|
|
1817 |
},
|
|
|
1818 |
{"termMatch", (PyCFunction)Db_termMatch, METH_VARARGS|METH_KEYWORDS,
|
|
|
1819 |
doc_Db_termMatch
|
1740 |
},
|
1820 |
},
|
1741 |
{"needUpdate", (PyCFunction)Db_needUpdate, METH_VARARGS,
|
1821 |
{"needUpdate", (PyCFunction)Db_needUpdate, METH_VARARGS,
|
1742 |
"needUpdate(udi, sig) -> Bool.\n"
|
1822 |
"needUpdate(udi, sig) -> Bool.\n"
|
1743 |
"Check if the index is up to date for the document defined by udi,\n"
|
1823 |
"Check if the index is up to date for the document defined by udi,\n"
|
1744 |
"having the current signature sig."
|
1824 |
"having the current signature sig."
|