Filtering out properties and classes from full text search NIHVIVO-643
This commit is contained in:
parent
66134154f8
commit
cad57c2c88
6 changed files with 61 additions and 63 deletions
|
@ -986,16 +986,24 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
||||||
try {
|
try {
|
||||||
while (typeIt.hasNext()) {
|
while (typeIt.hasNext()) {
|
||||||
Resource typeRes = (Resource) typeIt.next();
|
Resource typeRes = (Resource) typeIt.next();
|
||||||
|
String type = typeRes.getURI();
|
||||||
// brute forcing this until we implement a better strategy
|
// brute forcing this until we implement a better strategy
|
||||||
if (VitroVocabulary.PORTAL.equals(typeRes.getURI()) ||
|
if (VitroVocabulary.PORTAL.equals(type) ||
|
||||||
VitroVocabulary.TAB.equals(typeRes.getURI()) ||
|
VitroVocabulary.TAB.equals(type) ||
|
||||||
VitroVocabulary.TAB_INDIVIDUALRELATION.equals(typeRes.getURI()) ||
|
VitroVocabulary.TAB_INDIVIDUALRELATION.equals(type) ||
|
||||||
VitroVocabulary.LINK.equals(typeRes.getURI()) ||
|
VitroVocabulary.LINK.equals(type) ||
|
||||||
VitroVocabulary.KEYWORD.equals(typeRes.getURI()) ||
|
VitroVocabulary.KEYWORD.equals(type) ||
|
||||||
VitroVocabulary.KEYWORD_INDIVIDUALRELATION.equals(typeRes.getURI()) ||
|
VitroVocabulary.KEYWORD_INDIVIDUALRELATION.equals(type) ||
|
||||||
VitroVocabulary.CLASSGROUP.equals(typeRes.getURI()) ||
|
VitroVocabulary.CLASSGROUP.equals(type) ||
|
||||||
VitroVocabulary.PROPERTYGROUP.equals(typeRes.getURI()) ||
|
VitroVocabulary.PROPERTYGROUP.equals(type) ||
|
||||||
VitroVocabulary.APPLICATION.equals(typeRes.getURI())) {
|
VitroVocabulary.APPLICATION.equals(type)) {
|
||||||
|
userVisible = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( OWL.ObjectProperty.getURI().equals(type) ||
|
||||||
|
OWL.DatatypeProperty.getURI().equals(type) ||
|
||||||
|
OWL.AnnotationProperty.getURI().equals(type) ||
|
||||||
|
RDF.type.getURI().equals(type) ){
|
||||||
userVisible = false;
|
userVisible = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
|
||||||
public interface ObjectSourceIface {
|
public interface ObjectSourceIface {
|
||||||
|
|
||||||
Iterator getAllOfThisTypeIterator();
|
Iterator<Individual> getAllOfThisTypeIterator();
|
||||||
|
|
||||||
Iterator getUpdatedSinceIterator(long msSinceEpoc);
|
Iterator<Individual> getUpdatedSinceIterator(long msSinceEpoc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,10 @@ public class IndexBuilder implements Runnable {
|
||||||
long since = indexer.getModified() - 60000;
|
long since = indexer.getModified() - 60000;
|
||||||
|
|
||||||
Iterator<ObjectSourceIface> sources = sourceList.iterator();
|
Iterator<ObjectSourceIface> sources = sourceList.iterator();
|
||||||
List<Iterator<ObjectSourceIface>> listOfIterators =
|
|
||||||
new LinkedList<Iterator<ObjectSourceIface>>();
|
List<Iterator<Individual>> listOfIterators =
|
||||||
|
new LinkedList<Iterator<Individual>>();
|
||||||
|
|
||||||
while (sources.hasNext()) {
|
while (sources.hasNext()) {
|
||||||
Object obj = sources.next();
|
Object obj = sources.next();
|
||||||
if (obj != null && obj instanceof ObjectSourceIface)
|
if (obj != null && obj instanceof ObjectSourceIface)
|
||||||
|
@ -219,10 +221,10 @@ public class IndexBuilder implements Runnable {
|
||||||
* @param items
|
* @param items
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected void indexForSource(Iterator items , boolean newDocs){
|
protected void indexForSource(Iterator<Individual> individuals , boolean newDocs){
|
||||||
if( items == null ) return;
|
if( individuals == null ) return;
|
||||||
while(items.hasNext()){
|
while(individuals.hasNext()){
|
||||||
indexItem(items.next(), newDocs);
|
indexItem(individuals.next(), newDocs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,12 +250,17 @@ public class IndexBuilder implements Runnable {
|
||||||
* @param item
|
* @param item
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected void indexItem( Object item, boolean newDoc){
|
protected void indexItem( Individual ind, boolean newDoc){
|
||||||
try{
|
try{
|
||||||
indexer.index(item, newDoc);
|
if( ind == null )
|
||||||
|
return;
|
||||||
|
if( ind.getVClasses() == null || ind.getVClasses().size() < 1 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
indexer.index(ind, newDoc);
|
||||||
}catch(Throwable ex){
|
}catch(Throwable ex){
|
||||||
log.debug("IndexBuilder.indexItem() Error indexing "
|
log.debug("IndexBuilder.indexItem() Error indexing "
|
||||||
+ item + "\n" +ex);
|
+ ind + "\n" +ex);
|
||||||
}
|
}
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.search.indexing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
||||||
public interface IndexerIface {
|
public interface IndexerIface {
|
||||||
|
|
||||||
public void addObj2Doc(Obj2DocIface o2d);
|
public void addObj2Doc(Obj2DocIface o2d);
|
||||||
public List getObj2DocList();
|
public List<Obj2DocIface> getObj2DocList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if indexing is currently running in a different thread.
|
* Check if indexing is currently running in a different thread.
|
||||||
|
@ -37,7 +38,7 @@ public interface IndexerIface {
|
||||||
* @param newDoc - if true, just insert doc, if false attempt to update.
|
* @param newDoc - if true, just insert doc, if false attempt to update.
|
||||||
* @throws IndexingException
|
* @throws IndexingException
|
||||||
*/
|
*/
|
||||||
public void index(Object doc, boolean newDoc)throws IndexingException;
|
public void index(Individual ind, boolean newDoc)throws IndexingException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +46,7 @@ public interface IndexerIface {
|
||||||
* @param obj
|
* @param obj
|
||||||
* @throws IndexingException
|
* @throws IndexingException
|
||||||
*/
|
*/
|
||||||
public void removeFromIndex(Object obj ) throws IndexingException;
|
public void removeFromIndex(Individual ind) throws IndexingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all documents from the index.
|
* Removes all documents from the index.
|
||||||
|
|
|
@ -75,27 +75,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{
|
||||||
private static String entClassName = Individual.class.getName();
|
private static String entClassName = Individual.class.getName();
|
||||||
|
|
||||||
public boolean canTranslate(Object obj) {
|
public boolean canTranslate(Object obj) {
|
||||||
if(obj != null && obj instanceof Individual){
|
return (obj != null && obj instanceof Individual);
|
||||||
Individual ind = (Individual)obj;
|
|
||||||
List<VClass> vclasses = ind.getVClasses();
|
|
||||||
if( vclasses == null || vclasses.size() < 1 ){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for( VClass c : vclasses ){
|
|
||||||
if( c != null)
|
|
||||||
if (VitroVocabulary.RDF_TYPE.equals(c.getURI()))
|
|
||||||
return false;
|
|
||||||
else if ( OWL.OBJECTPROPERTY.stringValue().equals((c.getURI())))
|
|
||||||
return false;
|
|
||||||
else if ( OWL.DATATYPEPROPERTY.stringValue().equals((c.getURI())))
|
|
||||||
return false;
|
|
||||||
else if ( OWL.ANNOTATIONPROPERTY.stringValue().equals((c.getURI())))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.apache.lucene.search.IndexSearcher;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.FSDirectory;
|
import org.apache.lucene.store.FSDirectory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
|
||||||
|
@ -181,8 +182,7 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
* to setup the modifier.
|
* to setup the modifier.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public synchronized void index(Object obj, boolean newDoc)
|
public void index(Individual ind, boolean newDoc) throws IndexingException {
|
||||||
throws IndexingException {
|
|
||||||
if( ! indexing )
|
if( ! indexing )
|
||||||
throw new IndexingException("LuceneIndexer: must call " +
|
throw new IndexingException("LuceneIndexer: must call " +
|
||||||
"startIndexing() before index().");
|
"startIndexing() before index().");
|
||||||
|
@ -193,11 +193,11 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
Iterator<Obj2DocIface> it = getObj2DocList().iterator();
|
Iterator<Obj2DocIface> it = getObj2DocList().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Obj2DocIface obj2doc = (Obj2DocIface) it.next();
|
Obj2DocIface obj2doc = (Obj2DocIface) it.next();
|
||||||
if (obj2doc.canTranslate(obj)) {
|
if (obj2doc.canTranslate(ind)) {
|
||||||
if( !newDoc ){
|
if( !newDoc ){
|
||||||
writer.deleteDocuments((Term)obj2doc.getIndexId(obj));
|
writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
||||||
}
|
}
|
||||||
Document d = (Document) obj2doc.translate(obj);
|
Document d = (Document) obj2doc.translate(ind);
|
||||||
if( d != null)
|
if( d != null)
|
||||||
writer.addDocument(d);
|
writer.addDocument(d);
|
||||||
}
|
}
|
||||||
|
@ -211,8 +211,7 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
* Removes a single object from index. <code>obj</code> is translated
|
* Removes a single object from index. <code>obj</code> is translated
|
||||||
* using the obj2DocList.
|
* using the obj2DocList.
|
||||||
*/
|
*/
|
||||||
public synchronized void removeFromIndex(Object obj )
|
public void removeFromIndex(Individual ind) throws IndexingException {
|
||||||
throws IndexingException{
|
|
||||||
if( writer == null )
|
if( writer == null )
|
||||||
throw new IndexingException("LuceneIndexer: cannot delete from " +
|
throw new IndexingException("LuceneIndexer: cannot delete from " +
|
||||||
"index, IndexWriter is null.");
|
"index, IndexWriter is null.");
|
||||||
|
@ -220,8 +219,8 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
Iterator<Obj2DocIface> it = getObj2DocList().iterator();
|
Iterator<Obj2DocIface> it = getObj2DocList().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Obj2DocIface obj2doc = (Obj2DocIface) it.next();
|
Obj2DocIface obj2doc = (Obj2DocIface) it.next();
|
||||||
if (obj2doc.canTranslate(obj)) {
|
if (obj2doc.canTranslate(ind)) {
|
||||||
writer.deleteDocuments((Term)obj2doc.getIndexId(obj));
|
writer.deleteDocuments((Term)obj2doc.getIndexId(ind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
@ -311,4 +310,6 @@ public class LuceneIndexer implements IndexerIface {
|
||||||
// The directory is now empty so delete it
|
// The directory is now empty so delete it
|
||||||
return dir.delete();
|
return dir.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue