Fossil SCM

Many improvements to the indexed search debugging logic.

drh 2020-04-04 19:34 trunk
Commit 53d1f053ad9271639bfc998ead403fcc55aa877f54171825a4725d0baca1c421
2 files changed +68 -15 +1
+68 -15
--- src/search.c
+++ src/search.c
@@ -1852,18 +1852,25 @@
18521852
**
18531853
** The current search settings are displayed after any changes are applied.
18541854
** Run this command with no arguments to simply see the settings.
18551855
*/
18561856
void fts_config_cmd(void){
1857
- static const struct { int iCmd; const char *z; } aCmd[] = {
1857
+ static const struct {
1858
+ int iCmd;
1859
+ const char *z;
1860
+ } aCmd[] = {
18581861
{ 1, "reindex" },
18591862
{ 2, "index" },
18601863
{ 3, "disable" },
18611864
{ 4, "enable" },
18621865
{ 5, "stemmer" },
18631866
};
1864
- static const struct { const char *zSetting; const char *zName; const char *zSw; } aSetng[] = {
1867
+ static const struct {
1868
+ const char *zSetting;
1869
+ const char *zName;
1870
+ const char *zSw;
1871
+ } aSetng[] = {
18651872
{ "search-ci", "check-in search:", "c" },
18661873
{ "search-doc", "document search:", "d" },
18671874
{ "search-tkt", "ticket search:", "t" },
18681875
{ "search-wiki", "wiki search:", "w" },
18691876
{ "search-technote", "tech note search:", "e" },
@@ -1953,48 +1960,77 @@
19531960
Stmt q;
19541961
const char *zId = P("id");
19551962
const char *zType = P("y");
19561963
const char *zIdxed = P("ixed");
19571964
int id;
1958
- int cnt = 0;
1965
+ int cnt1 = 0, cnt2 = 0, cnt3 = 0;
19591966
login_check_credentials();
19601967
if( !g.perm.Admin ){ login_needed(0); return; }
19611968
if( !search_index_exists() ){
19621969
@ <p>Indexed search is disabled
19631970
style_footer();
19641971
return;
19651972
}
1973
+ search_sql_setup(g.db);
1974
+ style_submenu_element("Setup","%R/srchsetup");
19661975
if( zId!=0 && (id = atoi(zId))>0 ){
19671976
/* Show information about a single ftsdocs entry */
19681977
style_header("Information about ftsdoc entry %d", id);
1978
+ style_submenu_element("Summary","%R/test-ftsdocs");
19691979
db_prepare(&q,
19701980
"SELECT type||rid, name, idxed, label, url, datetime(mtime)"
19711981
" FROM ftsdocs WHERE rowid=%d", id
19721982
);
19731983
if( db_step(&q)==SQLITE_ROW ){
19741984
const char *zUrl = db_column_text(&q,4);
1985
+ const char *zDocId = db_column_text(&q,0);
1986
+ char *zName;
1987
+ char *z;
19751988
@ <table border=0>
1976
- @ <tr><td align='right'>rowid:<td>&nbsp;&nbsp;<td>%d(id)
1977
- @ <tr><td align='right'>id:<td><td>%s(db_column_text(&q,0))
1989
+ @ <tr><td align='right'>docid:<td>&nbsp;&nbsp;<td>%d(id)
1990
+ @ <tr><td align='right'>id:<td><td>%s(zDocId)
19781991
@ <tr><td align='right'>name:<td><td>%h(db_column_text(&q,1))
19791992
@ <tr><td align='right'>idxed:<td><td>%d(db_column_int(&q,2))
19801993
@ <tr><td align='right'>label:<td><td>%h(db_column_text(&q,3))
19811994
@ <tr><td align='right'>url:<td><td>
19821995
@ <a href='%R%s(zUrl)'>%h(zUrl)</a>
19831996
@ <tr><td align='right'>mtime:<td><td>%s(db_column_text(&q,5))
1997
+ z = db_text(0, "SELECT title FROM ftsidx WHERE docid=%d",id);
1998
+ if( z && z[0] ){
1999
+ @ <tr><td align="right">title:<td><td>%h(z)
2000
+ fossil_free(z);
2001
+ }
2002
+ z = db_text(0, "SELECT body FROM ftsidx WHERE docid=%d",id);
2003
+ if( z && z[0] ){
2004
+ @ <tr><td align="right" valign="top">body:<td><td>%h(z)
2005
+ fossil_free(z);
2006
+ }
19842007
@ </table>
2008
+ zName = mprintf("Indexed '%c' docs",zDocId[0]);
2009
+ style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=1",zDocId[0]);
2010
+ zName = mprintf("Unindexed '%c' docs",zDocId[0]);
2011
+ style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=0",zDocId[0]);
19852012
}
19862013
db_finalize(&q);
19872014
style_footer();
19882015
return;
19892016
}
19902017
if( zType!=0 && zType[0]!=0 && zType[1]==0 &&
19912018
zIdxed!=0 && (zIdxed[0]=='1' || zIdxed[0]=='0') && zIdxed[1]==0
19922019
){
19932020
int ixed = zIdxed[0]=='1';
2021
+ char *zName;
19942022
style_header("List of '%c' documents that are%s indexed",
19952023
zType[0], ixed ? "" : " not");
2024
+ style_submenu_element("Summary","%R/test-ftsdocs");
2025
+ if( ixed==0 ){
2026
+ zName = mprintf("Indexed '%c' docs",zType[0]);
2027
+ style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=1",zType[0]);
2028
+ }else{
2029
+ zName = mprintf("Unindexed '%c' docs",zType[0]);
2030
+ style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=0",zType[0]);
2031
+ }
19962032
db_prepare(&q,
19972033
"SELECT rowid, type||rid ||' '|| coalesce(label,'')"
19982034
" FROM ftsdocs WHERE type='%c' AND %s idxed",
19992035
zType[0], ixed ? "" : "NOT"
20002036
);
@@ -2008,29 +2044,46 @@
20082044
style_footer();
20092045
return;
20102046
}
20112047
style_header("Summary of ftsdocs");
20122048
db_prepare(&q,
2013
- "SELECT type, idxed, count(*) FROM ftsdocs"
2014
- " GROUP BY 1, 2 ORDER BY 3 DESC"
2049
+ "SELECT type, sum(idxed IS TRUE), sum(idxed IS FALSE), count(*)"
2050
+ " FROM ftsdocs"
2051
+ " GROUP BY 1 ORDER BY 4 DESC"
20152052
);
20162053
@ <table border=1 cellpadding=3 cellspacing=0>
20172054
@ <thead>
2018
- @ <tr><th>Type<th>Indexed?<th>Count<th>Link
2055
+ @ <tr><th>Type<th>Indexed<th>Unindexed<th>Total
20192056
@ </thead>
20202057
@ <tbody>
20212058
while( db_step(&q)==SQLITE_ROW ){
20222059
const char *zType = db_column_text(&q,0);
2023
- int idxed = db_column_int(&q,1);
2024
- int n = db_column_int(&q,2);
2025
- @ <tr><td>%h(zType)<td>%d(idxed)
2026
- @ <td>%d(n)
2027
- @ <td><a href='test-ftsdocs?y=%s(zType)&ixed=%d(idxed)'>listing</a>
2060
+ int nIndexed = db_column_int(&q, 1);
2061
+ int nUnindexed = db_column_int(&q, 2);
2062
+ int nTotal = db_column_int(&q, 3);
2063
+ @ <tr><td>%h(zType)
2064
+ if( nIndexed>0 ){
2065
+ @ <td align="right"><a href='%R/test-ftsdocs?y=%s(zType)&ixed=1'>\
2066
+ @ %d(nIndexed)</a>
2067
+ }else{
2068
+ @ <td align="right">0
2069
+ }
2070
+ if( nUnindexed>0 ){
2071
+ @ <td align="right"><a href='%R/test-ftsdocs?y=%s(zType)&ixed=0'>\
2072
+ @ %d(nUnindexed)</a>
2073
+ }else{
2074
+ @ <td align="right">0
2075
+ }
2076
+ @ <td align="right">%d(nTotal)
20282077
@ </tr>
2029
- cnt += n;
2078
+ cnt1 += nIndexed;
2079
+ cnt2 += nUnindexed;
2080
+ cnt3 += nTotal;
20302081
}
2082
+ db_finalize(&q);
20312083
@ </tbody><tfooter>
2032
- @ <tr><th>Total<th><th>%d(cnt)<th>
2084
+ @ <tr><th>Total<th align="right">%d(cnt1)<th align="right">%d(cnt2)
2085
+ @ <th align="right">%d(cnt3)
20332086
@ </tfooter>
20342087
@ </table>
20352088
style_footer();
20362089
}
20372090
--- src/search.c
+++ src/search.c
@@ -1852,18 +1852,25 @@
1852 **
1853 ** The current search settings are displayed after any changes are applied.
1854 ** Run this command with no arguments to simply see the settings.
1855 */
1856 void fts_config_cmd(void){
1857 static const struct { int iCmd; const char *z; } aCmd[] = {
 
 
 
1858 { 1, "reindex" },
1859 { 2, "index" },
1860 { 3, "disable" },
1861 { 4, "enable" },
1862 { 5, "stemmer" },
1863 };
1864 static const struct { const char *zSetting; const char *zName; const char *zSw; } aSetng[] = {
 
 
 
 
1865 { "search-ci", "check-in search:", "c" },
1866 { "search-doc", "document search:", "d" },
1867 { "search-tkt", "ticket search:", "t" },
1868 { "search-wiki", "wiki search:", "w" },
1869 { "search-technote", "tech note search:", "e" },
@@ -1953,48 +1960,77 @@
1953 Stmt q;
1954 const char *zId = P("id");
1955 const char *zType = P("y");
1956 const char *zIdxed = P("ixed");
1957 int id;
1958 int cnt = 0;
1959 login_check_credentials();
1960 if( !g.perm.Admin ){ login_needed(0); return; }
1961 if( !search_index_exists() ){
1962 @ <p>Indexed search is disabled
1963 style_footer();
1964 return;
1965 }
 
 
1966 if( zId!=0 && (id = atoi(zId))>0 ){
1967 /* Show information about a single ftsdocs entry */
1968 style_header("Information about ftsdoc entry %d", id);
 
1969 db_prepare(&q,
1970 "SELECT type||rid, name, idxed, label, url, datetime(mtime)"
1971 " FROM ftsdocs WHERE rowid=%d", id
1972 );
1973 if( db_step(&q)==SQLITE_ROW ){
1974 const char *zUrl = db_column_text(&q,4);
 
 
 
1975 @ <table border=0>
1976 @ <tr><td align='right'>rowid:<td>&nbsp;&nbsp;<td>%d(id)
1977 @ <tr><td align='right'>id:<td><td>%s(db_column_text(&q,0))
1978 @ <tr><td align='right'>name:<td><td>%h(db_column_text(&q,1))
1979 @ <tr><td align='right'>idxed:<td><td>%d(db_column_int(&q,2))
1980 @ <tr><td align='right'>label:<td><td>%h(db_column_text(&q,3))
1981 @ <tr><td align='right'>url:<td><td>
1982 @ <a href='%R%s(zUrl)'>%h(zUrl)</a>
1983 @ <tr><td align='right'>mtime:<td><td>%s(db_column_text(&q,5))
 
 
 
 
 
 
 
 
 
 
1984 @ </table>
 
 
 
 
1985 }
1986 db_finalize(&q);
1987 style_footer();
1988 return;
1989 }
1990 if( zType!=0 && zType[0]!=0 && zType[1]==0 &&
1991 zIdxed!=0 && (zIdxed[0]=='1' || zIdxed[0]=='0') && zIdxed[1]==0
1992 ){
1993 int ixed = zIdxed[0]=='1';
 
1994 style_header("List of '%c' documents that are%s indexed",
1995 zType[0], ixed ? "" : " not");
 
 
 
 
 
 
 
 
1996 db_prepare(&q,
1997 "SELECT rowid, type||rid ||' '|| coalesce(label,'')"
1998 " FROM ftsdocs WHERE type='%c' AND %s idxed",
1999 zType[0], ixed ? "" : "NOT"
2000 );
@@ -2008,29 +2044,46 @@
2008 style_footer();
2009 return;
2010 }
2011 style_header("Summary of ftsdocs");
2012 db_prepare(&q,
2013 "SELECT type, idxed, count(*) FROM ftsdocs"
2014 " GROUP BY 1, 2 ORDER BY 3 DESC"
 
2015 );
2016 @ <table border=1 cellpadding=3 cellspacing=0>
2017 @ <thead>
2018 @ <tr><th>Type<th>Indexed?<th>Count<th>Link
2019 @ </thead>
2020 @ <tbody>
2021 while( db_step(&q)==SQLITE_ROW ){
2022 const char *zType = db_column_text(&q,0);
2023 int idxed = db_column_int(&q,1);
2024 int n = db_column_int(&q,2);
2025 @ <tr><td>%h(zType)<td>%d(idxed)
2026 @ <td>%d(n)
2027 @ <td><a href='test-ftsdocs?y=%s(zType)&ixed=%d(idxed)'>listing</a>
 
 
 
 
 
 
 
 
 
 
 
 
2028 @ </tr>
2029 cnt += n;
 
 
2030 }
 
2031 @ </tbody><tfooter>
2032 @ <tr><th>Total<th><th>%d(cnt)<th>
 
2033 @ </tfooter>
2034 @ </table>
2035 style_footer();
2036 }
2037
--- src/search.c
+++ src/search.c
@@ -1852,18 +1852,25 @@
1852 **
1853 ** The current search settings are displayed after any changes are applied.
1854 ** Run this command with no arguments to simply see the settings.
1855 */
1856 void fts_config_cmd(void){
1857 static const struct {
1858 int iCmd;
1859 const char *z;
1860 } aCmd[] = {
1861 { 1, "reindex" },
1862 { 2, "index" },
1863 { 3, "disable" },
1864 { 4, "enable" },
1865 { 5, "stemmer" },
1866 };
1867 static const struct {
1868 const char *zSetting;
1869 const char *zName;
1870 const char *zSw;
1871 } aSetng[] = {
1872 { "search-ci", "check-in search:", "c" },
1873 { "search-doc", "document search:", "d" },
1874 { "search-tkt", "ticket search:", "t" },
1875 { "search-wiki", "wiki search:", "w" },
1876 { "search-technote", "tech note search:", "e" },
@@ -1953,48 +1960,77 @@
1960 Stmt q;
1961 const char *zId = P("id");
1962 const char *zType = P("y");
1963 const char *zIdxed = P("ixed");
1964 int id;
1965 int cnt1 = 0, cnt2 = 0, cnt3 = 0;
1966 login_check_credentials();
1967 if( !g.perm.Admin ){ login_needed(0); return; }
1968 if( !search_index_exists() ){
1969 @ <p>Indexed search is disabled
1970 style_footer();
1971 return;
1972 }
1973 search_sql_setup(g.db);
1974 style_submenu_element("Setup","%R/srchsetup");
1975 if( zId!=0 && (id = atoi(zId))>0 ){
1976 /* Show information about a single ftsdocs entry */
1977 style_header("Information about ftsdoc entry %d", id);
1978 style_submenu_element("Summary","%R/test-ftsdocs");
1979 db_prepare(&q,
1980 "SELECT type||rid, name, idxed, label, url, datetime(mtime)"
1981 " FROM ftsdocs WHERE rowid=%d", id
1982 );
1983 if( db_step(&q)==SQLITE_ROW ){
1984 const char *zUrl = db_column_text(&q,4);
1985 const char *zDocId = db_column_text(&q,0);
1986 char *zName;
1987 char *z;
1988 @ <table border=0>
1989 @ <tr><td align='right'>docid:<td>&nbsp;&nbsp;<td>%d(id)
1990 @ <tr><td align='right'>id:<td><td>%s(zDocId)
1991 @ <tr><td align='right'>name:<td><td>%h(db_column_text(&q,1))
1992 @ <tr><td align='right'>idxed:<td><td>%d(db_column_int(&q,2))
1993 @ <tr><td align='right'>label:<td><td>%h(db_column_text(&q,3))
1994 @ <tr><td align='right'>url:<td><td>
1995 @ <a href='%R%s(zUrl)'>%h(zUrl)</a>
1996 @ <tr><td align='right'>mtime:<td><td>%s(db_column_text(&q,5))
1997 z = db_text(0, "SELECT title FROM ftsidx WHERE docid=%d",id);
1998 if( z && z[0] ){
1999 @ <tr><td align="right">title:<td><td>%h(z)
2000 fossil_free(z);
2001 }
2002 z = db_text(0, "SELECT body FROM ftsidx WHERE docid=%d",id);
2003 if( z && z[0] ){
2004 @ <tr><td align="right" valign="top">body:<td><td>%h(z)
2005 fossil_free(z);
2006 }
2007 @ </table>
2008 zName = mprintf("Indexed '%c' docs",zDocId[0]);
2009 style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=1",zDocId[0]);
2010 zName = mprintf("Unindexed '%c' docs",zDocId[0]);
2011 style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=0",zDocId[0]);
2012 }
2013 db_finalize(&q);
2014 style_footer();
2015 return;
2016 }
2017 if( zType!=0 && zType[0]!=0 && zType[1]==0 &&
2018 zIdxed!=0 && (zIdxed[0]=='1' || zIdxed[0]=='0') && zIdxed[1]==0
2019 ){
2020 int ixed = zIdxed[0]=='1';
2021 char *zName;
2022 style_header("List of '%c' documents that are%s indexed",
2023 zType[0], ixed ? "" : " not");
2024 style_submenu_element("Summary","%R/test-ftsdocs");
2025 if( ixed==0 ){
2026 zName = mprintf("Indexed '%c' docs",zType[0]);
2027 style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=1",zType[0]);
2028 }else{
2029 zName = mprintf("Unindexed '%c' docs",zType[0]);
2030 style_submenu_element(zName,"%R/test-ftsdocs?y=%c&ixed=0",zType[0]);
2031 }
2032 db_prepare(&q,
2033 "SELECT rowid, type||rid ||' '|| coalesce(label,'')"
2034 " FROM ftsdocs WHERE type='%c' AND %s idxed",
2035 zType[0], ixed ? "" : "NOT"
2036 );
@@ -2008,29 +2044,46 @@
2044 style_footer();
2045 return;
2046 }
2047 style_header("Summary of ftsdocs");
2048 db_prepare(&q,
2049 "SELECT type, sum(idxed IS TRUE), sum(idxed IS FALSE), count(*)"
2050 " FROM ftsdocs"
2051 " GROUP BY 1 ORDER BY 4 DESC"
2052 );
2053 @ <table border=1 cellpadding=3 cellspacing=0>
2054 @ <thead>
2055 @ <tr><th>Type<th>Indexed<th>Unindexed<th>Total
2056 @ </thead>
2057 @ <tbody>
2058 while( db_step(&q)==SQLITE_ROW ){
2059 const char *zType = db_column_text(&q,0);
2060 int nIndexed = db_column_int(&q, 1);
2061 int nUnindexed = db_column_int(&q, 2);
2062 int nTotal = db_column_int(&q, 3);
2063 @ <tr><td>%h(zType)
2064 if( nIndexed>0 ){
2065 @ <td align="right"><a href='%R/test-ftsdocs?y=%s(zType)&ixed=1'>\
2066 @ %d(nIndexed)</a>
2067 }else{
2068 @ <td align="right">0
2069 }
2070 if( nUnindexed>0 ){
2071 @ <td align="right"><a href='%R/test-ftsdocs?y=%s(zType)&ixed=0'>\
2072 @ %d(nUnindexed)</a>
2073 }else{
2074 @ <td align="right">0
2075 }
2076 @ <td align="right">%d(nTotal)
2077 @ </tr>
2078 cnt1 += nIndexed;
2079 cnt2 += nUnindexed;
2080 cnt3 += nTotal;
2081 }
2082 db_finalize(&q);
2083 @ </tbody><tfooter>
2084 @ <tr><th>Total<th align="right">%d(cnt1)<th align="right">%d(cnt2)
2085 @ <th align="right">%d(cnt3)
2086 @ </tfooter>
2087 @ </table>
2088 style_footer();
2089 }
2090
--- src/setup.c
+++ src/setup.c
@@ -1640,10 +1640,11 @@
16401640
@ <p>Currently using an SQLite FTS4 search index. This makes search
16411641
@ run faster, especially on large repositories, but takes up space.</p>
16421642
onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
16431643
@ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
16441644
@ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
1645
+ style_submenu_element("FTS Index Debugging","%R/test-ftsdocs");
16451646
}else{
16461647
@ <p>The SQLite FTS4 search index is disabled. All searching will be
16471648
@ a full-text scan. This usually works fine, but can be slow for
16481649
@ larger repositories.</p>
16491650
onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
16501651
--- src/setup.c
+++ src/setup.c
@@ -1640,10 +1640,11 @@
1640 @ <p>Currently using an SQLite FTS4 search index. This makes search
1641 @ run faster, especially on large repositories, but takes up space.</p>
1642 onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
1643 @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
1644 @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
 
1645 }else{
1646 @ <p>The SQLite FTS4 search index is disabled. All searching will be
1647 @ a full-text scan. This usually works fine, but can be slow for
1648 @ larger repositories.</p>
1649 onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
1650
--- src/setup.c
+++ src/setup.c
@@ -1640,10 +1640,11 @@
1640 @ <p>Currently using an SQLite FTS4 search index. This makes search
1641 @ run faster, especially on large repositories, but takes up space.</p>
1642 onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
1643 @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
1644 @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
1645 style_submenu_element("FTS Index Debugging","%R/test-ftsdocs");
1646 }else{
1647 @ <p>The SQLite FTS4 search index is disabled. All searching will be
1648 @ a full-text scan. This usually works fine, but can be slow for
1649 @ larger repositories.</p>
1650 onoff_attribute("Use Porter Stemmer","search-stemmer","ss",0,0);
1651

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button