You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2009/10/28 07:38:35 UTC
svn commit: r830448 - in /tuscany/branches/sca-java-1.x/modules:
domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/
domain-manager/src/main/resources/
domain-search/src/main/java/org/apache/tuscany/sca/domain/search/
domain-search...
Author: adrianocrestani
Date: Wed Oct 28 06:38:34 2009
New Revision: 830448
URL: http://svn.apache.org/viewvc?rev=830448&view=rev
Log:
applying patch tuscany_2552_phillipe_ramalho_09_30_2009.patch from TUSCANY-2552
Added:
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java (with props)
Removed:
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java
Modified:
tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java
tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java
tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java
tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
Modified: tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java Wed Oct 28 06:38:34 2009
@@ -75,6 +75,7 @@
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.apache.tuscany.sca.domain.manager.impl.ContributionCollectionImpl.Cache.ContributionCache;
import org.apache.tuscany.sca.domain.search.DomainSearch;
+import org.apache.tuscany.sca.domain.search.IndexException;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
@@ -225,7 +226,14 @@
// add it to the search index, contributionUpdated is called to guarantee
// only one contribution with the same URI in the index
if (domainSearch != null) { // can be null in unit tests
- domainSearch.contributionUpdated(contribution, contribution);
+
+ try {
+ domainSearch.updateContribution(contribution, contribution);
+
+ } catch (IndexException e) {
+ logger.warning("Could not update contribution on index: " + contribution.getURI());
+ }
+
}
return key;
@@ -274,7 +282,13 @@
// delete it from the search index
if (domainSearch != null) { // can be null in unit tests
- domainSearch.contributionRemoved(contribution);
+
+ try {
+ domainSearch.removeContribution(contribution);
+ } catch (IndexException e) {
+ logger.warning("Could not remove contribution from index: " + contribution.getURI());
+ }
+
}
return;
Modified: tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java Wed Oct 28 06:38:34 2009
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
Modified: tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java Wed Oct 28 06:38:34 2009
@@ -39,7 +39,6 @@
import org.apache.tuscany.sca.data.collection.ItemCollection;
import org.apache.tuscany.sca.data.collection.LocalItemCollection;
import org.apache.tuscany.sca.data.collection.NotFoundException;
-import org.apache.tuscany.sca.domain.search.DomainSearch;
import org.osoa.sca.ServiceRuntimeException;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
Modified: tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java Wed Oct 28 06:38:34 2009
@@ -17,6 +17,7 @@
import org.apache.tuscany.sca.data.collection.LocalItemCollection;
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.apache.tuscany.sca.domain.search.DomainSearch;
+import org.apache.tuscany.sca.domain.search.IndexException;
import org.apache.tuscany.sca.domain.search.Result;
import org.apache.tuscany.sca.domain.search.impl.DomainSearchFormatter;
import org.apache.tuscany.sca.domain.search.impl.HighlightingUtil;
@@ -52,7 +53,7 @@
private int elementCounter;
public void delete(String key) throws NotFoundException {
- System.out.println("delete");
+
}
private static void startIndentation(int size, StringWriter writer) {
@@ -159,7 +160,13 @@
for (Contribution contribution : contributions) {
if (!contribution.getURI().equals(DomainManagerUtil.DEPLOYMENT_CONTRIBUTION_URI)) {
- this.domainSearch.contributionUpdated(contribution, contribution);
+
+ try {
+ this.domainSearch.updateContribution(contribution, contribution);
+ } catch (IndexException e) {
+
+ }
+
}
}
}
@@ -194,7 +201,7 @@
item.setContents("No results match: <u>" + query + "</u>");
}
- System.out.println(item.getContents());
+ // System.out.println(item.getContents());
return item;
@@ -234,16 +241,6 @@
}
}
- //
- // System.out.println("set-size: " + set.size());
- // for (char character : set) {
- // System.out.print(",");
- // System.out.print((int) character);
- // System.out.print("/*" + character + "*/");
- //
- // }
- //
- // System.out.println();
return sb.toString();
Modified: tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite Wed Oct 28 06:38:34 2009
@@ -310,7 +310,7 @@
<component name="DomainSearchComponent">
<implementation.java class="org.apache.tuscany.sca.domain.search.impl.DomainSearchImpl"/>
- <!--<property name="indexDirectoryPath">domainSearchIndex</property> -->
+ <property name="indexDirectoryPath">domainSearchIndex</property>
</component>
</composite>
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java Wed Oct 28 06:38:34 2009
@@ -23,6 +23,11 @@
import org.apache.tuscany.sca.domain.search.impl.Document;
/**
+ * A map that holds a collection of {@link Document}s. Each {@link Document} key
+ * should ideally be something that is unique across the entire contribution
+ * documents. This class overrides {@link HashMap#get(Object)} method, so it
+ * adds an empty {@link Document} object if the specified key is not found in
+ * the map.
*
* @version $Rev$ $Date$
*/
@@ -30,6 +35,14 @@
private static final long serialVersionUID = -2402910290314939928L;
+ /**
+ * Returns a {@link Document} object mapped from the specified key. If no
+ * {@link Document} object is found from the specified key, a empty
+ * {@link Document} object is created and added to the map.
+ *
+ * @param key the {@link Document} key
+ * @return the {@link Document} object mapped from the key
+ */
@Override
public Document get(Object key) {
Document doc = super.get(key);
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java Wed Oct 28 06:38:34 2009
@@ -21,6 +21,9 @@
import org.apache.tuscany.sca.domain.search.impl.Document;
/**
+ * A {@link DocumentProcessor} implementations knows how to extract data from a
+ * contribution {@link Object}. The extract data is added to a {@link Document},
+ * which is stored in a {@link DocumentMap}.
*
* @version $Rev$ $Date$
*/
@@ -28,12 +31,34 @@
final public static Document FAKE_DOCUMENT = new Document();
+ /**
+ * Process a contribution {@link Object}, extracting from it data that
+ * should be indexed. The data should be add to a {@link Document} object,
+ * which can be found accessing the {@link DocumentMap} if it's not passed
+ * as an argument. The key used to find the {@link Document} object should
+ * be the one returned by {@link #getDocumentKey(Object)} method.
+ *
+ * @param parentProcessor the processor that invoked this processor, if any
+ * @param documents the {@link DocumentMap} object
+ * @param object the object where data should be extracted from
+ * @param document the {@link Document} object to store the extracted data
+ * @param parent string that represent the object's parent path in the
+ * contribution
+ * @return the resulted {@link Document} object
+ */
Document process(DocumentProcessor parentProcessor,
DocumentMap documents,
Object object,
Document document,
String parent);
+ /**
+ * Returns a object key generated from object passed as argument. The key
+ * should be unique in a contribution.
+ *
+ * @param object the object
+ * @return a key generated from the object
+ */
Object getDocumentKey(Object object);
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java Wed Oct 28 06:38:34 2009
@@ -19,129 +19,86 @@
package org.apache.tuscany.sca.domain.search;
import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import org.apache.tuscany.sca.domain.search.impl.Document;
+
/**
+ * This class is a {@link DocumentProcessor} that holds a map from {@link Class}
+ * -> {@link DocumentProcessor}, and based on this map this processor delegates
+ * the object to be processed to its respective {@link DocumentProcessor}.
*
* @version $Rev$ $Date$
*/
-public class DocumentProcessorsMap extends
- HashMap<Class<?>, List<DocumentProcessor>> implements DocumentProcessor {
+public class DocumentProcessorsMap extends HashMap<Class<?>, DocumentProcessor> implements DocumentProcessor {
private static final long serialVersionUID = 3967390896890947159L;
- private Object documentKey;
-
- public void addDocumentProcessor(Class<?> clazz, DocumentProcessor processor) {
- List<DocumentProcessor> processors = get(clazz);
-
- if (processors == null) {
- processors = new LinkedList<DocumentProcessor>();
- put(clazz, processors);
-
- }
-
- processors.add(processor);
-
- }
-
- private void appendProcessors(LinkedList<DocumentProcessor> processorsList,
- List<DocumentProcessor> processors,
- Object object) {
-
- if (processors != null) {
-
- for (DocumentProcessor processor : processors) {
-
- if (this.documentKey == null) {
- this.documentKey = processor.getDocumentKey(object);
-
- if (processorsList == null) {
- return;
- }
-
- }
-
- if (processorsList != null) {
- processorsList.add(processor);
- }
-
- }
-
- }
-
- }
-
- private void findAllDocumentProcessors(LinkedList<DocumentProcessor> processorsList, Object object) {
- Class<?> clazz = object.getClass();
- appendProcessors(processorsList, get(clazz), object);
+ private DocumentProcessor findDocumentProcessor(Object object, Class<?> clazz) {
+ DocumentProcessor processor = get(clazz);
- while (clazz != null) {
+ if (processor == null) {
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> interfac : interfaces) {
- Class<?>[] interfaces2 = interfac.getInterfaces();
- appendProcessors(processorsList, get(interfac), object);
+ processor = findDocumentProcessor(object, interfac);
- for (Class<?> interface2 : interfaces2) {
- appendProcessors(processorsList, get(interface2), object);
+ if (processor != null) {
+ return processor;
}
}
- clazz = clazz.getSuperclass();
- appendProcessors(processorsList, get(clazz), object);
+ if (!clazz.isInterface()) {
+ return findDocumentProcessor(object, clazz.getSuperclass());
+ }
}
+ return processor;
+
}
+ /**
+ * @see DocumentProcessor#getDocumentKey(Object)
+ */
public Document process(DocumentProcessor parentProcessor,
DocumentMap documents,
Object object,
Document document,
String parent) {
- LinkedList<DocumentProcessor> processorsList;
-
- try {
-
- this.documentKey = document;
- processorsList = new LinkedList<DocumentProcessor>();
- findAllDocumentProcessors(processorsList, object);
+ DocumentProcessor processor = findDocumentProcessor(object, object.getClass());
- if (document == null && this.documentKey != null) {
- document = documents.get(this.documentKey);
+ if (processor == null) {
+ throw new IllegalArgumentException();
+ }
- if (document == null) {
- document = FAKE_DOCUMENT;
- }
+ if (document == null) {
+ document = documents.get(processor.getDocumentKey(object));
+ if (document == null) {
+ document = FAKE_DOCUMENT;
}
- } finally {
- this.documentKey = null;
}
- for (DocumentProcessor processor : processorsList) {
- processor.process(parentProcessor, documents, object, document, parent);
- }
+ processor.process(parentProcessor, documents, object, document, parent);
return document;
}
+ /**
+ * @see DocumentProcessor#getDocumentKey(Object)
+ */
public Object getDocumentKey(Object object) {
+ DocumentProcessor processor = findDocumentProcessor(object, object.getClass());
- try {
- findAllDocumentProcessors(null, object);
-
- return this.documentKey;
+ if (processor != null) {
+ return processor.getDocumentKey(object);
- } finally {
- this.documentKey = null;
+ } else {
+ return null;
}
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java Wed Oct 28 06:38:34 2009
@@ -18,48 +18,91 @@
*/
package org.apache.tuscany.sca.domain.search;
+import java.io.IOException;
+
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
import org.apache.tuscany.sca.contribution.Contribution;
import org.osoa.sca.annotations.Remotable;
/**
+ * This is the interface that must be implemented by the service that provides
+ * the functionality index/search and search contribution data.
*
* @version $Rev$ $Date$
*/
@Remotable
public interface DomainSearch {
+ /**
+ * Returns <code>true</code> if the index is somehow created already, otherwise <code>false</code>.
+ *
+ * @return <code>true</code> if the index is somehow created already, otherwise <code>false</code>
+ */
boolean indexExists();
- Result[] parseAndSearch(String searchQuery, boolean highlight) throws Exception;
+ /**
+ * Parse a query string, execute it against the index and return the results.
+ *
+ * @param searchQuery the string containing the search query
+ * @param highlight <code>true</code> if the results should be highlighted
+ *
+ * @return an array containing the search results
+ *
+ * @throws CorruptIndexException
+ * @throws IOException
+ * @throws ParseException
+ */
+ Result[] parseAndSearch(String searchQuery, boolean highlight) throws IndexException, ParseException;
- Result[] search(Query searchQuery, boolean hightlight) throws Exception;
+ /**
+ * Executes a search query against the index and return the results.
+ *
+ * @param searchQuery the search query
+ * @param hightlight highlight <code>true</code> if the results should be highlighted
+ *
+ * @return an array containing the search results
+ *
+ * @throws CorruptIndexException
+ * @throws IOException
+ */
+ Result[] search(Query searchQuery, boolean hightlight) throws IndexException;
- String highlight(String field, String text, String searchQuery) throws Exception;
+ /**
+ * Highlights in the specified text strings that matches the specified search query. The matches can be filtered by field.
+ *
+ * @param field the field to filter
+ * @param text the text to be highlighted
+ * @param searchQuery the search query
+ *
+ * @return the text highlighted
+ *
+ * @throws ParseException
+ * @throws IOException
+ */
+ String highlight(String field, String text, String searchQuery) throws ParseException;
/**
- * Notifies the listener that a contribution has been added.
+ * Adds a contribution to the index.
*
- * @param repository The contribution repository
- * @param contribution The new contribution
+ * @param contribution the contribution to be added
*/
- void contributionAdded(Contribution contribution);
+ void addContribution(Contribution contribution) throws IndexException;
/**
- * Notifies the listener that a contribution has been removed.
+ * Removes a contribution from the index.
*
- * @param repository The contribution repository
- * @param contribution The removed contribution.
+ * @param contribution the contribution to be removed
*/
- void contributionRemoved(Contribution contribution);
+ void removeContribution(Contribution contribution) throws IndexException;
/**
- * Notifies the listener that a contribution has been updated.
+ * Updates a contribution in the index.
*
- * @param repository The contribution repository
- * @param oldContribution The old contribution
- * @param contribution The new contribution
+ * @param oldContribution the old contribution state
+ * @param contribution the new contribution state
*/
- void contributionUpdated(Contribution oldContribution, Contribution contribution);
+ void updateContribution(Contribution oldContribution, Contribution contribution) throws IndexException;
}
Added: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java?rev=830448&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java (added)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java Wed Oct 28 06:38:34 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.domain.search;
+
+/**
+ * Exception thrown when a exception occurs while accessing the index.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IndexException extends Exception {
+
+ private static final long serialVersionUID = -6395734136706805723L;
+
+ /**
+ * @see Exception#Exception(String)
+ */
+ public IndexException(String message) {
+ super(message);
+ }
+
+ /**
+ * @see Exception#Exception(String,Throwable)
+ */
+ public IndexException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Propchange: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java Wed Oct 28 06:38:34 2009
@@ -22,27 +22,100 @@
import java.util.Map;
/**
+ * <p>
+ * The object that implements this interface carries a search's result data.
+ * </p>
+ * <p>
+ * A result contains a value, which is the value displayed to the user. It also
+ * contains a field name, which is the field the value is related to.
+ * </p>
+ * <p>
+ * A search result may be split into different {@link Result} objects, each one
+ * contained inside other, representing a complex result hierarchy. For example:
+ * a result structure may represent as result a folder and files/folders
+ * contained in it.
+ * </p>
+ *
+ * @see ResultProcessor
+ * @see ResultFactory
*
* @version $Rev$ $Date$
*/
public interface Result extends Serializable {
+ /**
+ * Returns the value held by this object.
+ *
+ * @return the value held by this object
+ */
String getValue();
+ /**
+ * Sets the result value.
+ *
+ * @param value the result value
+ */
void setValue(String value);
+ /**
+ * Returns the {@link Result} object that contains this object or
+ * <code>null</code> if it's not contained in any object.
+ *
+ * @return the {@link Result} object that contains this object or
+ * <code>null</code> if it's not contained in any object
+ */
Result getContainer();
+ /**
+ * A {@link Map} containing {@link Result} objects contained in this
+ * {@link Object}. The contents are mapped from a key, which may be any kind
+ * of identifier, the identifier is chosen by the {@link Result}
+ * implementation.
+ *
+ * @return the contents map
+ */
Map<String, Result> getContents();
+ /**
+ * Adds a {@link Result} content to this result.
+ *
+ * @param artifactResult the {@link Result} content
+ * @throw {@link UnsupportedOperationException} if the {@link Result}
+ * implementations does not support this operation
+ * @see #getContents()
+ */
void addContent(Result artifactResult);
+ /**
+ * Removes a {@link Result} content from this result.
+ *
+ * @param artifactResult the {@link Result} content
+ * @throw {@link UnsupportedOperationException} if the {@link Result}
+ * implementations does not support this operation
+ * @see #getContents()
+ */
void removeContent(Result artifactResult);
+ /**
+ * Sets this object's container.
+ *
+ * @param container the object's container
+ * @see #getContainer()
+ */
void setContainer(Result container);
+ /**
+ * Returns the field related to the result's value.
+ *
+ * @return the field name
+ */
String getField();
+ /**
+ * Sets the field related to the result's value.
+ *
+ * @param field the field name
+ */
void setField(String field);
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java Wed Oct 28 06:38:34 2009
@@ -21,13 +21,31 @@
import org.apache.lucene.document.Document;
/**
+ * This interface should be implemented to provide a way to create
+ * {@link Result} objects from a field name and its value or a {@link Document}
+ * resulted from a search.
*
+ * @see Result
* @version $Rev$ $Date$
*/
public interface ResultFactory<T extends Result> {
+ /**
+ * Creates a {@link Result} instance from a field name and its value.
+ *
+ * @param field the field name
+ * @param value the value
+ * @return the {@link Result} instance
+ */
T createResult(String field, String value);
+ /**
+ * Creates a {@link Result} instance from a {@link Document} object resulted
+ * from a search.
+ *
+ * @param document the result {@link Document}
+ * @return the {@link Result} instance
+ */
T createResult(Document document);
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java Wed Oct 28 06:38:34 2009
@@ -21,11 +21,30 @@
import org.apache.lucene.document.Document;
/**
+ * This interface should be implemented by classes that process a
+ * {@link Document} object resulted from a search and create a {@link Result}
+ * object from it.
*
* @version $Rev$ $Date$
*/
public interface ResultProcessor {
+ /**
+ * <p>
+ * Process the {@link Document} object and returns a {@link Result} object
+ * containing the processed data.
+ * </p>
+ * <p>
+ * A {@link Result} object may be specified to hold the processed data. If
+ * no object is specified, the implementation must create a new object a
+ * return it.
+ * </p>
+ *
+ * @param document the {@link Document} object resulted from a search
+ * @param result the {@link Result} object that will hold the processed data
+ * or <code>null</code> a new object should be returned.
+ * @return a {@link Result} object containing the processed data
+ */
Result process(Document document, Result result);
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java Wed Oct 28 06:38:34 2009
@@ -28,107 +28,80 @@
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
/**
- *
* @version $Rev$ $Date$
*/
public class ArtifactDocumentProcessor implements DocumentProcessor {
- public Document process(DocumentProcessor parentProcessor,
- DocumentMap documents, Object object, Document document,
- String parent) {
+ public Document process(DocumentProcessor parentProcessor,
+ DocumentMap documents,
+ Object object,
+ Document document,
+ String parent) {
- if (object instanceof Artifact) {
- Artifact artifact = (Artifact) object;
- // String uri = artifact.getURI();
+ if (object instanceof Artifact) {
+ Artifact artifact = (Artifact)object;
- // if (uri != null && uri.length() == 0) {
- // uri = null;
- // }
- //
- // if (uri != null) {
- //
- // if (uri.endsWith(".composite")
- // || uri.endsWith(".component")) {
- //
- // parent += DomainPathAnalyzer.PATH_SEPARATOR
- // + SearchFields.ARTIFACT_FIELD
- // + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
- //
- // if (document == null) {
- // document = documents.get(uri);
- // }
- //
- // document.add(new Field(SearchFields.ARTIFACT_FIELD, uri,
- // Field.Store.YES, Field.Index.ANALYZED));
- //
- // }
- //
- // }
+ if (!(object instanceof Contribution)) {
- if (!(object instanceof Contribution)) {
+ String location = artifact.getLocation();
- String location = artifact.getLocation();
+ try {
- try {
+ if (document == null) {
+ document = documents.get(SearchFields.ARTIFACT_FIELD + location);
+ }
- if (document == null) {
- document = documents.get(SearchFields.ARTIFACT_FIELD + location);
- }
+ FileContent fileContent = new WrappedFileContent(new URL(location));
- FileContent fileContent = new WrappedFileContent(new URL(
- location));
+ document.add(new Field(SearchFields.ARTIFACT_FIELD, fileContent.getName(), Field.Store.YES,
+ Field.Index.ANALYZED));
- document.add(new Field(SearchFields.ARTIFACT_FIELD,
- fileContent.getName(), Field.Store.YES,
- Field.Index.ANALYZED));
+ parent +=
+ DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR
+ + location
+ + DomainPathAnalyzer.URI_SEPARATOR
+ + fileContent.getName();
- parent += DomainPathAnalyzer.PATH_SEPARATOR
- + SearchFields.ARTIFACT_FIELD
- + DomainPathAnalyzer.TYPE_SEPARATOR
- + location + DomainPathAnalyzer.URI_SEPARATOR
- + fileContent.getName();
+ // parent += DomainPathAnalyzer.PATH_SEPARATOR
+ // + SearchFields.FILE_FIELD
+ // + DomainPathAnalyzer.TYPE_SEPARATOR + location +
+ // DomainPathAnalyzer.URI_SEPARATOR + fileContent.getName();
- // parent += DomainPathAnalyzer.PATH_SEPARATOR
- // + SearchFields.FILE_FIELD
- // + DomainPathAnalyzer.TYPE_SEPARATOR + location +
- // DomainPathAnalyzer.URI_SEPARATOR + fileContent.getName();
+ Document fileDoc = parentProcessor.process(parentProcessor, documents, fileContent, null, parent);
- Document fileDoc = parentProcessor.process(parentProcessor,
- documents, fileContent, null, parent);
+ fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED));
- fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
+ } catch (IOException e) {
+ // ignore location
+ }
- } catch (IOException e) {
- // ignore location
- }
+ }
- }
+ return document == null ? FAKE_DOCUMENT : document;
- return document == null ? FAKE_DOCUMENT : document;
+ }
- }
+ throw new IllegalArgumentException();
- throw new IllegalArgumentException();
+ }
- }
+ public Object getDocumentKey(Object obj) {
- public Object getDocumentKey(Object obj) {
+ if (obj instanceof Artifact) {
+ Artifact artifact = (Artifact)obj;
+ String uri = artifact.getLocation();
- if (obj instanceof Artifact) {
- Artifact artifact = (Artifact) obj;
- String uri = artifact.getLocation();
+ if (uri != null && uri.length() == 0) {
+ return null;
+ }
- if (uri != null && uri.length() == 0) {
- return null;
- }
+ return SearchFields.ARTIFACT_FIELD + uri;
- return SearchFields.ARTIFACT_FIELD + uri;
+ }
- }
+ throw new IllegalArgumentException();
- throw new IllegalArgumentException();
-
- }
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java Wed Oct 28 06:38:34 2009
@@ -28,7 +28,6 @@
import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap;
/**
- *
* @version $Rev$ $Date$
*/
public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap {
@@ -36,15 +35,15 @@
private static final long serialVersionUID = -4651637686945322606L;
public DomainSearchDocumentProcessorsMap() {
- addDocumentProcessor(Contribution.class, new ContributionDocumentProcessor());
- addDocumentProcessor(Artifact.class, new ArtifactDocumentProcessor());
- addDocumentProcessor(Property.class, new PropertyDocumentProcessor());
- addDocumentProcessor(ComponentType.class, new ComponentTypeDocumentProcessor());
- addDocumentProcessor(Binding.class, new BindingDocumentProcessor());
- addDocumentProcessor(Component.class, new ComponentDocumentProcessor());
- addDocumentProcessor(Composite.class, new CompositeDocumentProcessor());
- addDocumentProcessor(FileContent.class, new DomainSearchFileDocumentProcessor());
- addDocumentProcessor(Property.class, new PropertyDocumentProcessor());
+ put(Contribution.class, new ContributionDocumentProcessor());
+ put(Artifact.class, new ArtifactDocumentProcessor());
+ put(Property.class, new PropertyDocumentProcessor());
+ put(ComponentType.class, new ComponentTypeDocumentProcessor());
+ put(Binding.class, new BindingDocumentProcessor());
+ put(Component.class, new ComponentDocumentProcessor());
+ put(Composite.class, new CompositeDocumentProcessor());
+ put(FileContent.class, new DomainSearchFileDocumentProcessor());
+ put(Property.class, new PropertyDocumentProcessor());
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java Wed Oct 28 06:38:34 2009
@@ -19,7 +19,6 @@
package org.apache.tuscany.sca.domain.search.impl;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
@@ -40,13 +39,13 @@
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DomainSearch;
+import org.apache.tuscany.sca.domain.search.IndexException;
import org.apache.tuscany.sca.domain.search.Result;
import org.osoa.sca.annotations.AllowsPassByReference;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
/**
- *
* @version $Rev$ $Date$
*/
@Scope("COMPOSITE")
@@ -75,7 +74,6 @@
public DomainSearchImpl() {
this.qp.setAllowLeadingWildcard(true);
-
}
private Directory getIndexDirectory() throws IOException {
@@ -108,7 +106,7 @@
}
@AllowsPassByReference
- public void contributionAdded(Contribution contribution) {
+ public void addContribution(Contribution contribution) throws IndexException {
IndexWriter indexWriter = null;
@@ -132,7 +130,7 @@
}
- throw new RuntimeException("Problem while indexing!", e);
+ throw new IndexException(e.getMessage(), e);
} finally {
@@ -152,7 +150,7 @@
}
@AllowsPassByReference
- public void contributionRemoved(Contribution contribution) {
+ public void removeContribution(Contribution contribution) throws IndexException {
IndexWriter indexWriter = null;
@@ -178,7 +176,7 @@
}
- throw new RuntimeException("Problem while indexing!", e);
+ throw new IndexException(e.getMessage(), e);
} finally {
@@ -199,8 +197,7 @@
}
- private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException,
- IOException {
+ private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws IndexException {
String contributionURI = contribution.getURI();
StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD);
@@ -218,14 +215,18 @@
indexWriter.deleteDocuments(query);
} catch (ParseException e) {
- throw new RuntimeException("Could not parse query: " + sb.toString(), e);
+ // ignore exception
+
+ } catch (CorruptIndexException ex) {
+ throw new IndexException(ex.getMessage(), ex);
+
+ } catch (IOException ex) {
+ throw new IndexException(ex.getMessage(), ex);
}
}
- private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException,
- IOException {
-
+ private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws IndexException {
DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap();
DocumentMap docs = new DocumentMap();
@@ -236,37 +237,30 @@
e.printStackTrace();
}
- FileWriter writer = new FileWriter("indexed.txt");
+ // FileWriter writer = new FileWriter("indexed.txt");
for (Document doc : docs.values()) {
org.apache.lucene.document.Document luceneDoc = doc.createLuceneDocument();
- writer.write(luceneDoc.toString());
- writer.write('\n');
- writer.write('\n');
- indexWriter.addDocument(luceneDoc);
-
+ // writer.write(luceneDoc.toString());
+ // writer.write('\n');
+ // writer.write('\n');
+
+ try {
+ indexWriter.addDocument(luceneDoc);
+
+ } catch (CorruptIndexException e) {
+ throw new IndexException(e.getMessage(), e);
+
+ } catch (IOException e) {
+ throw new IndexException(e.getMessage(), e);
+ }
+
}
-
- writer.close();
-
- // BufferedReader consoleReader = new BufferedReader(
- // new InputStreamReader(System.in));
- //
- // while (true) {
- // System.out.print("query: ");
- // String queryString = consoleReader.readLine();
- //
- // if (queryString.equals("exit")) {
- // break;
- // }
- //
- // parseAndSearch(queryString, false);
- //
- // }
+ // writer.close();
}
@AllowsPassByReference
- public void contributionUpdated(Contribution oldContribution, Contribution contribution) {
+ public void updateContribution(Contribution oldContribution, Contribution contribution) throws IndexException {
IndexWriter indexWriter = null;
@@ -291,7 +285,7 @@
}
- throw new RuntimeException("Problem while indexing!", e);
+ throw new IndexException(e.getMessage(), e);
} finally {
@@ -310,65 +304,53 @@
}
- public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws Exception {
-
- final IndexSearcher searcher = new IndexSearcher(getIndexDirectory());
-
- DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(new DomainSearchResultFactory());
-
- final Query query = qp.parse(searchQuery);
- System.out.println("query: " + searchQuery);
-
- TopDocs topDocs = searcher.search(query, 1000);
+ public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws IndexException, ParseException {
+ return search(this.qp.parse(searchQuery), highlight);
+ }
- int indexed = 0;
- HashSet<String> set = new HashSet<String>();
- for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
- org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc);
+ public Result[] search(Query searchQuery, boolean highlight) throws IndexException {
- resultProcessor.process(luceneDocument, null);
+ try {
+ final IndexSearcher searcher = new IndexSearcher(getIndexDirectory());
+ DomainSearchResultProcessor resultProcessor =
+ new DomainSearchResultProcessor(new DomainSearchResultFactory());
+ TopDocs topDocs = searcher.search(searchQuery, 1000);
+
+ int indexed = 0;
+ HashSet<String> set = new HashSet<String>();
+ for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
+ org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc);
- indexed++;
- set.add(luceneDocument.toString());
+ resultProcessor.process(luceneDocument, null);
- System.out.println(luceneDocument);
+ indexed++;
+ set.add(luceneDocument.toString());
- }
+ }
- /*
- * searcher.search(query, new HitCollector() {
- * @Override public void collect(int doc, float score) { try {
- * org.apache.lucene.document.Document document = searcher .doc(doc);
- * luceneDocuments.put(doc, document); System.out.println(doc); } catch
- * (CorruptIndexException e) { // TODO Auto-generated catch block
- * e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated
- * catch block e.printStackTrace(); } } });
- */
-
- System.out.println("indexed = " + indexed);
- System.out.println("set.size() = " + set.size());
+ Result[] results = resultProcessor.createResultRoots();
- Result[] results = resultProcessor.createResultRoots();
+ if (highlight) {
- if (highlight) {
+ for (Result result : results) {
+ HighlightingUtil.highlightResult(result, searchQuery);
+ }
- for (Result result : results) {
- HighlightingUtil.highlightResult(result, query);
}
- }
+ return results;
- return results;
+ } catch (CorruptIndexException ex) {
+ throw new IndexException(ex.getMessage(), ex);
- }
+ } catch (IOException ex) {
+ throw new IndexException(ex.getMessage(), ex);
+ }
- public Result[] search(Query searchQuery, boolean hightlight) {
- // TODO Auto-generated method stub
- return null;
}
- public String highlight(String field, String text, String searchQuery) throws Exception {
- final Query query = qp.parse(searchQuery);
+ public String highlight(String field, String text, String searchQuery) throws ParseException {
+ final Query query = this.qp.parse(searchQuery);
return HighlightingUtil.highlight(field, query, text);
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java Wed Oct 28 06:38:34 2009
@@ -33,7 +33,6 @@
import org.apache.tuscany.sca.domain.search.Result;
/**
- *
* @version $Rev$ $Date$
*/
final public class HighlightingUtil {
@@ -53,22 +52,17 @@
}
- try {
- String highlightedText =
- HighlightingUtil.bestFragmentHighlighted(result.getField(), query, result.getValue(), fragmenter);
-
- // checks if something was highlighted before resetting the value
- if (highlightedText != null && highlightedText.length() > 0) {
- result.setValue(highlightedText);
- }
+ String highlightedText =
+ HighlightingUtil.bestFragmentHighlighted(result.getField(), query, result.getValue(), fragmenter);
- } catch (IOException e) {
- // ignore highlighting
+ // checks if something was highlighted before resetting the value
+ if (highlightedText != null && highlightedText.length() > 0) {
+ result.setValue(highlightedText);
}
}
- public static String highlight(String field, Query query, String text) throws IOException {
+ public static String highlight(String field, Query query, String text) {
String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter());
if (highlightedText == null || text.length() >= highlightedText.length()) {
@@ -83,26 +77,30 @@
return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100));
}
- public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter)
- throws IOException {
- CachingTokenFilter tokenStream =
- new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(field, new StringReader(text)));
-
- Highlighter highlighter =
- new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, ""));
- highlighter.setTextFragmenter(fragmenter);
- tokenStream.reset();
+ public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) {
try {
- return highlighter.getBestFragments(tokenStream, text, 2, " ... ");
+ CachingTokenFilter tokenStream =
+ new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(field, new StringReader(text)));
- } catch (InvalidTokenOffsetsException e) {
+ Highlighter highlighter =
+ new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, ""));
+ highlighter.setTextFragmenter(fragmenter);
+ tokenStream.reset();
- // could not create fragments, return empty string
- return "";
+ try {
+ return highlighter.getBestFragments(tokenStream, text, 2, " ... ");
+ } catch (InvalidTokenOffsetsException e) {
+ // could not create fragments, return empty string
+ }
+
+ } catch (IOException ex) {
+ // should never happen
}
+ return "";
+
}
public static String replaceHighlightMarkupBy(CharSequence text, String startHighlight, String endHighlight) {
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java?rev=830448&r1=830447&r2=830448&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java Wed Oct 28 06:38:34 2009
@@ -25,7 +25,6 @@
import java.net.URL;
/**
- *
* @version $Rev$ $Date$
*/
public class WrappedFileContent implements FileContent {
@@ -37,49 +36,9 @@
if (protocol.equals("jar")) {
JarURLConnection jarConn = (JarURLConnection)url.openConnection();
- // Enumeration<JarEntry> entries = jarConn.getJarFile().entries();
String file = url.getFile();
file = file.substring(file.lastIndexOf('!') + 1);
- // if (file.charAt(file.length() - 1) != '/') {
- //
- // int beginIndex;
- //
- // if (file.charAt(0) == '/') {
- // beginIndex = 1;
- //
- // } else {
- // beginIndex = 0;
- // }
- //
- // file = file.substring(beginIndex);
- //
- // while (entries.hasMoreElements()) {
- // String actualFile = entries.nextElement().getName();
- //
- // if (actualFile.charAt(0) == '/') {
- // beginIndex = 1;
- //
- // } else {
- // beginIndex = 0;
- // }
- //
- // if (actualFile.length() - beginIndex == file.length() + 1 &&
- // actualFile.charAt(actualFile.length() - 1) == '/') {
- //
- // if (actualFile.startsWith(file, beginIndex)) {
- // file = actualFile;
- //
- // break;
- //
- // }
- //
- // }
- //
- // }
- //
- // }
-
this.fileContent = ZipFileContent.createZipFileContent(jarConn.getJarFile(), file);
} else if (protocol.equals("file")) {