You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2014/08/27 16:16:15 UTC
[1/2] git commit: CXF-5963: LuceneQueryVisitor should use analyzer to
create query properly. Added more LuceneQueryVisitor test cases.
Repository: cxf
Updated Branches:
refs/heads/master 481466c7a -> 41348da1b
CXF-5963: LuceneQueryVisitor should use analyzer to create query properly. Added more LuceneQueryVisitor test cases.
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/162bbb5e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/162bbb5e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/162bbb5e
Branch: refs/heads/master
Commit: 162bbb5ea63cfeb6c258d750627c77c9e694f928
Parents: af2f7d3
Author: reta <dr...@gmail.com>
Authored: Wed Aug 27 10:15:52 2014 -0400
Committer: reta <dr...@gmail.com>
Committed: Wed Aug 27 10:15:52 2014 -0400
----------------------------------------------------------------------
.../java/demo/jaxrs/search/server/Catalog.java | 33 +++++----
.../ext/search/lucene/LuceneQueryVisitor.java | 9 +++
.../lucene/AbstractLuceneQueryVisitorTest.java | 50 +++++++++++--
.../LuceneQueryVisitorAnalyzerFiqlTest.java | 77 ++++++++++++++++++++
4 files changed, 149 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/162bbb5e/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
index ea6e3c7..9de8b65 100644
--- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
+++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java
@@ -180,20 +180,25 @@ public class Catalog {
final LuceneQueryVisitor<SearchBean> visitor = createVisitor();
visitor.visit(searchContext.getCondition(SearchBean.class));
- final TopDocs topDocs = searcher.search(visitor.getQuery(), 1000);
- for (final ScoreDoc scoreDoc: topDocs.scoreDocs) {
- final Document document = reader.document(scoreDoc.doc);
- final String source = document.getField(LuceneDocumentMetadata.SOURCE_FIELD).stringValue();
-
- builder.add(
- Json.createObjectBuilder()
- .add("source", source)
- .add("score", scoreDoc.score)
- .add("url", uri.getBaseUriBuilder()
- .path(Catalog.class)
- .path(source)
- .build().toString())
- );
+ final Query query = visitor.getQuery();
+ if (query != null) {
+ final TopDocs topDocs = searcher.search(query, 1000);
+ for (final ScoreDoc scoreDoc: topDocs.scoreDocs) {
+ final Document document = reader.document(scoreDoc.doc);
+ final String source = document
+ .getField(LuceneDocumentMetadata.SOURCE_FIELD)
+ .stringValue();
+
+ builder.add(
+ Json.createObjectBuilder()
+ .add("source", source)
+ .add("score", scoreDoc.score)
+ .add("url", uri.getBaseUriBuilder()
+ .path(Catalog.class)
+ .path(source)
+ .build().toString())
+ );
+ }
}
return builder.build();
http://git-wip-us.apache.org/repos/asf/cxf/blob/162bbb5e/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
index f9bf620..ec4a9a5 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
@@ -58,6 +58,11 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T, Que
this(Collections.<String, String>emptyMap());
}
+ public LuceneQueryVisitor(Analyzer analyzer) {
+ this(Collections.<String, String>emptyMap(), null, analyzer);
+ }
+
+
public LuceneQueryVisitor(String contentsFieldAlias, String contentsFieldName) {
this(Collections.singletonMap(contentsFieldAlias, contentsFieldName));
}
@@ -65,6 +70,10 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T, Que
public LuceneQueryVisitor(String contentsFieldName) {
this(Collections.<String, String>emptyMap(), contentsFieldName);
}
+
+ public LuceneQueryVisitor(String contentsFieldName, Analyzer analyzer) {
+ this(Collections.<String, String>emptyMap(), contentsFieldName, analyzer);
+ }
public LuceneQueryVisitor(Map<String, String> fieldsMap) {
this(fieldsMap, null);
http://git-wip-us.apache.org/repos/asf/cxf/blob/162bbb5e/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/AbstractLuceneQueryVisitorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/AbstractLuceneQueryVisitorTest.java b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/AbstractLuceneQueryVisitorTest.java
index b6868b6..bc745d3 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/AbstractLuceneQueryVisitorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/AbstractLuceneQueryVisitorTest.java
@@ -80,8 +80,15 @@ public abstract class AbstractLuceneQueryVisitorTest extends Assert {
protected abstract SearchConditionParser<SearchBean> getParser();
protected void doTestTextContentMatch(String expression) throws Exception {
-
- Query query = createTermQuery("contents", expression);
+ doTestTextContentMatch(expression, false);
+ }
+
+ protected void doTestTextContentMatchWithAnalyzer(String expression) throws Exception {
+ doTestTextContentMatch(expression, true);
+ }
+
+ protected void doTestTextContentMatch(String expression, boolean useAnalyzer) throws Exception {
+ Query query = createTermQuery("contents", expression, useAnalyzer);
doTestTextContentMatchWithQuery(query);
}
@@ -123,24 +130,47 @@ public abstract class AbstractLuceneQueryVisitorTest extends Assert {
}
protected Query createTermQuery(String expression) throws Exception {
+ return createTermQuery(expression, false);
+ }
+
+ protected Query createTermQueryWithAnalyzer(String expression) throws Exception {
+ return createTermQuery(expression, true);
+ }
+
+ protected Query createTermQuery(String expression, boolean useAnalyzer) throws Exception {
SearchCondition<SearchBean> filter = getParser().parse(expression);
- SearchConditionVisitor<SearchBean, Query> lucene = new LuceneQueryVisitor<SearchBean>();
+ SearchConditionVisitor<SearchBean, Query> lucene =
+ new LuceneQueryVisitor<SearchBean>(useAnalyzer ? analyzer : null);
lucene.visit(filter);
return lucene.getQuery();
}
+ protected Query createTermQueryWithFieldClassWithAnalyzer(String expression, Class<?> cls) throws Exception {
+ return createTermQueryWithFieldClass(expression, cls, true);
+ }
+
protected Query createTermQueryWithFieldClass(String expression, Class<?> cls) throws Exception {
+ return createTermQueryWithFieldClass(expression, cls, false);
+ }
+
+ protected Query createTermQueryWithFieldClass(String expression, Class<?> cls,
+ boolean useAnalyzer) throws Exception {
SearchCondition<SearchBean> filter = getParser().parse(expression);
- LuceneQueryVisitor<SearchBean> lucene = new LuceneQueryVisitor<SearchBean>();
+ LuceneQueryVisitor<SearchBean> lucene =
+ new LuceneQueryVisitor<SearchBean>(useAnalyzer ? analyzer : null);
lucene.setPrimitiveFieldTypeMap(Collections.<String, Class<?>>singletonMap("intfield", cls));
lucene.visit(filter);
return lucene.getQuery();
}
protected Query createTermQuery(String fieldName, String expression) throws Exception {
+ return createTermQuery(fieldName, expression, false);
+ }
+
+ protected Query createTermQuery(String fieldName, String expression, boolean useAnalyzer) throws Exception {
SearchCondition<SearchBean> filter = getParser().parse(expression);
LuceneQueryVisitor<SearchBean> lucene =
- new LuceneQueryVisitor<SearchBean>("ct", fieldName);
+ new LuceneQueryVisitor<SearchBean>("ct", fieldName, useAnalyzer ? analyzer : null);
lucene.visit(filter);
return lucene.getQuery();
}
@@ -156,9 +186,17 @@ public abstract class AbstractLuceneQueryVisitorTest extends Assert {
}
protected Query createPhraseQuery(String fieldName, String expression) throws Exception {
+ return createPhraseQuery(fieldName, expression, false);
+ }
+
+ protected Query createPhraseQueryWithAnalyzer(String fieldName, String expression) throws Exception {
+ return createPhraseQuery(fieldName, expression, true);
+ }
+
+ protected Query createPhraseQuery(String fieldName, String expression, boolean useAnalyzer) throws Exception {
SearchCondition<SearchBean> filter = getParser().parse(expression);
LuceneQueryVisitor<SearchBean> lucene =
- new LuceneQueryVisitor<SearchBean>(fieldName);
+ new LuceneQueryVisitor<SearchBean>(fieldName, useAnalyzer ? analyzer : null);
lucene.visit(filter);
return lucene.getQuery();
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/162bbb5e/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorAnalyzerFiqlTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorAnalyzerFiqlTest.java b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorAnalyzerFiqlTest.java
new file mode 100644
index 0000000..f6b336e
--- /dev/null
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorAnalyzerFiqlTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.lucene;
+
+import org.apache.cxf.jaxrs.ext.search.SearchBean;
+import org.apache.cxf.jaxrs.ext.search.SearchConditionParser;
+import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
+import org.apache.lucene.search.Query;
+import org.junit.Test;
+
+public class LuceneQueryVisitorAnalyzerFiqlTest extends AbstractLuceneQueryVisitorTest {
+ @Test
+ public void testTextContentMatchEqual() throws Exception {
+ doTestTextContentMatchWithAnalyzer("ct==tEXt");
+ }
+
+ @Test
+ public void testTextContentMatchStopWord() throws Exception {
+ assertNull("No query should be returned for stop words", createTermQueryWithAnalyzer("ct==the"));
+ }
+
+ @Test
+ public void testTextAndContentMatch() throws Exception {
+ Query query = createTermQueryWithAnalyzer("contents==namE;contents==tExt");
+ doTestTextContentMatchWithQuery(query);
+
+ }
+
+ @Test
+ public void testTextOrContentMatch() throws Exception {
+ Query query = createTermQueryWithAnalyzer("contents==BAR,contents==TEXT");
+ doTestTextContentMatchWithQuery(query);
+
+ }
+
+ @Test
+ public void testIntAndTextContentMatch() throws Exception {
+ Query query = createTermQueryWithFieldClassWithAnalyzer("intfield==4;contents==teXt", Integer.class);
+ doTestIntContentMatchWithQuery(query);
+ doTestTextContentMatchWithQuery(query);
+ }
+
+ @Test
+ public void testIntOrTextContentMatch() throws Exception {
+ Query query = createTermQueryWithAnalyzer("intfield==3,contents==tExt");
+ doTestTextContentMatchWithQuery(query);
+ doTestIntContentMatchWithQuery(query);
+
+ }
+
+ @Test
+ public void testTextContentMatchEqualPhrase() throws Exception {
+ Query query = createPhraseQueryWithAnalyzer("contents", "name==TEXT");
+ doTestTextContentMatchWithQuery(query);
+ }
+
+ @Override
+ protected SearchConditionParser<SearchBean> getParser() {
+ return new FiqlParser<SearchBean>(SearchBean.class);
+ }
+}
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/cxf
Posted by re...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cxf
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/41348da1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/41348da1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/41348da1
Branch: refs/heads/master
Commit: 41348da1b88da56ae55c8c4181e6bb2507a52a3e
Parents: 162bbb5 481466c
Author: reta <dr...@gmail.com>
Authored: Wed Aug 27 10:15:58 2014 -0400
Committer: reta <dr...@gmail.com>
Committed: Wed Aug 27 10:15:58 2014 -0400
----------------------------------------------------------------------
.../cxf/jaxrs/model/wadl/WadlGenerator.java | 28 +++-
.../WebSocketVirtualServletRequest.java | 132 +++++++++----------
.../WebSocketVirtualServletResponse.java | 114 ++++++++--------
.../websocket/ahc/AhcWebSocketConduit.java | 8 +-
.../atmosphere/AtmosphereWebSocketHandler.java | 8 +-
.../AtmosphereWebSocketStreamHandler.java | 2 +-
.../websocket/jetty/JettyWebSocket.java | 10 +-
7 files changed, 160 insertions(+), 142 deletions(-)
----------------------------------------------------------------------