aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2017-12-17 13:20:31 -0500
committerTucker Evans <tuckerevans24@gmail.com>2017-12-17 13:20:31 -0500
commit6cc5652a8af3361288393718ec2adb2889c9af1e (patch)
tree8842efca416d6702af6a53b6829f439243b47ce1
parentb238b4baff5898dc996f1011c764c6b6c520885c (diff)
CSC2621/assignments/search: Added flags for search phrase and index file;
Fixed multi-word searches... again.
-rw-r--r--search/search.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/search/search.go b/search/search.go
index cb01f0b..c144055 100644
--- a/search/search.go
+++ b/search/search.go
@@ -12,6 +12,8 @@ import "search/index"
import "os"
import "fmt"
import "sort"
+import "flag"
+import "strings"
type res struct {
doc string;
@@ -27,6 +29,19 @@ func main() {
var searchBool, perWord, docAdded map[string]bool; //map[doc]bool
var resultSort []res;
var err error;
+ var fname, s string;
+ var search []string;
+
+ flag.StringVar(&fname, "f", "./index.dat", "Index file");
+ flag.StringVar(&s, "s", "" , "Search phrase");
+
+ flag.Parse();
+ if len(s) == 0 {
+ fmt.Printf("Usage: search -s \"search phrase\" [-f index_file]");
+ os.Exit(1);
+ } else {
+ search = strings.Fields(s);
+ }
scores = make(map[string]map[string]float64);
searchBool = make(map[string]bool);
@@ -38,13 +53,12 @@ func main() {
- init_index, err = index.NewInvertedIndexFromFile("index.dat"); //TODO add flag for filename
+ init_index, err = index.NewInvertedIndexFromFile(fname);
if err != nil {
panic(err)
}
-
- for i = 1; i < len(os.Args); i++ {
- sIndex[os.Args[i]] = init_index[os.Args[i]]
+ for i = 0; i < len(search); i++ {
+ sIndex[search[i]] = init_index[search[i]]
}
for _, v := range sIndex {
@@ -58,9 +72,8 @@ func main() {
for tmp = v; tmp != nil; tmp = tmp.Next {
perWord[tmp.This.Doc] = true;
}
-
for d := range searchBool {
- if _, o := perWord[d]; !o {
+ if !perWord[d] {
searchBool[d] = false;
}
}