incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [7/9] git commit: Added the print off of the score from the search.
Date Tue, 19 Feb 2013 01:59:11 GMT
Added the print off of the score from the search.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/7dded844
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/7dded844
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/7dded844

Branch: refs/heads/0.2-dev
Commit: 7dded844976aa7cf4ebcad4bee86f0a75d35d664
Parents: 7a982c4
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Feb 18 20:53:58 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Feb 18 20:53:58 2013 -0500

----------------------------------------------------------------------
 .../java/org/apache/blur/shell/SearchCommand.java  |   20 +++++++++++++-
 1 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7dded844/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
index 03ff0b8..60a851a 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
@@ -29,6 +29,7 @@ import jline.console.ConsoleReader;
 
 import org.apache.blur.thrift.BlurClient;
 import org.apache.blur.thrift.BlurThriftUtil;
+import org.apache.blur.thrift.DoubleField;
 import org.apache.blur.thrift.LongField;
 import org.apache.blur.thrift.StringField;
 import org.apache.blur.thrift.TextField;
@@ -39,6 +40,7 @@ import org.apache.blur.thrift.generated.Field;
 import org.apache.blur.thrift.generated.Query;
 import org.apache.blur.thrift.generated.QueryArgs;
 import org.apache.blur.thrift.generated.QueryType;
+import org.apache.blur.thrift.generated.ScoreDoc;
 import org.apache.blur.thrift.generated.Session;
 import org.apache.blur.thrift.generated.TYPE;
 import org.apache.blur.thrift.generated.TopFieldDocs;
@@ -53,6 +55,7 @@ import org.apache.thrift.TException;
 public class SearchCommand extends TableSingleArgumentCommand {
 
   private static final String DOCLOC = "docloc";
+  private static final String SCORE = "score";
   private static final String HELP = "help";
   private static final String BOOST = "boost";
   private static final String FIELD = "field";
@@ -85,6 +88,7 @@ public class SearchCommand extends TableSingleArgumentCommand {
     options.addOption("t", TYPE_STR, false, "Show field type.");
     options.addOption("b", BOOST, false, "Show field boost.");
     options.addOption("l", DOCLOC, false, "Show document locations.");
+    options.addOption("s", SCORE, false, "Show document scores.");
 
     CommandLineParser parser = new PosixParser();
     CommandLine line = parser.parse(options, args);
@@ -104,6 +108,7 @@ public class SearchCommand extends TableSingleArgumentCommand {
     boolean showBoost = line.hasOption(BOOST);
     boolean showType = line.hasOption(TYPE_STR);
     boolean showDocLocations = line.hasOption(DOCLOC);
+    boolean showScores = line.hasOption(SCORE);
     String[] fieldNames = line.getOptionValues(FIELD);
 
     Iface client = getClient();
@@ -139,7 +144,7 @@ public class SearchCommand extends TableSingleArgumentCommand {
     }
     long totalHits = topFieldDocs.getTotalHits();
     out.println("Totalhits " + totalHits);
-    print(docs, docLocations, showDocLocations, showBoost, showType, out, maxLineWidth);
+    print(docs, docLocations, showDocLocations, showScores, topFieldDocs.getScoreDocs(),
showBoost, showType, out, maxLineWidth);
     client.closeReadSession(session);
   }
 
@@ -153,7 +158,7 @@ public class SearchCommand extends TableSingleArgumentCommand {
     return "search";
   }
 
-  private void print(List<Document> docs, List<Long> docLocations, boolean showDocLocations,
boolean showBoost, boolean showType, PrintWriter out, int maxLineWidth) {
+  private void print(List<Document> docs, List<Long> docLocations, boolean showDocLocations,
boolean showScores, List<ScoreDoc> scoreDocs, boolean showBoost, boolean showType, PrintWriter
out, int maxLineWidth) {
     List<String> fieldNames = new ArrayList<String>();
     List<String> fieldTypes = new ArrayList<String>();
     for (int d = 0; d < docs.size(); d++) {
@@ -166,6 +171,14 @@ public class SearchCommand extends TableSingleArgumentCommand {
         fields = newFields;
         document.setFields(fields);
       }
+      if (showScores) {
+        List<Field> newFields = new ArrayList<Field>();
+        newFields.add(new DoubleField("score", scoreDocs.get(d).getScore()));
+        newFields.addAll(fields);
+        fields = newFields;
+        document.setFields(fields);
+      }
+      
       for (Field field : fields) {
         String name = field.getName();
         String type = field.getType().name();
@@ -259,6 +272,9 @@ public class SearchCommand extends TableSingleArgumentCommand {
     case LONG:
       Long valueLong = new LongField(field).getValueLong();
       return valueLong == null ? "NULL" : valueLong.toString();
+    case DOUBLE:
+      Double valueDouble = new DoubleField(field).getValueDouble();
+      return valueDouble == null ? "NULL" : valueDouble.toString();
     default:
       throw new RuntimeException("Not supported");
     }


Mime
View raw message