Fossil

Check-in [13dfcdd957]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Search improvements: Limit the number of search results to the value in the "search-limit" setting, or 100 results if the setting is omitted. And, show the date of each article if the date is not included as part of the title.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 13dfcdd9576baa4656797db889401ae4ab8457fcc67750f99678c4d577fcc1bc
User & Date: drh 2020-06-16 20:46:30.358
Context
2020-06-17
14:38
Include first-generation simple cherrypicks in ancestor graphs on the timeline. check-in: 5a23a724ae user: drh tags: trunk
2020-06-16
20:46
Search improvements: Limit the number of search results to the value in the "search-limit" setting, or 100 results if the setting is omitted. And, show the date of each article if the date is not included as part of the title. check-in: 13dfcdd957 user: drh tags: trunk
14:40
Add a link to /fileedit from /sitemap, so that it appears in the hamburger menu when it is enabled. check-in: cc17add265 user: drh tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/search.c.
1029
1030
1031
1032
1033
1034
1035

1036



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1064
1065






1066
1067
1068
1069
1070
1071
1072
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082







+

+
+
+













-
+






+








-
+
+
+
+
+
+







int search_run_and_output(
  const char *zPattern,       /* The query pattern */
  unsigned int srchFlags,     /* What to search over */
  int fDebug                  /* Extra debugging output */
){
  Stmt q;
  int nRow = 0;
  int nLimit = db_get_int("search-limit", 100);

  if( P("searchlimit")!=0 ){
    nLimit = atoi(P("searchlimit"));
  }
  srchFlags = search_restrict(srchFlags);
  if( srchFlags==0 ) return 0;
  search_sql_setup(g.db);
  add_content_sql_commands(g.db);
  db_multi_exec(
    "CREATE TEMP TABLE x(label,url,score,id,date,snip);"
  );
  if( !search_index_exists() ){
    search_fullscan(zPattern, srchFlags);  /* Full-scan search */
  }else{
    search_update_index(srchFlags);        /* Update the index, if necessary */
    search_indexed(zPattern, srchFlags);   /* Indexed search */
  }
  db_prepare(&q, "SELECT url, snip, label, score, id"
  db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)"
                 "  FROM x"
                 " ORDER BY score DESC, date DESC;");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zUrl = db_column_text(&q, 0);
    const char *zSnippet = db_column_text(&q, 1);
    const char *zLabel = db_column_text(&q, 2);
    const char *zDate = db_column_text(&q, 5);
    if( nRow==0 ){
      @ <ol>
    }
    nRow++;
    @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a>
    if( fDebug ){
      @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4))
    }
    @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li>
    @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet)) \
    if( zDate && zDate[0] && strstr(zLabel,zDate)==0 ){
      @ <small>(%h(zDate))</small>
    }
    @ </span></li>
    if( nLimit && nRow>=nLimit ) break;
  }
  db_finalize(&q);
  if( nRow ){
    @ </ol>
  }
  return nRow;
}