Updated handling of TEXT field - no longer in the index - built from all content fields

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4521 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2006-12-05 16:04:54 +00:00
parent fd351b9411
commit 0311fdd75a
2 changed files with 62 additions and 15 deletions

View File

@@ -1515,7 +1515,7 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
// don't index from the reader
readerReady = false;
// not indexed: no transformation
doc.add(new Field("TEXT", NOT_INDEXED_NO_TRANSFORMATION, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
//doc.add(new Field("TEXT", NOT_INDEXED_NO_TRANSFORMATION, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
doc.add(new Field(attributeName, NOT_INDEXED_NO_TRANSFORMATION, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
}
else if (indexAtomicPropertiesOnly
@@ -1550,7 +1550,7 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
readerReady = false;
// not indexed: transformation
// failed
doc.add(new Field("TEXT", NOT_INDEXED_TRANSFORMATION_FAILED, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
//doc.add(new Field("TEXT", NOT_INDEXED_TRANSFORMATION_FAILED, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
doc.add(new Field(attributeName, NOT_INDEXED_TRANSFORMATION_FAILED, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
}
}
@@ -1560,18 +1560,18 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
if (readerReady)
{
InputStreamReader isr = null;
InputStream ris = reader.getContentInputStream();
try
{
isr = new InputStreamReader(ris, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
isr = new InputStreamReader(ris);
}
doc.add(new Field("TEXT", isr, Field.TermVector.NO));
//InputStream ris = reader.getContentInputStream();
//try
//{
// isr = new InputStreamReader(ris, "UTF-8");
// }
//catch (UnsupportedEncodingException e)
// {
// isr = new InputStreamReader(ris);
//}
//doc.add(new Field("TEXT", isr, Field.TermVector.NO));
ris = reader.getReader().getContentInputStream();
InputStream ris = reader.getReader().getContentInputStream();
try
{
isr = new InputStreamReader(ris, "UTF-8");

View File

@@ -19,12 +19,15 @@ package org.alfresco.repo.search.impl.lucene;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.lucene.query.PathQuery;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.NamespacePrefixResolver;
@@ -125,6 +128,18 @@ public class LuceneQueryParser extends QueryParser
pathQuery.setRepeats(true);
return pathQuery;
}
else if(field.equals("TEXT"))
{
Set<QName> contentAttributes = getContentAttributes();
BooleanQuery query = new BooleanQuery();
for(QName qname : contentAttributes)
{
// The super implementation will create phrase queries etc if required
Query part = super.getFieldQuery("@"+qname.toString(), queryText);
query.add(part, Occur.SHOULD);
}
return query;
}
else if (field.equals("ID"))
{
TermQuery termQuery = new TermQuery(new Term(field, queryText));
@@ -278,8 +293,7 @@ public class LuceneQueryParser extends QueryParser
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
if((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)))
{
TermQuery termQuery = new TermQuery(new Term(expandedFieldName, queryText));
return termQuery;
return super.getFieldQuery(expandedFieldName, queryText);
}
}
@@ -301,6 +315,37 @@ public class LuceneQueryParser extends QueryParser
}
private Set<QName> getContentAttributes()
{
HashSet<QName> contentAttributes = new HashSet<QName>();
for(QName type : dictionaryService.getAllTypes())
{
Map<QName, PropertyDefinition> props = dictionaryService.getType(type).getProperties();
for(QName prop : props.keySet())
{
if(props.get(prop).getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
contentAttributes.add(prop);
}
}
}
for(QName aspect : dictionaryService.getAllAspects())
{
Map<QName, PropertyDefinition> props = dictionaryService.getAspect(aspect).getProperties();
for(QName prop : props.keySet())
{
if(props.get(prop).getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
contentAttributes.add(prop);
}
}
}
return contentAttributes;
}
/**
* @exception ParseException
* throw in overridden method to disallow
@@ -374,5 +419,7 @@ public class LuceneQueryParser extends QueryParser
{
this.dictionaryService = dictionaryService;
}
}