lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1131275 [1/2] - in /lucene/dev/branches/docvalues: ./ dev-tools/idea/lucene/contrib/ dev-tools/scripts/ lucene/ lucene/contrib/queries/src/test/org/apache/lucene/search/regex/ lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlp...
Date Fri, 03 Jun 2011 22:40:44 GMT
Author: simonw
Date: Fri Jun  3 22:40:42 2011
New Revision: 1131275

URL: http://svn.apache.org/viewvc?rev=1131275&view=rev
Log:
fixed several merge problems

Added:
    lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TermAllGroupsCollectorTest.java
      - copied unchanged from r1131267, lucene/dev/trunk/modules/grouping/src/test/org/apache/lucene/search/grouping/TermAllGroupsCollectorTest.java
    lucene/dev/branches/docvalues/solr/example/solr/conf/admin-extra.menu-bottom.html
      - copied unchanged from r1131267, lucene/dev/trunk/solr/example/solr/conf/admin-extra.menu-bottom.html
    lucene/dev/branches/docvalues/solr/example/solr/conf/admin-extra.menu-top.html
      - copied unchanged from r1131267, lucene/dev/trunk/solr/example/solr/conf/admin-extra.menu-top.html
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/MutableValueBool.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/MutableValueBool.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/BoolDocValues.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/BoolDocValues.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/BoolFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/BoolFunction.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DefFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DefFunction.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/IfFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IfFunction.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/MultiBoolFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiBoolFunction.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/MultiFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFunction.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/SimpleBoolFunction.java
      - copied unchanged from r1131267, lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleBoolFunction.java
Removed:
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/AllGroupsCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/SecondPassGroupingCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/schema-browser_field.html
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/schema-browser_index.html
Modified:
    lucene/dev/branches/docvalues/   (props changed)
    lucene/dev/branches/docvalues/dev-tools/idea/lucene/contrib/   (props changed)
    lucene/dev/branches/docvalues/dev-tools/scripts/poll-mirrors.pl
    lucene/dev/branches/docvalues/lucene/   (props changed)
    lucene/dev/branches/docvalues/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java   (props changed)
    lucene/dev/branches/docvalues/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java   (props changed)
    lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/index/TermsHashPerField.java
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermFirstPassGroupingCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermSecondPassGroupingCollector.java
    lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
    lucene/dev/branches/docvalues/solr/   (props changed)
    lucene/dev/branches/docvalues/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/docvalues/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/docvalues/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/docvalues/solr/README.txt   (props changed)
    lucene/dev/branches/docvalues/solr/build.xml   (props changed)
    lucene/dev/branches/docvalues/solr/client/   (props changed)
    lucene/dev/branches/docvalues/solr/common-build.xml   (props changed)
    lucene/dev/branches/docvalues/solr/contrib/   (props changed)
    lucene/dev/branches/docvalues/solr/example/   (props changed)
    lucene/dev/branches/docvalues/solr/lib/   (props changed)
    lucene/dev/branches/docvalues/solr/site/   (props changed)
    lucene/dev/branches/docvalues/solr/src/   (props changed)
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/schema/BoolField.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/FunctionQParser.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/ValueSourceParser.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstNumberSource.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstValueSource.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DocValues.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/LongDocValues.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StrDocValues.java
    lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java
    lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/TestQueryTypes.java
    lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java
    lucene/dev/branches/docvalues/solr/src/webapp/web/css/screen.css
    lucene/dev/branches/docvalues/solr/src/webapp/web/index.jsp
    lucene/dev/branches/docvalues/solr/src/webapp/web/js/script.js
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/analysis.html
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/cores.html
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/dashboard.html
    lucene/dev/branches/docvalues/solr/src/webapp/web/tpl/schema-browser.html
    lucene/dev/branches/docvalues/solr/testlogging.properties   (props changed)

Modified: lucene/dev/branches/docvalues/dev-tools/scripts/poll-mirrors.pl
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/dev-tools/scripts/poll-mirrors.pl?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/dev-tools/scripts/poll-mirrors.pl (original)
+++ lucene/dev/branches/docvalues/dev-tools/scripts/poll-mirrors.pl Fri Jun  3 22:40:42 2011
@@ -28,14 +28,15 @@ use strict;
 use warnings;
 use Getopt::Long;
 use LWP::Simple;
+require LWP::Parallel::UserAgent;
 
 my $version;
 my $interval = 300;
 my $quiet = 0;
 
-my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval, "quiet" => \$quiet);
+my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval);
 
-my $usage = "$0 -v version [ -i interval (seconds; default: 300)] [ -quiet ]";
+my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]";
 
 unless ($result) {
   print STDERR $usage;
@@ -47,26 +48,71 @@ unless (defined($version) && $version =~
 }
 
 my $previously_selected = select STDOUT;
-$| = 1; # turn off buffering of STDOUT, so "."s are printed immediately
+$| = 1; # turn off buffering of STDOUT, so status is printed immediately
 select $previously_selected;
 
-my $apache_backup_url = "http://www.apache.org/dist//lucene/java/$version/lucene-$version.tgz.asc";
-my $maven_url = "http://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom";
+my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc";
+my $apache_mirrors_list_url = "http://www.apache.org/mirrors/";
+my $maven_url = "http://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
 
-my $apache_available = 0;
 my $maven_available = 0;
 
-until ($apache_available && $maven_available) {
-  unless ($apache_available) {
-    my $content = get($apache_backup_url);
-    $apache_available = defined($content);
-    print "\nDownloadable: $apache_backup_url\n" if ($apache_available);
+my @apache_mirrors = ();
+
+my $apache_mirrors_list_page = get($apache_mirrors_list_url);
+if (defined($apache_mirrors_list_page)) {
+  #<TR>
+  #  <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A>&nbsp;&nbsp;<A HREF="http://apache.dattatec.com/">@</A></TD>
+  #
+  #  <TD>http</TD>
+  #  <TD ALIGN=RIGHT>8 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
+  #  <TD ALIGN=RIGHT>5 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
+  #  <TD>ok</TD>
+  #</TR>
+  while ($apache_mirrors_list_page =~ m~<TR>(.*?)</TR>~gis) {
+    my $mirror_entry = $1;
+    next unless ($mirror_entry =~ m~<TD>\s*ok\s*</TD>\s*$~i); # skip mirrors with problems
+    if ($mirror_entry =~ m~<A\s+HREF\s*=\s*"([^"]+)"\s*>~i) {
+      my $mirror_url = $1;
+      push @apache_mirrors, "$mirror_url/$apache_url_suffix";
+    }
   }
+} else {
+  print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url";
+  exit(1);
+}
+
+my $num_apache_mirrors = $#apache_mirrors;
+print "# Apache Mirrors: $num_apache_mirrors\n";
+
+while (1) {
   unless ($maven_available) {
     my $content = get($maven_url);
     $maven_available = defined($content);
-    print "\nDownloadable: $maven_url\n" if ($maven_available);
   }
-  print "." unless ($quiet);
-  sleep($interval) unless ($apache_available && $maven_available);
+  @apache_mirrors = &check_mirrors;
+  my $num_downloadable_apache_mirrors
+    = $num_apache_mirrors - $#apache_mirrors;
+
+  print "Available: ";
+  print "Maven Central; " if ($maven_available);
+  printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors,
+    $num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors);
+  last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors);
+  sleep($interval);
+}
+
+sub check_mirrors {
+  my $agent = LWP::Parallel::UserAgent->new();
+  $agent->timeout(30);
+  $agent->redirect(1);  # follow redirects
+  $agent->register($_) for (@apache_mirrors);
+  my $entries = $agent->wait();
+  my @not_yet_downloadable_apache_mirrors;
+  for my $entry (keys %$entries) {
+    my $response = $entries->{$entry}->response;
+    push @not_yet_downloadable_apache_mirrors, $response->request->uri
+      unless ($response->is_success);
+  }
+  return @not_yet_downloadable_apache_mirrors;
 }

Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/index/TermsHashPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/index/TermsHashPerField.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/index/TermsHashPerField.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/index/TermsHashPerField.java Fri Jun  3 22:40:42 2011
@@ -181,9 +181,9 @@ final class TermsHashPerField extends In
     // term text into textStart address
     // Get the text & hash of this term.
     int termID;
-    try{
-       termID = bytesHash.add(termBytesRef, termAtt.fillBytesRef());
-    }catch (MaxBytesLengthExceededException e) {
+    try {
+      termID = bytesHash.add(termBytesRef, termAtt.fillBytesRef());
+    } catch (MaxBytesLengthExceededException e) {
       // Not enough room in current block
       // Just skip this term, to remain as robust as
       // possible during indexing.  A TokenFilter

Modified: lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java (original)
+++ lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java Fri Jun  3 22:40:42 2011
@@ -212,7 +212,7 @@ public class BlockGroupingCollector exte
           // Swap pending scores
           final float[] savScores = og.scores;
           og.scores = pendingSubScores;
-          pendingSubScores = og.scores;
+          pendingSubScores = savScores;
         }
         og.readerContext = currentReaderContext;
         //og.groupOrd = lastGroupOrd;

Modified: lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermFirstPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermFirstPassGroupingCollector.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermFirstPassGroupingCollector.java (original)
+++ lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermFirstPassGroupingCollector.java Fri Jun  3 22:40:42 2011
@@ -26,7 +26,7 @@ import java.io.IOException;
 
 /**
  * Concrete implementation of {@link AbstractFirstPassGroupingCollector} that groups based on
- * field values and more specifically uses {@link org.apache.lucene.search.FieldCache.DocTerms}
+ * field values and more specifically uses {@link org.apache.lucene.search.FieldCache.DocTermsIndex}
  * to collect groups.
  *
  * @lucene.experimental

Modified: lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermSecondPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermSecondPassGroupingCollector.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermSecondPassGroupingCollector.java (original)
+++ lucene/dev/branches/docvalues/modules/grouping/src/java/org/apache/lucene/search/grouping/TermSecondPassGroupingCollector.java Fri Jun  3 22:40:42 2011
@@ -27,7 +27,7 @@ import java.util.Collection;
 
 /**
  * Concrete implementation of {@link AbstractSecondPassGroupingCollector} that groups based on
- * field values and more specifically uses {@link org.apache.lucene.search.FieldCache.DocTerms}
+ * field values and more specifically uses {@link org.apache.lucene.search.FieldCache.DocTermsIndex}
  * to collect grouped docs.
  *
  * @lucene.experimental

Modified: lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java (original)
+++ lucene/dev/branches/docvalues/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java Fri Jun  3 22:40:42 2011
@@ -154,7 +154,10 @@ public class TestGrouping extends Lucene
     final BytesRef group;
     final BytesRef sort1;
     final BytesRef sort2;
+    // content must be "realN ..."
     final String content;
+    float score;
+    float score2;
 
     public GroupDoc(int id, BytesRef group, BytesRef sort1, BytesRef sort2, String content) {
       this.id = id;
@@ -167,16 +170,21 @@ public class TestGrouping extends Lucene
 
   private Sort getRandomSort() {
     final List<SortField> sortFields = new ArrayList<SortField>();
-    if (random.nextBoolean()) {
+    if (random.nextInt(7) == 2) {
+      sortFields.add(SortField.FIELD_SCORE);
+    } else {
       if (random.nextBoolean()) {
+        if (random.nextBoolean()) {
+          sortFields.add(new SortField("sort1", SortField.STRING, random.nextBoolean()));
+        } else {
+          sortFields.add(new SortField("sort2", SortField.STRING, random.nextBoolean()));
+        }
+      } else if (random.nextBoolean()) {
         sortFields.add(new SortField("sort1", SortField.STRING, random.nextBoolean()));
-      } else {
         sortFields.add(new SortField("sort2", SortField.STRING, random.nextBoolean()));
       }
-    } else if (random.nextBoolean()) {
-      sortFields.add(new SortField("sort1", SortField.STRING, random.nextBoolean()));
-      sortFields.add(new SortField("sort2", SortField.STRING, random.nextBoolean()));
     }
+    // Break ties:
     sortFields.add(new SortField("id", SortField.INT));
     return new Sort(sortFields.toArray(new SortField[sortFields.size()]));
   }
@@ -188,7 +196,15 @@ public class TestGrouping extends Lucene
       public int compare(GroupDoc d1, GroupDoc d2) {
         for(SortField sf : sortFields) {
           final int cmp;
-          if (sf.getField().equals("sort1")) {
+          if (sf.getType() == SortField.SCORE) {
+            if (d1.score > d2.score) {
+              cmp = -1;
+            } else if (d1.score < d2.score) {
+              cmp = 1;
+            } else {
+              cmp = 0;
+            }
+          } else if (sf.getField().equals("sort1")) {
             cmp = d1.sort1.compareTo(d2.sort1);
           } else if (sf.getField().equals("sort2")) {
             cmp = d1.sort2.compareTo(d2.sort2);
@@ -213,7 +229,9 @@ public class TestGrouping extends Lucene
     for(int fieldIDX=0;fieldIDX<sortFields.length;fieldIDX++) {
       final Comparable<?> c;
       final SortField sf = sortFields[fieldIDX];
-      if (sf.getField().equals("sort1")) {
+      if (sf.getType() == SortField.SCORE) {
+        c = new Float(d.score);
+      } else if (sf.getField().equals("sort1")) {
         c = d.sort1;
       } else if (sf.getField().equals("sort2")) {
         c = d.sort2;
@@ -237,17 +255,17 @@ public class TestGrouping extends Lucene
   */
 
   private TopGroups<BytesRef> slowGrouping(GroupDoc[] groupDocs,
-                                 String searchTerm,
-                                 boolean fillFields,
-                                 boolean getScores,
-                                 boolean getMaxScores,
-                                 boolean doAllGroups,
-                                 Sort groupSort,
-                                 Sort docSort,
-                                 int topNGroups,
-                                 int docsPerGroup,
-                                 int groupOffset,
-                                 int docOffset) {
+                                           String searchTerm,
+                                           boolean fillFields,
+                                           boolean getScores,
+                                           boolean getMaxScores,
+                                           boolean doAllGroups,
+                                           Sort groupSort,
+                                           Sort docSort,
+                                           int topNGroups,
+                                           int docsPerGroup,
+                                           int groupOffset,
+                                           int docOffset) {
 
     final Comparator<GroupDoc> groupSortComp = getComparator(groupSort);
 
@@ -262,11 +280,11 @@ public class TestGrouping extends Lucene
     //System.out.println("TEST: slowGrouping");
     for(GroupDoc d : groupDocs) {
       // TODO: would be better to filter by searchTerm before sorting!
-      if (!d.content.equals(searchTerm)) {
+      if (!d.content.startsWith(searchTerm)) {
         continue;
       }
       totalHitCount++;
-      //System.out.println("  match id=" + d.id);
+      //System.out.println("  match id=" + d.id + " score=" + d.score);
 
       if (doAllGroups) {
         if (!knownGroups.contains(d.group)) {
@@ -312,9 +330,9 @@ public class TestGrouping extends Lucene
           final GroupDoc d = docs.get(docIDX);
           final FieldDoc fd;
           if (fillFields) {
-            fd = new FieldDoc(d.id, 0.0f, fillFields(d, docSort));
+            fd = new FieldDoc(d.id, getScores ? d.score : Float.NaN, fillFields(d, docSort));
           } else {
-            fd = new FieldDoc(d.id, 0.0f);
+            fd = new FieldDoc(d.id, getScores ? d.score : Float.NaN);
           }
           hits[docIDX-docOffset] = fd;
         }
@@ -373,7 +391,7 @@ public class TestGrouping extends Lucene
         doc.add(newField("sort1", groupValue.sort1.utf8ToString(), Field.Index.NOT_ANALYZED));
         doc.add(newField("sort2", groupValue.sort2.utf8ToString(), Field.Index.NOT_ANALYZED));
         doc.add(new NumericField("id").setIntValue(groupValue.id));
-        doc.add(newField("content", groupValue.content, Field.Index.NOT_ANALYZED));
+        doc.add(newField("content", groupValue.content, Field.Index.ANALYZED));
         //System.out.println("TEST:     doc content=" + groupValue.content + " group=" + (groupValue.group == null ? "null" : groupValue.group.utf8ToString()) + " sort1=" + groupValue.sort1.utf8ToString() + " id=" + groupValue.id);
       }
       // So we can pull filter marking last doc in block:
@@ -421,7 +439,22 @@ public class TestGrouping extends Lucene
         groups.add(new BytesRef(_TestUtil.randomRealisticUnicodeString(random)));
         //groups.add(new BytesRef(_TestUtil.randomSimpleString(random)));
       }
-      final String[] contentStrings = new String[] {"a", "b", "c", "d"};
+      final String[] contentStrings = new String[_TestUtil.nextInt(random, 2, 20)];
+      if (VERBOSE) {
+        System.out.println("TEST: create fake content");
+      }
+      for(int contentIDX=0;contentIDX<contentStrings.length;contentIDX++) {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("real" + random.nextInt(3)).append(' ');
+        final int fakeCount = random.nextInt(10);
+        for(int fakeIDX=0;fakeIDX<fakeCount;fakeIDX++) {
+          sb.append("fake ");
+        }
+        contentStrings[contentIDX] = sb.toString();
+        if (VERBOSE) {
+          System.out.println("  content=" + sb.toString());
+        }
+      }
 
       Directory dir = newDirectory();
       RandomIndexWriter w = new RandomIndexWriter(
@@ -440,7 +473,7 @@ public class TestGrouping extends Lucene
       Field sort2 = newField("sort2", "", Field.Index.NOT_ANALYZED);
       doc.add(sort2);
       docNoGroup.add(sort2);
-      Field content = newField("content", "", Field.Index.NOT_ANALYZED);
+      Field content = newField("content", "", Field.Index.ANALYZED);
       doc.add(content);
       docNoGroup.add(content);
       NumericField id = new NumericField("id");
@@ -480,40 +513,96 @@ public class TestGrouping extends Lucene
         }
       }
 
+      final GroupDoc[] groupDocsByID = new GroupDoc[groupDocs.length];
+      System.arraycopy(groupDocs, 0, groupDocsByID, 0, groupDocs.length);
+
       final IndexReader r = w.getReader();
       w.close();
 
-      // Build 2nd index, where docs are added in blocks by
-      // group, so we can use single pass collector
-      final Directory dir2 = newDirectory();
-      final IndexReader r2 = getDocBlockReader(dir2, groupDocs);
-      final Filter lastDocInBlock = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupend", "x"))));
-
-      final IndexSearcher s = new IndexSearcher(r);
-      final IndexSearcher s2 = new IndexSearcher(r2);
-
+      // NOTE: intentional but temporary field cache insanity!
       final int[] docIDToID = FieldCache.DEFAULT.getInts(r, "id");
-      final int[] docIDToID2 = FieldCache.DEFAULT.getInts(r2, "id");
+      IndexReader r2 = null;
+      Directory dir2 = null;
 
       try {
+        final IndexSearcher s = new IndexSearcher(r);
+
+        for(int contentID=0;contentID<3;contentID++) {
+          final ScoreDoc[] hits = s.search(new TermQuery(new Term("content", "real"+contentID)), numDocs).scoreDocs;
+          for(ScoreDoc hit : hits) {
+            final GroupDoc gd = groupDocs[docIDToID[hit.doc]];
+            assertTrue(gd.score == 0.0);
+            gd.score = hit.score;
+            assertEquals(gd.id, docIDToID[hit.doc]);
+            //System.out.println("  score=" + hit.score + " id=" + docIDToID[hit.doc]);
+          }
+        }
+
+        for(GroupDoc gd : groupDocs) {
+          assertTrue(gd.score != 0.0);
+        }
+
+        // Build 2nd index, where docs are added in blocks by
+        // group, so we can use single pass collector
+        dir2 = newDirectory();
+        r2 = getDocBlockReader(dir2, groupDocs);
+        final Filter lastDocInBlock = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupend", "x"))));
+        final int[] docIDToID2 = FieldCache.DEFAULT.getInts(r2, "id");
+
+        final IndexSearcher s2 = new IndexSearcher(r2);
+
+        // Reader2 only increases maxDoc() vs reader, which
+        // means a monotonic shift in scores, so we can
+        // reliably remap them w/ Map:
+        final Map<Float,Float> scoreMap = new HashMap<Float,Float>();
+
+        // Tricky: must separately set .score2, because the doc
+        // block index was created with possible deletions!
+        for(int contentID=0;contentID<3;contentID++) {
+          //System.out.println("term=real" + contentID + " dfold=" + s.docFreq(new Term("content", "real"+contentID)) +
+          //" dfnew=" + s2.docFreq(new Term("content", "real"+contentID)));
+          final ScoreDoc[] hits = s2.search(new TermQuery(new Term("content", "real"+contentID)), numDocs).scoreDocs;
+          for(ScoreDoc hit : hits) {
+            final GroupDoc gd = groupDocsByID[docIDToID2[hit.doc]];
+            assertTrue(gd.score2 == 0.0);
+            gd.score2 = hit.score;
+            assertEquals(gd.id, docIDToID2[hit.doc]);
+            //System.out.println("  score=" + hit.score + " id=" + docIDToID2[hit.doc]);
+            scoreMap.put(gd.score, gd.score2);
+          }
+        }
+
         for(int searchIter=0;searchIter<100;searchIter++) {
 
           if (VERBOSE) {
             System.out.println("TEST: searchIter=" + searchIter);
           }
 
-          final String searchTerm = contentStrings[random.nextInt(contentStrings.length)];
+          final String searchTerm = "real" + random.nextInt(3);
           final boolean fillFields = random.nextBoolean();
-          final boolean getScores = random.nextBoolean();
+          boolean getScores = random.nextBoolean();
           final boolean getMaxScores = random.nextBoolean();
           final Sort groupSort = getRandomSort();
           //final Sort groupSort = new Sort(new SortField[] {new SortField("sort1", SortField.STRING), new SortField("id", SortField.INT)});
           // TODO: also test null (= sort by relevance)
           final Sort docSort = getRandomSort();
 
+          for(SortField sf : docSort.getSort()) {
+            if (sf.getType() == SortField.SCORE) {
+              getScores = true;
+            }
+          }
+
+          for(SortField sf : groupSort.getSort()) {
+            if (sf.getType() == SortField.SCORE) {
+              getScores = true;
+            }
+          }
+
           final int topNGroups = _TestUtil.nextInt(random, 1, 30);
           //final int topNGroups = 4;
           final int docsPerGroup = _TestUtil.nextInt(random, 1, 50);
+
           final int groupOffset = _TestUtil.nextInt(random, 0, (topNGroups-1)/2);
           //final int groupOffset = 0;
 
@@ -523,7 +612,7 @@ public class TestGrouping extends Lucene
           final boolean doCache = random.nextBoolean();
           final boolean doAllGroups = random.nextBoolean();
           if (VERBOSE) {
-            System.out.println("TEST: groupSort=" + groupSort + " docSort=" + docSort + " searchTerm=" + searchTerm + " topNGroups=" + topNGroups + " groupOffset=" + groupOffset + " docOffset=" + docOffset + " doCache=" + doCache + " docsPerGroup=" + docsPerGroup + " doAllGroups=" + doAllGroups);
+            System.out.println("TEST: groupSort=" + groupSort + " docSort=" + docSort + " searchTerm=" + searchTerm + " topNGroups=" + topNGroups + " groupOffset=" + groupOffset + " docOffset=" + docOffset + " doCache=" + doCache + " docsPerGroup=" + docsPerGroup + " doAllGroups=" + doAllGroups + " getScores=" + getScores + " getMaxScores=" + getMaxScores);
           }
 
           final TermAllGroupsCollector allGroupsCollector;
@@ -636,13 +725,12 @@ public class TestGrouping extends Lucene
               for(GroupDocs<BytesRef> gd : expectedGroups.groups) {
                 System.out.println("  group=" + (gd.groupValue == null ? "null" : gd.groupValue.utf8ToString()));
                 for(ScoreDoc sd : gd.scoreDocs) {
-                  System.out.println("    id=" + sd.doc);
+                  System.out.println("    id=" + sd.doc + " score=" + sd.score);
                 }
               }
             }
           }
-          // NOTE: intentional but temporary field cache insanity!
-          assertEquals(docIDToID, expectedGroups, groupsResult, true);
+          assertEquals(docIDToID, expectedGroups, groupsResult, true, getScores);
 
           final boolean needsScores = getScores || getMaxScores || docSort == null;
           final BlockGroupingCollector c3 = new BlockGroupingCollector(groupSort, groupOffset+topNGroups, needsScores, lastDocInBlock);
@@ -665,11 +753,53 @@ public class TestGrouping extends Lucene
           } else {
             groupsResult2 = tempTopGroups2;
           }
-          assertEquals(docIDToID2, expectedGroups, groupsResult2, false);
+
+          if (expectedGroups != null) {
+            // Fixup scores for reader2
+            for (GroupDocs groupDocsHits : expectedGroups.groups) {
+              for(ScoreDoc hit : groupDocsHits.scoreDocs) {
+                final GroupDoc gd = groupDocsByID[hit.doc];
+                assertEquals(gd.id, hit.doc);
+                //System.out.println("fixup score " + hit.score + " to " + gd.score2 + " vs " + gd.score);
+                hit.score = gd.score2;
+              }
+            }
+
+            final SortField[] sortFields = groupSort.getSort();
+            for(int groupSortIDX=0;groupSortIDX<sortFields.length;groupSortIDX++) {
+              if (sortFields[groupSortIDX].getType() == SortField.SCORE) {
+                for (GroupDocs groupDocsHits : expectedGroups.groups) {
+                  if (groupDocsHits.groupSortValues != null) {
+                    groupDocsHits.groupSortValues[groupSortIDX] = scoreMap.get(groupDocsHits.groupSortValues[groupSortIDX]);
+                    assertNotNull(groupDocsHits.groupSortValues[groupSortIDX]);
+                  }
+                }
+              }
+            }
+
+            final SortField[] docSortFields = docSort.getSort();
+            for(int docSortIDX=0;docSortIDX<docSortFields.length;docSortIDX++) {
+              if (docSortFields[docSortIDX].getType() == SortField.SCORE) {
+                for (GroupDocs groupDocsHits : expectedGroups.groups) {
+                  for(ScoreDoc _hit : groupDocsHits.scoreDocs) {
+                    FieldDoc hit = (FieldDoc) _hit;
+                    if (hit.fields != null) {
+                      hit.fields[docSortIDX] = scoreMap.get(hit.fields[docSortIDX]);
+                      assertNotNull(hit.fields[docSortIDX]);
+                    }
+                  }
+                }
+              }
+            }
+          }
+
+          assertEquals(docIDToID2, expectedGroups, groupsResult2, false, getScores);
         }
       } finally {
         FieldCache.DEFAULT.purge(r);
-        FieldCache.DEFAULT.purge(r2);
+        if (r2 != null) {
+          FieldCache.DEFAULT.purge(r2);
+        }
       }
 
       r.close();
@@ -680,7 +810,7 @@ public class TestGrouping extends Lucene
     }
   }
 
-  private void assertEquals(int[] docIDtoID, TopGroups expected, TopGroups actual, boolean verifyGroupValues) {
+  private void assertEquals(int[] docIDtoID, TopGroups expected, TopGroups actual, boolean verifyGroupValues, boolean testScores) {
     if (expected == null) {
       assertNull(actual);
       return;
@@ -716,9 +846,14 @@ public class TestGrouping extends Lucene
       for(int docIDX=0;docIDX<expectedFDs.length;docIDX++) {
         final FieldDoc expectedFD = (FieldDoc) expectedFDs[docIDX];
         final FieldDoc actualFD = (FieldDoc) actualFDs[docIDX];
+        //System.out.println("  actual doc=" + docIDtoID[actualFD.doc] + " score=" + actualFD.score);
         assertEquals(expectedFD.doc, docIDtoID[actualFD.doc]);
-        // TODO
-        // assertEquals(expectedFD.score, actualFD.score);
+        if (testScores) {
+          assertEquals(expectedFD.score, actualFD.score);
+        } else {
+          // TODO: too anal for now
+          //assertEquals(Float.NaN, actualFD.score);
+        }
         assertArrayEquals(expectedFD.fields, actualFD.fields);
       }
     }

Modified: lucene/dev/branches/docvalues/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/CHANGES.txt?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/CHANGES.txt (original)
+++ lucene/dev/branches/docvalues/solr/CHANGES.txt Fri Jun  3 22:40:42 2011
@@ -144,6 +144,10 @@ New Features
   to IndexReader.open (in the case you have a custom IndexReaderFactory).
   (simonw via rmuir)
 
+* SOLR-2136: Boolean type added to function queries, along with
+  new functions exists(), if(), and(), or(), xor(), not(), def(),
+  and true and false constants. (yonik) 
+
 
 Optimizations
 ----------------------

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/schema/BoolField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/schema/BoolField.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/schema/BoolField.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/schema/BoolField.java Fri Jun  3 22:40:42 2011
@@ -17,12 +17,16 @@
 
 package org.apache.solr.schema;
 
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueBool;
+import org.apache.solr.search.MutableValueInt;
 import org.apache.solr.search.QParser;
-import org.apache.solr.search.function.ValueSource;
-import org.apache.solr.search.function.OrdFieldSource;
+import org.apache.solr.search.function.*;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.Tokenizer;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -50,7 +54,7 @@ public class BoolField extends FieldType
   @Override
   public ValueSource getValueSource(SchemaField field, QParser qparser) {
     field.checkFieldCacheSource(qparser);
-    return new OrdFieldSource(field.name);
+    return new BoolFieldSource(field.name);
   }
 
   // avoid instantiating every time...
@@ -121,7 +125,7 @@ public class BoolField extends FieldType
 
   @Override
   public Object toObject(SchemaField sf, BytesRef term) {
-    return term.bytes[0] == 'T';
+    return term.bytes[term.offset] == 'T';
   }
 
   @Override
@@ -145,6 +149,83 @@ public class BoolField extends FieldType
 
   @Override
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
-    writer.writeBool(name, f.stringValue().charAt(0) =='T');
+    writer.writeBool(name, f.stringValue().charAt(0) == 'T');
   }
 }
+
+// TODO - this can be much more efficient - use OpenBitSet or Bits
+class BoolFieldSource extends ValueSource {
+  protected String field;
+
+  public BoolFieldSource(String field) {
+    this.field = field;
+  }
+
+  @Override
+  public String description() {
+    return "bool(" + field + ')';
+  }
+
+
+  @Override
+  public DocValues getValues(Map context, IndexReader.AtomicReaderContext readerContext) throws IOException {
+    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(readerContext.reader, field);
+
+    // figure out what ord maps to true
+    int nord = sindex.numOrd();
+    BytesRef br = new BytesRef();
+    int tord = -1;
+    for (int i=1; i<nord; i++) {
+      sindex.lookup(i, br);
+      if (br.length==1 && br.bytes[br.offset]=='T') {
+        tord = i;
+        break;
+      }
+    }
+
+    final int trueOrd = tord;
+
+    return new BoolDocValues(this) {
+      @Override
+      public boolean boolVal(int doc) {
+        return sindex.getOrd(doc) == trueOrd;
+      }
+
+      @Override
+      public boolean exists(int doc) {
+        return sindex.getOrd(doc) != 0;
+      }
+
+      @Override
+      public ValueFiller getValueFiller() {
+        return new ValueFiller() {
+          private final MutableValueBool mval = new MutableValueBool();
+
+          @Override
+          public MutableValue getValue() {
+            return mval;
+          }
+
+          @Override
+          public void fillValue(int doc) {
+            int ord = sindex.getOrd(doc);
+            mval.value = (ord == trueOrd);
+            mval.exists = (ord != 0);
+          }
+        };
+      }
+    };
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    return o.getClass() == BoolFieldSource.class && this.field.equals(((BoolFieldSource)o).field);
+  }
+
+  private static final int hcode = OrdFieldSource.class.hashCode();
+  @Override
+  public int hashCode() {
+    return hcode + field.hashCode();
+  };
+
+}

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/FunctionQParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/FunctionQParser.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/FunctionQParser.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/FunctionQParser.java Fri Jun  3 22:40:42 2011
@@ -364,8 +364,14 @@ public class FunctionQParser extends QPa
         sp.expect(")");
       }
       else {
-        SchemaField f = req.getSchema().getField(id);
-        valueSource = f.getType().getValueSource(f, this);
+        if ("true".equals(id)) {
+          valueSource = new BoolConstValueSource(true);
+        } else if ("false".equals(id)) {
+          valueSource = new BoolConstValueSource(false);
+        } else {
+          SchemaField f = req.getSchema().getField(id);
+          valueSource = f.getType().getValueSource(f, this);
+        }
       }
 
     }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/ValueSourceParser.java Fri Jun  3 22:40:42 2011
@@ -579,6 +579,134 @@ public abstract class ValueSourceParser 
         return new NumDocsValueSource();
       }
     });
+
+    addParser("true", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        return new BoolConstValueSource(true);
+      }
+    });
+
+    addParser("false", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        return new BoolConstValueSource(false);
+      }
+    });
+
+    addParser("exists", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        ValueSource vs = fp.parseValueSource();
+        return new SimpleBoolFunction(vs) {
+          @Override
+          protected String name() {
+            return "exists";
+          }
+          @Override
+          protected boolean func(int doc, DocValues vals) {
+            return vals.exists(doc);
+          }
+        };
+      }
+    });
+
+    addParser("not", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        ValueSource vs = fp.parseValueSource();
+        return new SimpleBoolFunction(vs) {
+          @Override
+          protected boolean func(int doc, DocValues vals) {
+            return !vals.boolVal(doc);
+          }
+          @Override
+          protected String name() {
+            return "not";
+          }
+        };
+      }
+    });
+
+
+    addParser("and", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        List<ValueSource> sources = fp.parseValueSourceList();
+        return new MultiBoolFunction(sources) {
+          @Override
+          protected String name() {
+            return "and";
+          }
+          @Override
+          protected boolean func(int doc, DocValues[] vals) {
+            for (DocValues dv : vals)
+              if (!dv.boolVal(doc)) return false;
+            return true;
+          }
+        };
+      }
+    });
+
+    addParser("or", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        List<ValueSource> sources = fp.parseValueSourceList();
+        return new MultiBoolFunction(sources) {
+          @Override
+          protected String name() {
+            return "or";
+          }
+          @Override
+          protected boolean func(int doc, DocValues[] vals) {
+            for (DocValues dv : vals)
+              if (dv.boolVal(doc)) return true;
+            return false;
+          }
+        };
+      }
+    });
+
+    addParser("xor", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        List<ValueSource> sources = fp.parseValueSourceList();
+        return new MultiBoolFunction(sources) {
+          @Override
+          protected String name() {
+            return "xor";
+          }
+          @Override
+          protected boolean func(int doc, DocValues[] vals) {
+            int nTrue=0, nFalse=0;
+            for (DocValues dv : vals) {
+              if (dv.boolVal(doc)) nTrue++;
+              else nFalse++;
+            }
+            return nTrue != 0 && nFalse != 0;
+          }
+        };
+      }
+    });
+
+    addParser("if", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        ValueSource ifValueSource = fp.parseValueSource();
+        ValueSource trueValueSource = fp.parseValueSource();
+        ValueSource falseValueSource = fp.parseValueSource();
+
+        return new IfFunction(ifValueSource, trueValueSource, falseValueSource);
+      }
+    });
+
+    addParser("def", new ValueSourceParser() {
+      @Override
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        return new DefFunction(fp.parseValueSourceList());
+      }
+    });
+
   }
 
   private static TInfo parseTerm(FunctionQParser fp) throws ParseException {
@@ -857,6 +985,11 @@ class LongConstValueSource extends Const
   public Number getNumber() {
     return constant;
   }
+
+  @Override
+  public boolean getBool() {
+    return constant != 0;
+  }
 }
 
 
@@ -981,3 +1114,69 @@ abstract class Double2Parser extends Nam
   }
 
 }
+
+
+class BoolConstValueSource extends ConstNumberSource {
+  final boolean constant;
+
+  public BoolConstValueSource(boolean constant) {
+    this.constant = constant;
+  }
+
+  @Override
+  public String description() {
+    return "const(" + constant + ")";
+  }
+
+  @Override
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    return new BoolDocValues(this) {
+      @Override
+      public boolean boolVal(int doc) {
+        return constant;
+      }
+    };
+  }
+
+  @Override
+  public int hashCode() {
+    return constant ? 0x12345678 : 0x87654321;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (BoolConstValueSource.class != o.getClass()) return false;
+    BoolConstValueSource other = (BoolConstValueSource) o;
+    return this.constant == other.constant;
+  }
+
+    @Override
+  public int getInt() {
+    return constant ? 1 : 0;
+  }
+
+  @Override
+  public long getLong() {
+    return constant ? 1 : 0;
+  }
+
+  @Override
+  public float getFloat() {
+    return constant ? 1 : 0;
+  }
+
+  @Override
+  public double getDouble() {
+    return constant ? 1 : 0;
+  }
+
+  @Override
+  public Number getNumber() {
+    return constant ? 1 : 0;
+  }
+
+  @Override
+  public boolean getBool() {
+    return constant;
+  }
+}

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstNumberSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstNumberSource.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstNumberSource.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstNumberSource.java Fri Jun  3 22:40:42 2011
@@ -26,4 +26,5 @@ public abstract class ConstNumberSource 
   public abstract float getFloat();
   public abstract double getDouble();  
   public abstract Number getNumber();  
+  public abstract boolean getBool();
 }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstValueSource.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstValueSource.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/ConstValueSource.java Fri Jun  3 22:40:42 2011
@@ -66,6 +66,10 @@ public class ConstValueSource extends Co
       public Object objectVal(int doc) {
         return constant;
       }
+      @Override
+      public boolean boolVal(int doc) {
+        return constant != 0.0f;
+      }
     };
   }
 
@@ -105,4 +109,9 @@ public class ConstValueSource extends Co
   public Number getNumber() {
     return constant;
   }
+
+  @Override
+  public boolean getBool() {
+    return constant != 0.0f;
+  }
 }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DocValues.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DocValues.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DocValues.java Fri Jun  3 22:40:42 2011
@@ -48,6 +48,10 @@ public abstract class DocValues {
   // TODO: should we make a termVal, returns BytesRef?
   public String strVal(int doc) { throw new UnsupportedOperationException(); }
 
+  public boolean boolVal(int doc) {
+    return intVal(doc) != 0;
+  }
+
   /** returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? */
   public boolean bytesVal(int doc, BytesRef target) {
     String s = strVal(doc);

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java Fri Jun  3 22:40:42 2011
@@ -115,4 +115,9 @@ public class DoubleConstValueSource exte
   public Number getNumber() {
     return constant;
   }
+
+  @Override
+  public boolean getBool() {
+    return constant != 0;
+  }
 }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java Fri Jun  3 22:40:42 2011
@@ -36,6 +36,11 @@ public abstract class DoubleDocValues ex
   }
 
   @Override
+  public boolean boolVal(int doc) {
+    return doubleVal(doc) != 0;
+  }
+
+  @Override
   public abstract double doubleVal(int doc);
 
   @Override

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java Fri Jun  3 22:40:42 2011
@@ -53,40 +53,15 @@ public class DoubleFieldSource extends N
     final double[] arr = vals.values;
     final Bits valid = vals.valid;
     
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float) arr[doc];
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) arr[doc];
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) arr[doc];
-      }
-
+    return new DoubleDocValues(this) {
       @Override
       public double doubleVal(int doc) {
         return arr[doc];
       }
 
       @Override
-      public String strVal(int doc) {
-        return Double.toString(arr[doc]);
-      }
-
-      @Override
-      public Object objectVal(int doc) {
-        return valid.get(doc) ? arr[doc] : null;
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + doubleVal(doc);
+      public boolean exists(int doc) {
+        return valid.get(doc);
       }
 
       @Override
@@ -147,7 +122,7 @@ public class DoubleFieldSource extends N
         }
       }
 
-            @Override
+      @Override
       public ValueFiller getValueFiller() {
         return new ValueFiller() {
           private final double[] doubleArr = arr;

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/LongDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/LongDocValues.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/LongDocValues.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/LongDocValues.java Fri Jun  3 22:40:42 2011
@@ -39,6 +39,11 @@ public abstract class LongDocValues exte
   }
 
   @Override
+  public boolean boolVal(int doc) {
+    return longVal(doc) != 0;
+  }
+
+  @Override
   public String strVal(int doc) {
     return Long.toString(longVal(doc));
   }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StrDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StrDocValues.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StrDocValues.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StrDocValues.java Fri Jun  3 22:40:42 2011
@@ -22,6 +22,11 @@ public abstract class StrDocValues exten
   }
 
   @Override
+  public boolean boolVal(int doc) {
+    return exists(doc);
+  }
+
+  @Override
   public String toString(int doc) {
     return vs.description() + "='" + strVal(doc) + "'";
   }

Modified: lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java (original)
+++ lucene/dev/branches/docvalues/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java Fri Jun  3 22:40:42 2011
@@ -78,6 +78,10 @@ public abstract class StringIndexDocValu
     return spareChars.toString();
   }
 
+  @Override
+  public boolean boolVal(int doc) {
+    return exists(doc);
+  }
 
   @Override
   public abstract Object objectVal(int doc);  // force subclasses to override

Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/TestQueryTypes.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/TestQueryTypes.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/TestQueryTypes.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/TestQueryTypes.java Fri Jun  3 22:40:42 2011
@@ -119,7 +119,29 @@ public class TestQueryTypes extends Abst
       assertQ(req( "q", "{!frange v="+f+" l='"+v+"' u='"+v+"'}" )
               ,"//result[@numFound='1']"
               );
-      
+
+      // exists()
+      assertQ(req( "fq","id:999", "q", "{!frange l=1 u=1}if(exists("+f+"),1,0)" )
+              ,"//result[@numFound='1']"
+              );
+
+      // boolean value of non-zero values (just leave off the exists from the prev test)
+      assertQ(req( "fq","id:999", "q", "{!frange l=1 u=1}if("+f+",1,0)" )
+              ,"//result[@numFound='1']"
+              );
+
+      if (!"id".equals(f)) {
+        assertQ(req( "fq","id:1", "q", "{!frange l=1 u=1}if(exists("+f+"),1,0)" )
+            ,"//result[@numFound='0']"
+        );
+
+       // boolean value of zero/missing values (just leave off the exists from the prev test)
+       assertQ(req( "fq","id:1", "q", "{!frange l=1 u=1}if("+f+",1,0)" )
+            ,"//result[@numFound='0']"
+        );
+
+      }
+
       // function query... just make sure it doesn't throw an exception
       if ("v_s".equals(f)) continue;  // in this context, functions must be able to be interpreted as a float
       assertQ(req( "q", "+id:999 _val_:\"" + f + "\"")

Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/function/TestFunctionQuery.java Fri Jun  3 22:40:42 2011
@@ -581,4 +581,56 @@ public class TestFunctionQuery extends S
     purgeFieldCache(FieldCache.DEFAULT);   // avoid FC insanity    
   }
 
+    @Test
+  public void testBooleanFunctions() throws Exception {
+    assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0"));
+    assertU(adoc("id", "2"                              , "foo_ti","10", "foo_tl","11"));
+    assertU(commit());
+
+    // true and false functions and constants
+    assertJQ(req("q", "id:1", "fl", "t:true(),f:false(),tt:{!func}true,ff:{!func}false")
+        , "/response/docs/[0]=={'t':true,'f':false,'tt':true,'ff':false}");
+
+    // test that exists(query) depends on the query matching the document
+    assertJQ(req("q", "id:1", "fl", "t:exists(query($q1)),f:exists(query($q2))", "q1","text:hello", "q2","text:there")
+        , "/response/docs/[0]=={'t':true,'f':false}");
+
+    // test if()
+    assertJQ(req("q", "id:1", "fl", "a1:if(true,'A','B')", "fl","b1:if(false,'A','B')")
+        , "/response/docs/[0]=={'a1':'A', 'b1':'B'}");
+
+    // test boolean operators
+    assertJQ(req("q", "id:1", "fl", "t1:and(true,true)", "fl","f1:and(true,false)", "fl","f2:and(false,true)", "fl","f3:and(false,false)")
+        , "/response/docs/[0]=={'t1':true, 'f1':false, 'f2':false, 'f3':false}");
+    assertJQ(req("q", "id:1", "fl", "t1:or(true,true)", "fl","t2:or(true,false)", "fl","t3:or(false,true)", "fl","f1:or(false,false)")
+        , "/response/docs/[0]=={'t1':true, 't2':true, 't3':true, 'f1':false}");
+    assertJQ(req("q", "id:1", "fl", "f1:xor(true,true)", "fl","t1:xor(true,false)", "fl","t2:xor(false,true)", "fl","f2:xor(false,false)")
+        , "/response/docs/[0]=={'t1':true, 't2':true, 'f1':false, 'f2':false}");
+    assertJQ(req("q", "id:1", "fl", "t:not(false),f:not(true)")
+        , "/response/docs/[0]=={'t':true, 'f':false}");
+
+
+    // def(), the default function that returns the first value that exists
+    assertJQ(req("q", "id:1", "fl", "x:def(id,123.0), y:def(foo_f,234.0)")
+        , "/response/docs/[0]=={'x':1.0, 'y':234.0}");
+    assertJQ(req("q", "id:1", "fl", "x:def(foo_s,'Q'), y:def(missing_s,'W')")
+        , "/response/docs/[0]=={'x':'A', 'y':'W'}");
+
+    // test constant conversion to boolean
+    assertJQ(req("q", "id:1", "fl", "a:not(0), b:not(1), c:not(0.0), d:not(1.1), e:not('A')")
+        , "/response/docs/[0]=={'a':true, 'b':false, 'c':true, 'd':false, 'e':false}");
+
+  }
+
+
+  @Test
+  public void testPseudoFieldFunctions() throws Exception {
+    assertU(adoc("id", "1", "text", "hello", "foo_s","A"));
+    assertU(adoc("id", "2"));
+    assertU(commit());
+
+    assertJQ(req("q", "id:1", "fl", "a:1,b:2.0,c:'X',d:{!func}foo_s,e:{!func}bar_s")  // if exists() is false, no pseudo-field should be added
+        , "/response/docs/[0]=={'a':1, 'b':2.0,'c':'X','d':'A'}");
+  }
+
 }

Modified: lucene/dev/branches/docvalues/solr/src/webapp/web/css/screen.css
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/webapp/web/css/screen.css?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/webapp/web/css/screen.css (original)
+++ lucene/dev/branches/docvalues/solr/src/webapp/web/css/screen.css Fri Jun  3 22:40:42 2011
@@ -462,6 +462,7 @@ ul
 
 #content #dashboard .block
 {
+    background-image: none;
     width: 49%;
 }
 
@@ -550,85 +551,13 @@ ul
     display: block;
 }
 
-#content #dashboard #replication.is-master .slave
+#content #dashboard #replication #details table thead td span
 {
     display: none;
 }
 
-#content #dashboard #replication table
-{
-    border-collapse: collapse;
-}
-
-#content #dashboard #replication table th,
-#content #dashboard #replication table td
-{
-    border: 1px solid #f0f0f0;
-    padding: 2px 5px;
-}
-
-#content #dashboard #replication table thead td
-{
-    border: 0;
-}
-
-#content #dashboard #replication table thead th,
-#content #dashboard #replication table tbody td
-{
-    border-right: 0;
-}
-
-#content #dashboard #replication table thead th
-{
-    border-top: 0;
-    font-weight: bold;
-}
-
-#content #dashboard #replication table tbody th,
-#content #dashboard #replication table tbody td
-{
-    border-bottom: 0;
-    text-align: right;
-}
-
-#content #dashboard #replication table tbody th
-{
-    border-left: 0;
-}
-
-#content #dashboard #replication table tbody th,
-#content #dashboard #replication dt
-{
-    width: 100px;
-}
-
-#content #dashboard #replication dl
-{
-    display: none;
-    margin-top: 10px;
-}
-
-#content #dashboard #replication dt,
-#content #dashboard #replication dd
-{
-    display: block;
-    padding-top: 1px;
-    padding-bottom: 1px;
-}
-
-#content #dashboard #replication dt
-{
-    border-right: 1px solid #f0f0f0;
-    float: left;
-    padding-left: 5px;
-    padding-right: 5px;
-    margin-right: 3px;
-    text-align: right;
-}
-
 #content #dashboard #dataimport
 {
-    background-color: #0ff;
     float: right;
 }
 
@@ -711,6 +640,19 @@ ul
     max-width: 99%;
 }
 
+#content #analysis #analysis-error
+{
+    background-color: #f00;
+    background-image: url( ../img/ico/construction.png );
+    background-position: 10px 50%;
+    color: #fff;
+    display: none;
+    font-weight: bold;
+    margin-bottom: 20px;
+    padding: 10px;
+    padding-left: 35px;
+}
+
 #content #analysis .analysis-result h2
 {
     position: relative;
@@ -1334,6 +1276,12 @@ ul
     padding-left: 10px;
 }
 
+#content #schema-browser #related #f-df-t
+{
+    border-bottom: 1px solid #f0f0f0;
+    padding-bottom: 15px;
+}
+
 #content #schema-browser #related dl
 {
     margin-top: 15px;
@@ -1367,7 +1315,9 @@ ul
 #content #schema-browser #related .dynamic-field .dynamic-field,
 #content #schema-browser #related .dynamic-field .dynamic-field a,
 #content #schema-browser #related .type .type,
-#content #schema-browser #related .type .type a
+#content #schema-browser #related .type .type a,
+#content #schema-browser #related .active,
+#content #schema-browser #related .active a
 {
     color: #333;
 }
@@ -1378,6 +1328,11 @@ ul
     color: #666;
 }
 
+#content #schema-browser #data
+{
+    display: none;
+}
+
 #content #schema-browser #data #index dt
 {
     display: none;
@@ -1491,6 +1446,7 @@ ul
 
 #content #schema-browser #data #field .topterms-holder
 {
+    display: none;
     float: left;
 }
 
@@ -2830,6 +2786,7 @@ ul
 #content #replication #details table tbody .size
 {
     text-align: right;
+    white-space: nowrap;
 }
 
 #content #replication #details table tbody .generation div

Modified: lucene/dev/branches/docvalues/solr/src/webapp/web/index.jsp
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/webapp/web/index.jsp?rev=1131275&r1=1131274&r2=1131275&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/webapp/web/index.jsp (original)
+++ lucene/dev/branches/docvalues/solr/src/webapp/web/index.jsp Fri Jun  3 22:40:42 2011
@@ -35,14 +35,14 @@
 
             <div id="wip-notice">
                 <p>This interface is work in progress. It works best in Chrome.</p>
-                <p><a href="admin/">Use the <span>old admin interface</span> if there are problems with this one.</a></p>
+                <p><a href="admin">Use the <span>old admin interface</span> if there are problems with this one.</a></p>
                 <p><a href="https://issues.apache.org/jira/browse/SOLR-2399">Bugs/Requests/Suggestions: <span>SOLR-2399</span></a></p>
             </div>
 
-	    <p id="environment">&nbsp;</p>
+            <p id="environment">&nbsp;</p>
 
         </div>
-        
+
         <div id="main" class="clearfix">
         
             <div id="content-wrapper">



Mime
View raw message