recache.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Before you execute the program, Launch `cqlsh` and execute:
  3. create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
  4. create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
  5. create index on example.tweet(timeline);
  6. */
  7. package main
  8. import (
  9. // "time"
  10. "flag"
  11. "fmt"
  12. // "strconv"
  13. "strings"
  14. "git.wecise.com/wecise/odbserver/odb/cqlfilter"
  15. "git.wecise.com/wecise/odbserver/odb/stmt"
  16. "git.wecise.com/wecise/odbserver/odb/test"
  17. "gitee.com/wecisecode/util/logger"
  18. )
  19. func main() {
  20. // connect to the cluster
  21. //cluster := gocql.NewCluster("192.168.40.14")
  22. keyspace := flag.String("keyspace", "matrix", "keyspace")
  23. flag.Parse()
  24. option := &Option{Cache: CacheAll, Keyspace: *keyspace, DisableInitialHostLookup: true}
  25. g, err := test.NewG(option)
  26. if err != nil {
  27. logger.Error(err.Error())
  28. } else {
  29. defer g.Close()
  30. }
  31. //logger.SetRollingDaily("C:/test/zkcron/src/test", "test.log")
  32. logger.SetConsole(true)
  33. for cls := range g.MICache.ToMap() {
  34. for _, relation := range g.Relations_col_as_field(nil) {
  35. fs := strings.Split(relation, " as ")
  36. column := fs[0] + "$_all"
  37. field := column
  38. if len(fs) == 2 {
  39. field = fs[1]
  40. }
  41. cql := fmt.Sprintf(`select class, %s from object where class='%s' and expr(object_lucene, ?) limit 1`, relation, cls)
  42. stru := &stmt.FilterStruct{Type: "range", Field: column}
  43. lucene, _ := cqlfilter.ToLucene(stru, false)
  44. if rows, err := g.RawQuery(cql, lucene); err != nil {
  45. logger.Errorf(" error: %v", err)
  46. } else {
  47. if len(rows) > 0 {
  48. value := rows[0][field].(map[string][]string)
  49. g.RefreshRelationsStats1(rows[0]["class"].(string), field, value)
  50. //logger.Error(rows[0]["class"], value["_all"])
  51. }
  52. }
  53. }
  54. }
  55. }