[Yanel-dev] Next-gen search interface for Yarep
Cedric Staub
cedric.staub at wyona.com
Mon Jan 10 09:04:01 CET 2011
On Fri, Jan 07, 2011 at 11:31:35AM +0100, Cedric Staub wrote:
> Hello out there
>
> We are currently thinking about extending the search-capabilities of
> Yarep by adding some new attributes that could be implemented by a
> repository implementation to allow access to various search interfaces.
>
> For example, I have drafted two possible interfaces:
> - QOMSearchableV1: This interface would allow a repository to expose
> the Query Object Model API as defined in JCR 2.0.
> - LuceneSearchableV1: This interface would allow a repository to
> expose the Lucene search interface, as defined in the Lucene API.
>
> A repository could choose to implement none, one, or both of them.
>
> One could also think of other possible search interfaces. Another
> possibility would be to come up with a new Yarep-specific search
> interface and implement that using e.g. Lucene as a backend, but I feel
> like we would be reinventing the wheel (also, it's a lot of work).
>
> There are some possible issues with the interfaces tough:
> - Most repositories use Lucene as a backend for indexing, but where
> are we going to find a QOM implementation that can interface with
> Lucene and that could be integrated in Yarep? Jackrabbit has JQOM,
> but I think we'd have to pull in all of Jackrabbit to make use of it.
> - If we expose the Lucene search interface, we might risk tying
> ourselves to Lucene too much. On the other hand, since we already
> use Lucene the implementation of this would be very
> straight-forward.
>
> I would like to know what other people think of this approach or if they
> can see a better solution ;-).
Ok, here's the proposal as a patch. It adds the new interfaces QOMSearchableV1
and LuceneSearchableV1 and makes the VFS repo LuceneSearchable.
Cheers
Cedric
-------------- next part --------------
Index: src/impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemRepository.java
===================================================================
--- src/impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemRepository.java (revision 54048)
+++ src/impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemRepository.java (working copy)
@@ -30,6 +30,9 @@
import org.wyona.yarep.core.search.Indexer;
import org.wyona.yarep.core.search.SearchException;
import org.wyona.yarep.core.search.Searcher;
+import org.wyona.yarep.impl.search.lucene.LuceneConfig;
+import org.wyona.yarep.core.attributes.LuceneSearchableV1;
+import org.apache.lucene.search.IndexSearcher;
/**
* Node based file system repository.
@@ -97,7 +100,7 @@
* </ul>
*
*/
-public class VirtualFileSystemRepository implements Repository {
+public class VirtualFileSystemRepository implements Repository, LuceneSearchableV1 {
private static Logger log = Logger.getLogger(VirtualFileSystemRepository.class);
@@ -106,6 +109,7 @@
protected String name;
protected Map map;
protected Storage storage;
+ protected Configuration searchConfig;
private String alternative = null;
private String dirListingMimeType = "application/xml";
private boolean isFulltextIndexingEnabled = false;
@@ -179,7 +183,7 @@
log.debug("Alternative: " + alternative);
log.debug("Mime type of directory listing: " + dirListingMimeType);
- Configuration searchConfig = config.getChild("search-index", false);
+ searchConfig = config.getChild("search-index", false);
if(searchConfig != null && searchConfig.getNamespace() != null && searchConfig.getNamespace().equals("http://www.wyona.org/yarep/search/2.0")) {
log.info("Use index/search configuration version 2.0!");
isFulltextIndexingEnabled = searchConfig.getChild("repo-auto-index-fulltext").getAttributeAsBoolean("boolean", true);
@@ -528,6 +532,15 @@
return searcher;
}
+ /**
+ * Get Lucene searcher
+ */
+ public org.apache.lucene.search.Searcher getLuceneSearcher() throws Exception {
+ LuceneConfig config = new LuceneConfig(searchConfig, configFile.getParent(), this);
+ org.apache.lucene.search.Searcher lsearcher = new IndexSearcher(config.getFulltextSearchIndexFile().getAbsolutePath());
+ return lsearcher;
+ }
+
public boolean isAutoFulltextIndexingEnabled() {
return isFulltextIndexingEnabled;
}
Index: src/core/java/org/wyona/yarep/core/attributes/LuceneSearchableV1.java
===================================================================
--- src/core/java/org/wyona/yarep/core/attributes/LuceneSearchableV1.java (revision 0)
+++ src/core/java/org/wyona/yarep/core/attributes/LuceneSearchableV1.java (revision 0)
@@ -0,0 +1,37 @@
+/*-
+ * Copyright 2011 Wyona
+ *
+ * Licensed 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.wyona.org/licenses/APACHE-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.wyona.yarep.core.attributes;
+
+import org.apache.lucene.search.Searcher;
+
+/**
+ * Lucene Search interface (DEV).
+ * Repositories which implement this interface are searchable using
+ * the Lucene search interface rather than the old Searcher interface.
+ * Note that this interface is still under development and subject
+ * to change, use at your own risk! See
+ * http://www.ibm.com/developerworks/java/library/os-apache-lucenesearch/index.html
+ * for some examples on how to search an index with Lucene.
+ */
+public interface LuceneSearchableV1 {
+ /**
+ * Get a Lucene searcher.
+ * This method should return an Lucene Searcher object through
+ * which the Lucene index of this repository can be searched.
+ */
+ public Searcher getLuceneSearcher() throws Exception;
+}
Index: src/core/java/org/wyona/yarep/core/attributes/QOMSearchableV1.java
===================================================================
--- src/core/java/org/wyona/yarep/core/attributes/QOMSearchableV1.java (revision 0)
+++ src/core/java/org/wyona/yarep/core/attributes/QOMSearchableV1.java (revision 0)
@@ -0,0 +1,37 @@
+/*-
+ * Copyright 2011 Wyona
+ *
+ * Licensed 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.wyona.org/licenses/APACHE-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.wyona.yarep.core.attributes;
+
+import javax.jcr.query.QueryManager;
+
+/**
+ * Query Object Model Search interface (DEV).
+ * Repositories which implement this interface are searchable using
+ * the Query Object Model (QOM) rather than the old Searcher interface.
+ * Note that this interface is still under development and subject
+ * to change, use at your own risk! See
+ * http://docs.jboss.org/modeshape/latest/manuals/reference/html/jcr-query-and-search.html#jcr-qom-query-language
+ * for some examples on how to search an index using QOM.
+ */
+public interface QOMSearchableV1 {
+ /**
+ * Get query manager object.
+ * This function should return a QueryManager object through
+ * which queries can be constructed and executed for this repository.
+ */
+ public QueryManager getQueryManager() throws Exception;
+}
More information about the Yanel-development
mailing list