+ $sth->finish;
+
+
+# my @w = split /[.,;:\s"'\$\%!£^&\*\(\)\[\]\{\}\#\<\>+=]+/, $self->{para};
+ my @w = split m|[\b\s]+|, $self->{para};
+# print join(' ', @w), "\n";
+ $sth = $dbh->prepare("insert into refer values(?,?,?,?)");
+
+ my $i = 0;
+ for (@w) {
+
+ # starts with a capital letter that isn't Q
+ if (/^[A-PR-Z]/ || m|\d+[A-Z][-/A-Z0-9]*$|) {
+ # not all digits
+ next if /^\d+$/;
+
+ # isn't a stop word
+ my $w = uc;
+ $w =~ s/\W+$//;
+ unless ($stop{$w}) {
+ # add it into the word list
+ $sth->execute($w, $lastrow, $self->{date}, $i);
+# print " $w";
+ }
+ }
+ $i++;
+ }
+ $sth->finish;
+}
+
+sub query
+{
+ my $self = shift;
+ my %args = @_;
+ my @out;
+
+ if ($args{'q'}) {
+ my @w = map { s|[^-/\w]||g; uc $_ } split /\s+/, $args{'q'};
+ if (@w) {
+ my $s = qq{select distinct p, t, bullid from (select distinct rowid from refer where };
+ while (@w) {
+ my $w = shift @w;
+ $s .= qq{r like '$w\%'};
+ $s .= ' or ' if @w;
+ }
+ my $l = $args{l};
+ $l =~ s/[^\d]//g;
+ $l ||= $limit;
+ $s .= qq{ order by t desc limit $l), paragraph where paragraph.ROWID=rowid};
+ my $sth = $dbh->prepare($s) or $error = $DBI::errstr, return @out;
+ $sth->execute;
+ while (my @row = $sth->fetchrow_array) {
+ push @out, \@row;
+ }
+ $sth->finish;
+ }
+ }
+ return @out;