protected final String getIndexedIdOptional(Document doc) { if (idField == null) return null; Field f = doc.getField(idField.getName()); if (f == null) return null; return idFieldType.storedToIndexed(f); }
protected final String getIndexedId(Document doc) { if (idField == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field"); // Right now, single valued fields that require value transformation from external to internal (indexed) // form have that transformation already performed and stored as the field value. Fieldable[] id = doc.getFieldables( idField.getName() ); if (id == null || id.length < 1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document is missing uniqueKey field " + idField.getName()); if( id.length > 1 ) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document specifies multiple unique ids! " + idField.getName()); return idFieldType.storedToIndexed( id[0] ); }
public DocListAndSet getMoreLikeThis( int id, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { Document doc = reader.document(id); mltquery = mlt.like(id); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } // exclude current document from results BooleanQuery mltQuery = new BooleanQuery(); mltQuery.add(mltquery, BooleanClause.Occur.MUST); mltQuery.add( new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getFieldable(uniqueKeyField.getName())))), BooleanClause.Occur.MUST_NOT); DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltQuery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltQuery, filters, null, start, rows, flags); } return results; }
public String getIndexedId(IndexSchema schema) { if (indexedId == null) { SchemaField sf = schema.getUniqueKeyField(); if (sf != null) { if (doc != null) { schema.getUniqueKeyField(); Field storedId = doc.getField(sf.getName()); indexedId = sf.getType().storedToIndexed(storedId); } if (solrDoc != null) { SolrInputField field = solrDoc.getField(sf.getName()); if (field != null) { indexedId = sf.getType().toInternal( field.getFirstValue().toString() ); } } } } return indexedId; }
TermQuery tq = new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getField(uniqueKeyField.getName())))); qryBuilder.add(tq, BooleanClause.Occur.MUST_NOT);