lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1573227 - in /lucene/dev/branches/lucene5376/lucene: server/src/java/org/apache/lucene/server/ server/src/java/org/apache/lucene/server/handlers/ server/src/test/org/apache/lucene/server/ suggest/src/java/org/apache/lucene/search/suggest/a...
Date Sat, 01 Mar 2014 21:01:08 GMT
Author: mikemccand
Date: Sat Mar  1 21:01:07 2014
New Revision: 1573227

URL: http://svn.apache.org/r1573227
Log:
LUCENE-5376: expose set/getCommitUserData

Added:
    lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/GetCommitUserDataHandler.java
  (with props)
    lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/SetCommitUserDataHandler.java
  (with props)
    lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestCommitUserData.java
  (with props)
Modified:
    lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/Server.java
    lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/BuildSuggestHandler.java
    lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java

Modified: lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/Server.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/Server.java?rev=1573227&r1=1573226&r2=1573227&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/Server.java
(original)
+++ lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/Server.java
Sat Mar  1 21:01:07 2014
@@ -644,6 +644,8 @@ public class Server {
       globalState.addHandler("suggestLookup", new SuggestLookupHandler(globalState));
       globalState.addHandler("updateSuggest", new UpdateSuggestHandler(globalState));
       globalState.addHandler("updateDocument", new UpdateDocumentHandler(globalState));
+      globalState.addHandler("setCommitUserData", new SetCommitUserDataHandler(globalState));
+      globalState.addHandler("getCommitUserData", new GetCommitUserDataHandler(globalState));
 
       globalState.loadPlugins();
 

Modified: lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/BuildSuggestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/BuildSuggestHandler.java?rev=1573227&r1=1573226&r2=1573227&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/BuildSuggestHandler.java
(original)
+++ lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/BuildSuggestHandler.java
Sat Mar  1 21:01:07 2014
@@ -96,7 +96,7 @@ public class BuildSuggestHandler extends
         new Param("source", "Where to get suggestions from",
             new StructType(
                   new Param("localFile", "Local file (to the server) to read suggestions
+ weights from; format is weight U+001F suggestion U+001F payload, one per line, with suggestion
UTF-8 encoded.  If this option is used then searcher, suggestField, weightField/Expression,
payloadField should not be specified.", new StringType()),
-                  new Param("searcher", "Specific searcher version to use for searching.
 There are three different ways to specify a searcher version.",
+                  new Param("searcher", "Specific searcher version to use for pull suggestions
to build.  There are three different ways to specify a searcher version.",
                             SearchHandler.SEARCHER_VERSION_TYPE),
                   new Param("suggestField", "Field (from stored documents) containing the
suggestion text", new StringType()),
                   new Param("weightField", "Numeric field (from stored documents) containing
the weight", new StringType()),

Added: lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/GetCommitUserDataHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/GetCommitUserDataHandler.java?rev=1573227&view=auto
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/GetCommitUserDataHandler.java
(added)
+++ lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/GetCommitUserDataHandler.java
Sat Mar  1 21:01:07 2014
@@ -0,0 +1,95 @@
+package org.apache.lucene.server.handlers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexCommit;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.server.FinishRequest;
+import org.apache.lucene.server.GlobalState;
+import org.apache.lucene.server.IndexState;
+import org.apache.lucene.server.params.*;
+import net.minidev.json.JSONObject;
+
+/** Handles {@code getCommitUserData}. */
+public class GetCommitUserDataHandler extends Handler {
+
+  private static StructType TYPE = new StructType(
+                                       new Param("indexName", "Index name", new StringType()),
+                                       new Param("searcher", "Specific searcher version to
use for retrieving the commit userData; if this is missing, the current IndexWriter's commitData
is returned.",
+                                                 SearchHandler.SEARCHER_VERSION_TYPE));
+
+  /** Sole constructor. */
+  public GetCommitUserDataHandler(GlobalState state) {
+    super(state);
+  }
+
+  @Override
+  public StructType getType() {
+    return TYPE;
+  }
+
+  @Override
+  public String getTopDoc() {
+    return "Gets the custom user data in the index, previously set with setCommitUserData.";
+  }
+  
+  @Override
+  public FinishRequest handle(final IndexState state, final Request r, Map<String,List<String>>
params) throws Exception {
+
+    return new FinishRequest() {
+      @Override
+      public String finish() throws IOException, InterruptedException {
+        long searcherVersion;
+        Map<String,String> userData;
+        if (r.hasParam("searcher")) {
+          // Specific searcher version:
+          SearcherAndTaxonomy s = SearchHandler.getSearcherAndTaxonomy(r, state, null);
+          try {
+            DirectoryReader dr = (DirectoryReader) s.searcher.getIndexReader();
+            searcherVersion = dr.getVersion();
+            IndexCommit commit = dr.getIndexCommit();
+            userData = commit.getUserData();
+          } finally {
+            state.manager.release(s);
+          }
+
+        } else {
+          // Just use current IndexWriter:
+          searcherVersion = -1;
+          state.verifyStarted(r);
+          userData = state.writer.getIndexWriter().getCommitData();
+        }
+
+        JSONObject result = new JSONObject();
+        result.put("searcher", searcherVersion);
+        JSONObject data = new JSONObject();
+        result.put("userData", data);
+        for(Map.Entry<String,String> ent : userData.entrySet()) {
+          data.put(ent.getKey(), ent.getValue());
+        }
+        return data.toString();
+      }
+    };
+  }
+}

Added: lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/SetCommitUserDataHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/SetCommitUserDataHandler.java?rev=1573227&view=auto
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/SetCommitUserDataHandler.java
(added)
+++ lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/handlers/SetCommitUserDataHandler.java
Sat Mar  1 21:01:07 2014
@@ -0,0 +1,72 @@
+package org.apache.lucene.server.handlers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.server.FinishRequest;
+import org.apache.lucene.server.GlobalState;
+import org.apache.lucene.server.IndexState;
+import org.apache.lucene.server.params.*;
+import net.minidev.json.JSONObject;
+
+/** Handles {@code setCommitUserData}. */
+public class SetCommitUserDataHandler extends Handler {
+
+  private static StructType TYPE = new StructType(
+                                                  new Param("indexName", "Index name", new
StringType()),
+                                                  new Param("userData", "Custom Map<String,String>",
new AnyType()));
+
+  /** Sole constructor. */
+  public SetCommitUserDataHandler(GlobalState state) {
+    super(state);
+  }
+
+  @Override
+  public StructType getType() {
+    return TYPE;
+  }
+
+  @Override
+  public String getTopDoc() {
+    return "Sets custom user data in the index, later retrieved with getCommitUserData.";
+  }
+  
+  @Override
+  public FinishRequest handle(final IndexState state, Request r, Map<String,List<String>>
params) throws Exception {
+
+    final Map<String,String> userData = new HashMap<String,String>();
+    for(Map.Entry<String,Object> ent : ((JSONObject) r.getAndRemoveRaw("userData")).entrySet())
{
+      if (ent.getValue() instanceof String == false) {
+        r.failWrongClass("userData", "all values must be String ", ent.getValue());
+      }
+      userData.put(ent.getKey(), (String) ent.getValue());
+    }
+
+    return new FinishRequest() {
+      @Override
+      public String finish() throws IOException {
+        state.writer.getIndexWriter().setCommitData(userData);
+        return "{}";
+      }
+    };
+  }
+}

Added: lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestCommitUserData.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestCommitUserData.java?rev=1573227&view=auto
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestCommitUserData.java
(added)
+++ lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestCommitUserData.java
Sat Mar  1 21:01:07 2014
@@ -0,0 +1,51 @@
+package org.apache.lucene.server;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class TestCommitUserData extends ServerBaseTestCase {
+  @BeforeClass
+  public static void initClass() throws Exception {
+    useDefaultIndex = true;
+    curIndexName = "index";
+    startServer();
+    createAndStartIndex();
+  }
+
+  @AfterClass
+  public static void fini() throws Exception {
+    shutdownServer();
+  }
+
+  /** Make sure we can set commit data even when there are
+   *  not docs */
+  public void testEmpty() throws Exception {
+    send("setCommitUserData", "{userData: {a: c, b: d}}");
+    send("getCommitUserData");
+    assertEquals("c", getString("a"));
+    assertEquals("d", getString("b"));
+    shutdownServer();
+    startServer();
+    send("startIndex");
+    send("getCommitUserData");
+    assertEquals("c", getString("a"));
+    assertEquals("d", getString("b"));
+  }
+}

Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java?rev=1573227&r1=1573226&r2=1573227&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
(original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
Sat Mar  1 21:01:07 2014
@@ -195,7 +195,6 @@ public class AnalyzingInfixSuggester ext
 
   @Override
   public void build(InputIterator iter) throws IOException {
-
     if (searcherMgr != null) {
       searcherMgr.close();
       searcherMgr = null;
@@ -273,6 +272,7 @@ public class AnalyzingInfixSuggester ext
       writer = new IndexWriter(dir,
                                getIndexWriterConfig(matchVersion, getGramAnalyzer(), sorter,
IndexWriterConfig.OpenMode.CREATE));
       writer.addIndexes(new IndexReader[] {r});
+      writer.commit();
       r.close();
 
       //System.out.println("sort time: " + ((System.nanoTime()-t1)/1000000) + " msec");



Mime
View raw message