Class PersonalizedDocFactory
- java.lang.Object
-
- ai.preferred.cerebro.index.builder.PersonalizedDocFactory
-
public class PersonalizedDocFactory extends java.lang.Object
This class handles the creation of Document object to ensure that there is no conflict in field name and that all the hashcoding behaves as intended.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addField(org.apache.lucene.index.IndexableField... fields)
boolean
checkReservedFieldName(java.lang.String fieldname)
void
create(java.lang.Object ID, double[] features)
void
create(java.lang.Object ID, org.apache.lucene.index.IndexableField... fields)
org.apache.lucene.document.Document
getDoc()
-
-
-
Method Detail
-
create
public void create(java.lang.Object ID, double[] features) throws java.lang.Exception
- Parameters:
ID
- unique ID of the document.features
- the latent feature vector to index.- Throws:
DocNotClearedException
- this exception is triggered when a call tocreate(Object, double[])
is not paired with a call togetDoc()
. Only use this function to construct a Document containing latent vector. To add additional fields to the Document, useaddField(IndexableField...)
. CallgetDoc()
to pass the Document to IndexWriter or before creating a new Document.java.lang.Exception
-
create
public void create(java.lang.Object ID, org.apache.lucene.index.IndexableField... fields) throws SameNameException, DocNotClearedException
- Parameters:
ID
- unique ID of the documentfields
- the custom fields- Throws:
SameNameException
- this is triggered when one of your custom field has name identical to Cerebro reserved word. See more detail atIndexConst
.DocNotClearedException
- this exception is triggered when a call tocreate(Object, double[])
is not paired with a call togetDoc()
. Call this function to construct a generic text-only Document. Should you need to add latent vector later call getDoc and start anew with the other create method.
-
addField
public void addField(org.apache.lucene.index.IndexableField... fields) throws SameNameException
- Parameters:
fields
-- Throws:
SameNameException
- this is triggered when one of your custom field has name identical to Cerebro reserved word. See more detail atIndexConst
. After callingcreate(Object, double[])
to create a document with latent vector if you still want add more custom fields to a Document then use this function.
-
getDoc
public org.apache.lucene.document.Document getDoc()
- Returns:
- the Document object being built since the last
create(Object, double[])
orcreate(Object, IndexableField...)
call. After calling this function the pointer doc become null again.
-
checkReservedFieldName
public boolean checkReservedFieldName(java.lang.String fieldname)
- Parameters:
fieldname
-- Returns:
- true if the fieldname is the similar to one of the reserved words.
-
-