虚拟表上的SQlite计数查询总是为1

时间:2013-02-02 02:24:56

标签: javascript sqlite fts3

我在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);
                }

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

 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次。我不太熟悉虚拟表,所以也许我错过了什么。

0 个答案:

没有答案