cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1397515 - /cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Date Fri, 12 Oct 2012 11:04:52 GMT
Author: sergeyb
Date: Fri Oct 12 11:04:51 2012
New Revision: 1397515

URL: http://svn.apache.org/viewvc?rev=1397515&view=rev
Log:
Adding an optional Lucene contents fields map

Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java?rev=1397515&r1=1397514&r2=1397515&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Fri Oct 12 11:04:51 2012
@@ -44,6 +44,7 @@ public class LuceneQueryVisitor<T> exten
 
     //private Analyzer analyzer;
     private String contentsFieldName;
+    private Map<String, String> contentsFieldMap;
     private Stack<List<Query>> queryStack = new Stack<List<Query>>();
     public LuceneQueryVisitor() {
         this(Collections.<String, String>emptyMap());
@@ -67,6 +68,10 @@ public class LuceneQueryVisitor<T> exten
         queryStack.push(new ArrayList<Query>());
     }
     
+    public void setContentsFieldMap(Map<String, String> map) {
+        this.contentsFieldMap = map;
+    }
+    
     public void visit(SearchCondition<T> sc) {
         PrimitiveStatement statement = sc.getStatement();
         if (statement != null) {
@@ -135,7 +140,8 @@ public class LuceneQueryVisitor<T> exten
             String strValue = value.toString();
             int wildCardIndex = strValue.indexOf('*'); 
             
-            if (contentsFieldName == null) {
+            String theContentsFieldName = getContentsFieldName(name);
+            if (theContentsFieldName == null) {
                 Term term = new Term(name, strValue);
                 
                 if (wildCardIndex == -1) {
@@ -145,14 +151,14 @@ public class LuceneQueryVisitor<T> exten
                 } 
             } else if (wildCardIndex == -1) {
                 PhraseQuery pquery = new PhraseQuery();
-                pquery.add(new Term(contentsFieldName, name));
-                pquery.add(new Term(contentsFieldName, strValue));
+                pquery.add(new Term(theContentsFieldName, name));
+                pquery.add(new Term(theContentsFieldName, strValue));
                 query = pquery;
             } else {
                 BooleanQuery pquery = new BooleanQuery();
-                pquery.add(new TermQuery(new Term(contentsFieldName, name)),
+                pquery.add(new TermQuery(new Term(theContentsFieldName, name)),
                            BooleanClause.Occur.MUST);
-                pquery.add(new WildcardQuery(new Term(contentsFieldName, strValue)),
+                pquery.add(new WildcardQuery(new Term(theContentsFieldName, strValue)),
                            BooleanClause.Occur.MUST);
                 query = pquery;                
             }
@@ -162,6 +168,17 @@ public class LuceneQueryVisitor<T> exten
         return query;
     }
     
+    private String getContentsFieldName(String name) {
+        String fieldName = null;
+        if (contentsFieldMap != null) {
+            fieldName = contentsFieldMap.get(name); 
+        }
+        if (fieldName == null) {
+            fieldName = contentsFieldName;
+        }
+        return fieldName;
+    }
+    
     private Query createRangeQuery(Class<?> cls, String name, Object value,
                                    ConditionType type) {
         if (String.class.isAssignableFrom(cls) || Number.class.isAssignableFrom(cls)) {



Mime
View raw message