0

我在 sqlite 中有一个虚拟表,我正在对它运行查询以查找关键字匹配,但计数始终为 1。结构如下。

var insertStatement2 = "INSERT INTO pagesfts3 (url,content) VALUES (?, ?)";
var createStatement2 = "CREATE VIRTUAL TABLE pagesfts3 USING fts3 (url VARCHAR,content TEXT)";
var selectStatement2 = "SELECT COUNT(*),url FROM pagesfts3 WHERE content MATCH ? GROUP BY url";


                try {
                      var db = openDatabase("search", "1.0", "search engine", 200000);
                      db.transaction(function(tx) {
                            //for example use drop table on each load
                            tx.executeSql(dropStatement, [], null, onError);
                            tx.executeSql(dropStatement2, [], null, onError);


                            tx.executeSql(createStatement, [], null, onError);
                            tx.executeSql(createStatement2, [], null, onError);

                      });

                      db.transaction(function(tx) {

                      });
                }
                catch (error) {
                      $('body').prepend('<div class="alert alert-danger">This script requires a SQlite compatible browser<br/> try Safari 4, iOS OS3, Chrome 5, or Opera 10.5</div>');
                }
                function onError(tx, error) {
                      alert(error.message);
                }

所以基本上我保存了一个网页数据及其相应的 url。当我去查询页面时,我运行这个

 var query = $('#query').val().toLowerCase();
                          var searchResults = $('#queryResult');
                          searchResults.html('');
                          db.transaction(function(tx) {
                                //run static select statment 2 on the virtual table
                                tx.executeSql(selectStatement2, [query], function(tx, result) {

                                      var dataset = result.rows;
                                      if (dataset.length > 0) {
                                            for (var i = 0, item = null; i < dataset.length; i++) {

                                                  item = dataset.item(i);
                                                  console.debug(item);
                                                  var url = item['url'];
                                                  var count = item['COUNT(*)'];

                                                  var str = '<p><a href="' + url + '">' + url + '</a> has the word <b>' + query + '</b></p>';

                                                  searchResults.append(str);

                                            }
                                      }else{
                                       searchResults.append('no results');
                                      }
                                });
                          });

但是列计数(*)始终为 1,即使我知道它们的关键字出现超过 1 次。我对虚拟表不太熟悉,所以也许我遗漏了一些东西。

4

0 回答 0