Using MoreLikeThis
more_like_this
is available through query methods, and will return similar documents according
to the provided criteria and options.
Syntax
def more_like_this(
self, more_like_this_or_builder: Union[MoreLikeThisBase, Callable[[MoreLikeThisBuilder[_T]], None]]
) -> DocumentQuery[_T]: ...
more_like_this_or_builder parameter |
Description |
MoreLikeThisBase |
Defines the type of MoreLikeThis that should be executed |
Callable[[MoreLikeThisBuilder[_T]], None]] |
Builder with fluent API that constructs the MoreLikeThisBase instance |
Builder
def using_any_document(self) -> MoreLikeThisOperations[_T]: ...
def using_document(
self, document_json_or_builder: Union[str, Callable[[DocumentQuery[_T]], None]]
) -> MoreLikeThisOperations[_T]: ...
def with_options(self, options: MoreLikeThisOptions) -> MoreLikeThisOperations[_T]: ...
Builder method |
Parameter |
Type |
Description |
using_any_document |
|
|
|
using_document |
document_json_or_builder (Union) |
str |
Inline JSON document that will be used for the operation |
using_document |
document_json_or_builder (Union) |
Callable[[DocumentQuery[_T]], None] |
Filtering expression to find a document that will be used for the operation |
with_options |
options |
MoreLikeThisOptions |
Non-default options to be used by the operation |
Options
def __init__(
self,
minimum_term_frequency: int = None,
maximum_query_terms: int = None,
maximum_number_of_tokens_parsed: int = None,
minimum_word_length: int = None,
maximum_word_length: int = None,
minimum_document_frequency: int = None,
maximum_document_frequency: int = None,
maximum_document_frequency_percentage: int = None,
boost: bool = None,
boost_factor: float = None,
stop_words_document_id: str = None,
fields: List[str] = None,
): ...
Options |
|
|
minimum_term_frequency |
int |
Ignores terms with less than this frequency in the source doc |
maximum_query_terms |
int |
Returns a query with no more than this many terms |
maximum_number_of_tokens_parsed |
int |
The maximum number of tokens to parse in each example doc field that is not stored with TermVector support |
minimum_word_length |
int |
Ignores words less than this length or, if 0, then this has no effect |
maximum_word_length |
int |
Ignores words greater than this length or if 0 then this has no effect |
minimum_document_frequency |
int |
Ignores words which do not occur in at least this many documents |
maximum_document_frequency |
int |
Ignores words which occur in more than this many documents |
maximum_document_frequency_percentage |
int |
Ignores words which occur in more than this percentage of documents |
boost |
bool |
Boost terms in query based on score |
boost_factor |
float |
Boost factor when boosting based on score |
stop_words_document_id |
str |
Document ID containing custom stop words |
Fields |
List[str] |
Fields to compare |
Example I
# Search for similar articles to 'articles/1'
# using 'Articles/MoreLikeThis' index and search only field 'body'
articles = list(
session.query_index_type(Articles_MoreLikeThis, Article).more_like_this(
lambda builder: builder.using_document(
lambda x: x.where_equals("Id", "articles/1")
).with_options(MoreLikeThisOptions(fields=["body"]))
)
)
from index 'Articles/MoreLikeThis'
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "Body" ] }')
Example II
# Search for similar articles to 'articles/1'
# using 'Articles/MoreLikeThis' index and search only field 'body'
# where article category is 'IT'
articles = list(
session.query_index_type(Articles_MoreLikeThis, Article)
.more_like_this(
lambda builder: builder.using_document(
lambda x: x.where_equals("Id", "articles/1")
).with_options(MoreLikeThisOptions(fields=["body"]))
)
.where_equals("category", "IT")
)
from index 'Articles/MoreLikeThis'
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "Body" ] }') and Category == 'IT'