Author: thomas.heute(a)jboss.com
Date: 2006-12-18 10:24:44 -0500 (Mon, 18 Dec 2006)
New Revision: 5888
Added:
trunk/search/src/main/org/jboss/portal/search/lucene/
trunk/search/src/main/org/jboss/portal/search/lucene/GenericDocument.java
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneQueryConverter.java
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneSearchFederated.java
trunk/search/src/main/org/jboss/portal/search/query/impl/BetweenDatesTerm.java
trunk/search/src/main/org/jboss/portal/search/query/impl/DateTerm.java
trunk/search/src/main/org/jboss/portal/search/result/ResultURL.java
trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResultURL.java
trunk/search/src/main/org/jboss/portal/search/test/TestLuceneSearchFederated.java
Removed:
trunk/search/src/main/org/jboss/portal/search/test/LuceneUtil.java
trunk/search/src/main/org/jboss/portal/search/test/SearchFederatedLucene.java
Modified:
trunk/search/
trunk/search/build.xml
trunk/search/src/main/org/jboss/portal/search/federation/Info.java
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederated.java
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederation.java
trunk/search/src/main/org/jboss/portal/search/federation/impl/SearchFederationService.java
trunk/search/src/main/org/jboss/portal/search/query/Query.java
trunk/search/src/main/org/jboss/portal/search/result/Result.java
trunk/search/src/main/org/jboss/portal/search/result/impl/AbstractResult.java
trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResult.java
trunk/search/src/main/org/jboss/portal/search/test/DummySearchFederated.java
trunk/search/src/main/org/jboss/portal/search/test/LuceneQueryTest.java
Log:
Lucene implementation + tests
Property changes on: trunk/search
___________________________________________________________________
Name: svn:ignore
+ Test
Modified: trunk/search/build.xml
===================================================================
--- trunk/search/build.xml 2006-12-18 03:03:27 UTC (rev 5887)
+++ trunk/search/build.xml 2006-12-18 15:24:44 UTC (rev 5888)
@@ -171,6 +171,7 @@
<x-test>
<test todir="${test.reports}"
name="org.jboss.portal.search.test.LuceneQueryTest"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.search.test.FederationTest"/>
</x-test>
<x-classpath>
<pathelement location="${build.classes}"/>
@@ -178,6 +179,7 @@
<path refid="dom4j.dom4j.classpath"/>
<path refid="library.classpath"/>
<path refid="dependentmodule.classpath"/>
+ <path refid="oswego.concurrent.classpath"/>
</x-classpath>
</execute-tests>
</target>
Modified: trunk/search/src/main/org/jboss/portal/search/federation/Info.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/federation/Info.java 2006-12-18 03:03:27
UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/federation/Info.java 2006-12-18 15:24:44
UTC (rev 5888)
@@ -57,8 +57,9 @@
public static final int STARTED = 0;
public static final int INDEXING = 1;
public static final int CORRUPTED = 2;
- public static final int UNAVAILABLE = 3;
- public static final int STOPPED = 4;
+ public static final int AVAILABLE = 3;
+ public static final int UNAVAILABLE = 4;
+ public static final int STOPPED = 5;
}
}
Modified: trunk/search/src/main/org/jboss/portal/search/federation/SearchFederated.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederated.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederated.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -33,14 +33,38 @@
public interface SearchFederated
{
+ /**
+ * Get the ID for this federated search
+ * @return String representing this particular federated search
+ */
public String getId();
+ /**
+ * Method called when this federated search is not used anymore.
+ * This could be the place to destry any index
+ * @throws IndexingException
+ */
public void destroy() throws IndexingException;
+ /**
+ * The create method should index the required components
+ * @throws IndexingException
+ */
public void create() throws IndexingException;
+ /**
+ * Info should return information on the current status
+ * if the federated search
+ * @return
+ */
public Info getInfo();
+ /**
+ * From the query object this method is responsible to return the
+ * results of the query
+ * @param query
+ * @return
+ */
public Results search(Query query);
public String getMarkup(Results results, int markupLevel);
Modified: trunk/search/src/main/org/jboss/portal/search/federation/SearchFederation.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederation.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/federation/SearchFederation.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -39,7 +39,7 @@
public void reindexAll();
- public List getSearchFederated();
+ public List getSearchFederatedList();
public SearchFederated getSearchFederated(String id);
Modified:
trunk/search/src/main/org/jboss/portal/search/federation/impl/SearchFederationService.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/federation/impl/SearchFederationService.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/federation/impl/SearchFederationService.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -90,7 +90,8 @@
while (it.hasNext())
{
SearchFederated federated = (SearchFederated) it.next();
- if (federated.getInfo().getStatus() != Info.Status.INDEXING)
+ int status = federated.getInfo().getStatus();
+ if (status != Info.Status.INDEXING)
{
Thread thread = new ReindexFederatedThread(federated);
thread.run();
@@ -115,7 +116,7 @@
{
federated.destroy();
federated.create();
- federated.getInfo().setStatus(Info.Status.STARTED);
+ federated.getInfo().setStatus(Info.Status.AVAILABLE);
}
catch (IndexingException e)
{
@@ -125,7 +126,7 @@
}
}
- public List getSearchFederated()
+ public List getSearchFederatedList()
{
return Collections.unmodifiableList(new ArrayList(registry.values()));
}
@@ -142,7 +143,10 @@
while (it.hasNext())
{
SearchFederated federated = (SearchFederated)it.next();
- results.addAll(federated.search(query));
+ if (federated.getInfo().getStatus() == Info.Status.AVAILABLE)
+ {
+ results.addAll(federated.search(query));
+ }
}
return results;
}
Added: trunk/search/src/main/org/jboss/portal/search/lucene/GenericDocument.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/lucene/GenericDocument.java 2006-12-18
03:03:27 UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/lucene/GenericDocument.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.lucene;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class GenericDocument
+{
+ private String title;
+
+ private long date;
+
+ private Map fields;
+
+ public Map getFields()
+ {
+ return fields;
+ }
+
+ public long getDate()
+ {
+ return date;
+ }
+
+ public void setDate(long date)
+ {
+ this.date = date;
+ }
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+
+ public void addField(String name, String value)
+ {
+ if (fields == null)
+ {
+ fields = new HashMap();
+ }
+ fields.put(name, value);
+ }
+}
Added: trunk/search/src/main/org/jboss/portal/search/lucene/LuceneQueryConverter.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneQueryConverter.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneQueryConverter.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.lucene;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.portal.search.query.Query;
+import org.jboss.portal.search.query.QueryTerm;
+import org.jboss.portal.search.query.impl.BetweenDatesTerm;
+import org.jboss.portal.search.query.impl.DateTerm;
+import org.jboss.portal.search.query.impl.FieldQueryTerm;
+import org.jboss.portal.search.query.impl.KeywordQueryTerm;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class LuceneQueryConverter
+{
+
+ public static String convert(Query query)
+ {
+ StringBuffer result = new StringBuffer();
+ Iterator it;
+
+ List terms = query.getMandatoryTerms();
+ if (terms != null)
+ {
+ it = terms.iterator();
+ while (it.hasNext())
+ {
+ QueryTerm term = (QueryTerm) it.next();
+ convert(result, term, "+");
+ }
+ }
+
+ terms = query.getNotTerms();
+ if (terms != null)
+ {
+ it = terms.iterator();
+ while (it.hasNext())
+ {
+ QueryTerm term = (QueryTerm) it.next();
+ convert(result, term, "-");
+ }
+ }
+
+ terms = query.getOptionalTerms();
+ if (terms != null)
+ {
+ it = terms.iterator();
+ while (it.hasNext())
+ {
+ QueryTerm term = (QueryTerm) it.next();
+ convert(result, term, "");
+ }
+ }
+ return result.toString();
+ }
+
+ private static void convert(StringBuffer result, QueryTerm term, String prefix)
+ {
+ if (term instanceof FieldQueryTerm)
+ {
+ FieldQueryTerm convertedTerm = (FieldQueryTerm) term;
+ result.append(" " + prefix + convertedTerm.getName() +
":\"" + convertedTerm.getValue()+"\"");
+ }
+ else if (term instanceof KeywordQueryTerm)
+ {
+ KeywordQueryTerm convertedTerm = (KeywordQueryTerm) term;
+ result.append(" " + prefix + convertedTerm.getKeyWord());
+ }
+ else if (term instanceof BetweenDatesTerm)
+ {
+ BetweenDatesTerm convertedTerm = (BetweenDatesTerm) term;
+ result.append(" " + prefix + convertedTerm.getField() + ":["
+ convertedTerm.getFromTime() + "," + convertedTerm.getToTime() +
"]");
+ }
+ else if (term instanceof DateTerm)
+ {
+ DateTerm convertedTerm = (DateTerm) term;
+ result.append(" " + prefix + convertedTerm.getField() + ":["
+ convertedTerm.getTime() + "," + (convertedTerm.getTime() + 24*60*60*1000) +
"}");
+ }
+ }
+
+}
Added: trunk/search/src/main/org/jboss/portal/search/lucene/LuceneSearchFederated.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneSearchFederated.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/lucene/LuceneSearchFederated.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.lucene;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Searcher;
+import org.jboss.portal.search.IndexingException;
+import org.jboss.portal.search.federation.Info;
+import org.jboss.portal.search.federation.SearchFederated;
+import org.jboss.portal.search.query.Query;
+import org.jboss.portal.search.result.Results;
+import org.jboss.portal.search.result.impl.AbstractResult;
+import org.jboss.portal.search.result.impl.SimpleResult;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class LuceneSearchFederated implements SearchFederated
+{
+
+ private IndexWriter index;
+
+ private String id;
+
+ private Info info;
+
+ private String indexPath;
+
+ private String defaultField;
+
+ public LuceneSearchFederated(String id, String indexPath, String defaultField)
+ {
+ this.id = id;
+ this.indexPath = indexPath;
+ this.defaultField = defaultField;
+ info = new Info();
+ }
+
+ public void create() throws IndexingException
+ {
+
+ try
+ {
+ index = new IndexWriter(indexPath, new StandardAnalyzer(), true);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ info.setStatus(Info.Status.INDEXING);
+ try
+ {
+ List documents = getLuceneDocuments();
+ Iterator it = documents.iterator();
+ while (it.hasNext())
+ {
+ Document document = (Document)it.next();
+ index.addDocument(document);
+ }
+ index.optimize();
+ index.close();
+ }
+ catch (IOException e)
+ {
+ throw new IndexingException("Cannot index document", e);
+ }
+ info.setStatus(Info.Status.STARTED);
+ }
+
+ public List getLuceneDocuments()
+ {
+ List documents = getDocuments();
+ Iterator it = documents.iterator();
+ while (it.hasNext())
+ {
+ GenericDocument genericDoc = (GenericDocument) it.next();
+ Document doc = new Document();
+ if (genericDoc.getTitle() != null)
+ doc.add(Field.Text("title", genericDoc.getTitle()));
+ if (genericDoc.getDate() != 0)
+ doc.add(Field.Text("date", genericDoc.getDate()+""));
+ if (genericDoc.getFields() != null)
+ {
+ Map map = genericDoc.getFields();
+ Iterator itKeys = map.keySet().iterator();
+ while (itKeys.hasNext())
+ {
+ String key = (String)itKeys.next();
+ doc.add(Field.Text(key, (String)map.get(key)));
+ }
+ }
+ documents.add(doc);
+ }
+ return documents;
+ }
+
+ public abstract List getDocuments();
+
+ public void destroy()
+ {
+ info.setStatus(Info.Status.STOPPED);
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public Info getInfo()
+ {
+ return info;
+ }
+
+ public Results search(Query query)
+ {
+ Results result = new Results();
+ String luceneQueryString = LuceneQueryConverter.convert(query);
+ QueryParser parser = new QueryParser(defaultField, new StandardAnalyzer());
+ try
+ {
+ org.apache.lucene.search.Query luceneQuery = parser.parse(luceneQueryString);
+ Searcher searcher = new IndexSearcher(indexPath);
+ Hits hits = searcher.search(luceneQuery);
+ for (int i=0; i<hits.length(); i++)
+ {
+ result.add(new SimpleResult(id, hits.doc(i)));
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ public String getMarkup(Results results, int markupLevel)
+ {
+ StringBuffer buffer = new StringBuffer();
+ Iterator it = results.iterator();
+ while (it.hasNext())
+ {
+ AbstractResult result = (AbstractResult) it.next();
+ Document document = (Document)((SimpleResult)result).getValue();
+ buffer.append("Id:" +
document.getField("id").stringValue());
+ buffer.append(" ");
+ }
+ return buffer.toString();
+ }
+
+}
Modified: trunk/search/src/main/org/jboss/portal/search/query/Query.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/query/Query.java 2006-12-18 03:03:27 UTC
(rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/query/Query.java 2006-12-18 15:24:44 UTC
(rev 5888)
@@ -27,6 +27,13 @@
/**
+ * The Query object is used to express a query.
+ * Common queries use mandatory terms, optional terms and missing terms.
+ * For instance you could do a query stating that you absolutely want
+ * the keyword 'Mustang' in your query, that the keyword 'car' is
optional
+ * and could be used to show the results with the two keywords higher
+ * in the list and without the keyword 'horse'. In traditional search
+ * tools it would be represented as the string: "+mustang car -horse"
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @version $Revision$
*/
@@ -37,9 +44,11 @@
private List optionalTerms;
private List notTerms;
+ /*
private List mandatoryQueries;
private List optionalQueries;
private List notQueries;
+ */
public void addMandatoryTerm(QueryTerm term)
{
@@ -68,6 +77,7 @@
notTerms.add(term);
}
+ /*
public void addMandatoryQuery(Query query)
{
if (mandatoryQueries == null)
@@ -99,27 +109,27 @@
{
return mandatoryQueries;
}
-
+*/
public List getMandatoryTerms()
{
return mandatoryTerms;
}
-
+/*
public List getNotQueries()
{
return notQueries;
}
-
+*/
public List getNotTerms()
{
return notTerms;
}
-
+/*
public List getOptionalQueries()
{
return optionalQueries;
}
-
+*/
public List getOptionalTerms()
{
return optionalTerms;
Added: trunk/search/src/main/org/jboss/portal/search/query/impl/BetweenDatesTerm.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/query/impl/BetweenDatesTerm.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/query/impl/BetweenDatesTerm.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.query.impl;
+
+import org.jboss.portal.search.query.QueryTerm;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class BetweenDatesTerm implements QueryTerm
+{
+ private String field;
+ private long fromTime;
+ private long toTime;
+
+ public BetweenDatesTerm(String field, long fromTime, long toTime)
+ {
+ this.field = field;
+ this.fromTime = fromTime;
+ this.toTime = toTime;
+ }
+
+ public String getField()
+ {
+ return field;
+ }
+
+ public long getFromTime()
+ {
+ return fromTime;
+ }
+
+ public long getToTime()
+ {
+ return toTime;
+ }
+}
Added: trunk/search/src/main/org/jboss/portal/search/query/impl/DateTerm.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/query/impl/DateTerm.java 2006-12-18
03:03:27 UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/query/impl/DateTerm.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.query.impl;
+
+import org.jboss.portal.search.query.QueryTerm;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class DateTerm implements QueryTerm
+{
+
+ public static final int BEFORE = 0;
+ public static final int AFTER = 1;
+ public static final int ON = 2;
+
+ private String field;
+ private long time;
+ private int temporal;
+
+ public DateTerm(String field, long time, int temporal)
+ {
+ this.field = field;
+ this.time = time;
+ this.temporal = temporal;
+ }
+
+ public String getField()
+ {
+ return field;
+ }
+
+ public int getTemporal()
+ {
+ return temporal;
+ }
+
+ public long getTime()
+ {
+ return time;
+ }
+
+}
Modified: trunk/search/src/main/org/jboss/portal/search/result/Result.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/result/Result.java 2006-12-18 03:03:27
UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/result/Result.java 2006-12-18 15:24:44
UTC (rev 5888)
@@ -31,4 +31,6 @@
public float getScore();
public String getFederatedId();
+
+ public ResultURL getURL();
}
Added: trunk/search/src/main/org/jboss/portal/search/result/ResultURL.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/result/ResultURL.java 2006-12-18
03:03:27 UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/result/ResultURL.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.result;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface ResultURL
+{
+
+}
Modified: trunk/search/src/main/org/jboss/portal/search/result/impl/AbstractResult.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/result/impl/AbstractResult.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/result/impl/AbstractResult.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -23,6 +23,7 @@
package org.jboss.portal.search.result.impl;
import org.jboss.portal.search.result.Result;
+import org.jboss.portal.search.result.ResultURL;
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
@@ -32,8 +33,22 @@
{
private String federatedId;
+ private String title;
+
private float score;
+ private ResultURL url;
+
+ public ResultURL getURL()
+ {
+ return url;
+ }
+
+ public void setURL(ResultURL url)
+ {
+ this.url = url;
+ }
+
public AbstractResult(String federatedId)
{
this.federatedId = federatedId;
@@ -54,4 +69,14 @@
this.score = score;
}
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+
}
Modified: trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResult.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResult.java 2006-12-18
03:03:27 UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResult.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -47,5 +47,4 @@
this.value = value;
}
-
}
Added: trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResultURL.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResultURL.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/result/impl/SimpleResultURL.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.result.impl;
+
+import org.jboss.portal.search.result.ResultURL;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class SimpleResultURL implements ResultURL
+{
+ private String url;
+
+ public SimpleResultURL(String url)
+ {
+ this.url = url;
+ }
+
+ public String getURL()
+ {
+ return url;
+ }
+}
Modified: trunk/search/src/main/org/jboss/portal/search/test/DummySearchFederated.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/test/DummySearchFederated.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/test/DummySearchFederated.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -46,6 +46,7 @@
public void create() throws IndexingException
{
info.setStatus(Info.Status.STARTED);
+ info.setStatus(Info.Status.AVAILABLE);
}
public void destroy() throws IndexingException
Modified: trunk/search/src/main/org/jboss/portal/search/test/LuceneQueryTest.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/test/LuceneQueryTest.java 2006-12-18
03:03:27 UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/test/LuceneQueryTest.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -23,7 +23,10 @@
package org.jboss.portal.search.test;
import org.jboss.portal.search.IndexingException;
+import org.jboss.portal.search.lucene.LuceneQueryConverter;
+import org.jboss.portal.search.lucene.LuceneSearchFederated;
import org.jboss.portal.search.query.Query;
+import org.jboss.portal.search.query.impl.BetweenDatesTerm;
import org.jboss.portal.search.query.impl.FieldQueryTerm;
import org.jboss.portal.search.result.Results;
@@ -41,17 +44,28 @@
Query query = new Query();
query.addMandatoryTerm(new FieldQueryTerm("Title", "My
Title"));
query.addMandatoryTerm(new FieldQueryTerm("id", "1"));
- assertEquals(" +Title:\"My Title\" +id:\"1\"",
LuceneUtil.convert(query));
+ assertEquals(" +Title:\"My Title\" +id:\"1\"",
LuceneQueryConverter.convert(query));
}
-
- public void test02() throws IndexingException
+
+ public void test02()
{
Query query = new Query();
+ query.addMandatoryTerm(new FieldQueryTerm("Title", "My
Title"));
query.addMandatoryTerm(new FieldQueryTerm("id", "1"));
- SearchFederatedLucene fed = new SearchFederatedLucene();
+ query.addNotTerm(new BetweenDatesTerm("date", 10000, 20000));
+ assertEquals(" +Title:\"My Title\" +id:\"1\"
-date:[10000,20000]", LuceneQueryConverter.convert(query));
+ }
+
+ public void test03() throws IndexingException
+ {
+ LuceneSearchFederated fed = new TestLuceneSearchFederated("TestSearch",
"test", "id");
fed.create();
+
+ Query query = new Query();
+ query.addMandatoryTerm(new FieldQueryTerm("id", "1"));
Results results = fed.search(query);
- assertEquals("Id:1 Id:1 test ", fed.getMarkup(results, 0));
+ System.out.println(fed.getMarkup(results, 0));
+ assertEquals("Id:1 Id:1 cat ", fed.getMarkup(results, 0));
}
}
Deleted: trunk/search/src/main/org/jboss/portal/search/test/LuceneUtil.java
===================================================================
--- trunk/search/src/main/org/jboss/portal/search/test/LuceneUtil.java 2006-12-18 03:03:27
UTC (rev 5887)
+++ trunk/search/src/main/org/jboss/portal/search/test/LuceneUtil.java 2006-12-18 15:24:44
UTC (rev 5888)
@@ -1,56 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.search.test;
-
-import java.util.Iterator;
-
-import org.jboss.portal.search.query.Query;
-import org.jboss.portal.search.query.QueryTerm;
-import org.jboss.portal.search.query.impl.FieldQueryTerm;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class LuceneUtil
-{
-
- // TODO: actually do it...
- public static String convert(Query query)
- {
- StringBuffer result = new StringBuffer();
- Iterator it = query.getMandatoryTerms().iterator();
- while (it.hasNext())
- {
- QueryTerm term = (QueryTerm) it.next();
- if (term instanceof FieldQueryTerm)
- {
- FieldQueryTerm convertedTerm = (FieldQueryTerm) term;
- result.append(" +" + convertedTerm.getName() + ":\""
+ convertedTerm.getValue()+"\"");
- }
- }
-
- return result.toString();
- }
-
-}
Deleted: trunk/search/src/main/org/jboss/portal/search/test/SearchFederatedLucene.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/test/SearchFederatedLucene.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/test/SearchFederatedLucene.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -1,145 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.search.test;
-
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Searcher;
-import org.jboss.portal.search.IndexingException;
-import org.jboss.portal.search.federation.Info;
-import org.jboss.portal.search.federation.SearchFederated;
-import org.jboss.portal.search.query.Query;
-import org.jboss.portal.search.result.Results;
-import org.jboss.portal.search.result.impl.AbstractResult;
-import org.jboss.portal.search.result.impl.SimpleResult;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class SearchFederatedLucene implements SearchFederated
-{
-
- private IndexWriter index;
-
- private String id;
-
- private Info info;
-
- public SearchFederatedLucene()
- {
- this.id = "Lucene Federated";
- info = new Info();
- try
- {
- index = new IndexWriter("Test", new StandardAnalyzer(), true);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- info.setStatus(Info.Status.STARTED);
- }
-
- public void create() throws IndexingException
- {
- info.setStatus(Info.Status.INDEXING);
- try
- {
- Document doc1 = new Document();
- doc1.add(Field.Keyword("id", "1"));
- index.addDocument(doc1);
- Document doc2 = new Document();
- doc2.add(Field.Text("id", "1 test"));
- index.addDocument(doc2);
- index.close();
- }
- catch (IOException e)
- {
- throw new IndexingException("Cannot index document", e);
- }
- info.setStatus(Info.Status.STARTED);
- }
-
- public void destroy()
- {
- info.setStatus(Info.Status.STOPPED);
- }
-
- public String getId()
- {
- return id;
- }
-
- public Info getInfo()
- {
- return info;
- }
-
- public Results search(Query query)
- {
- Results result = new Results();
- String luceneQueryString = LuceneUtil.convert(query);
- QueryParser parser = new QueryParser("all", new StandardAnalyzer());
- try
- {
- org.apache.lucene.search.Query luceneQuery = parser.parse(luceneQueryString);
- Searcher searcher = new IndexSearcher("Test");
- Hits hits = searcher.search(luceneQuery);
- for (int i=0; i<hits.length(); i++)
- {
- result.add(new SimpleResult(id, hits.doc(i)));
- }
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return result;
- }
-
- public String getMarkup(Results results, int markupLevel)
- {
- StringBuffer buffer = new StringBuffer();
- Iterator it = results.iterator();
- while (it.hasNext())
- {
- AbstractResult result = (AbstractResult) it.next();
- Document document = (Document)((SimpleResult)result).getValue();
- buffer.append("Id:" +
document.getField("id").stringValue());
- buffer.append(" ");
- }
- return buffer.toString();
- }
-
-}
Added: trunk/search/src/main/org/jboss/portal/search/test/TestLuceneSearchFederated.java
===================================================================
---
trunk/search/src/main/org/jboss/portal/search/test/TestLuceneSearchFederated.java 2006-12-18
03:03:27 UTC (rev 5887)
+++
trunk/search/src/main/org/jboss/portal/search/test/TestLuceneSearchFederated.java 2006-12-18
15:24:44 UTC (rev 5888)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.search.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.jboss.portal.search.lucene.LuceneSearchFederated;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class TestLuceneSearchFederated extends LuceneSearchFederated
+{
+
+ public TestLuceneSearchFederated(String id, String indexPath, String defaultField)
+ {
+ super(id, indexPath, defaultField);
+ }
+
+ public List getLuceneDocuments()
+ {
+ List result = new ArrayList();
+
+ Document doc1 = new Document();
+ doc1.add(Field.Text("id", "1"));
+ result.add(doc1);
+
+ Document doc2 = new Document();
+ doc2.add(Field.Text("id", "1 cat"));
+ result.add(doc2);
+
+ return result;
+ }
+
+ public List getDocuments()
+ {
+ return null;
+ }
+
+}