nitc :: IndexMatches
Index matches can be sorted, filtered and truncated.
Thanks to the fluent interface, the index matches can be manipulated in chain from a model index query:
var res = index.find("Foo").
uniq.
sort(new ScoreComparator, new MEntityComparator).
limit(10).
sort(new VisibilityComparator)
nitc :: IndexMatches :: defaultinit
nitc :: IndexMatches :: from_matches
Create a new ModelMatches from an array of matchesnitc :: IndexMatches :: rerank
Reset score of each matches to followself
order
nitc :: IndexMatches :: sort
Sort the matches withcomparator
(or a list of comparators)
nitc $ IndexMatches :: SELF
Type of this instance, automatically specialized in every classcore :: Collection :: CONCURRENT
Type of the concurrent variant of this collectioncore :: AbstractArrayRead :: _free_iterator
An old iterator, free to reuse.core :: AbstractArrayRead :: _length
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Collection :: combinations
Allr
-length combinations on self (in same order) without repeated elements.
core :: Collection :: combinations_with_replacement
Allr
-length combination on self (in same order) with repeated elements.
core :: AbstractArrayRead :: copy_to
Copy a portion ofself
to an other array.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Cloneable :: defaultinit
core :: SimpleCollection :: defaultinit
core :: AbstractArrayRead :: defaultinit
core :: AbstractArray :: defaultinit
core :: Sequence :: defaultinit
core :: SequenceRead :: defaultinit
core :: Collection :: defaultinit
nitc :: IndexMatches :: defaultinit
core :: Array :: defaultinit
core :: Object :: defaultinit
core :: AbstractArray :: enlarge
Force the capacity to be at leastcap
.
core :: Array :: filled_with
Create an array ofcount
elements
core :: AbstractArrayRead :: free_iterator
An old iterator, free to reuse.core :: AbstractArrayRead :: free_iterator=
An old iterator, free to reuse.serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: IndexMatches :: from_matches
Create a new ModelMatches from an array of matchescore :: SequenceRead :: get_or_default
Try to get an element, returndefault
if the index
is invalid.
core :: SequenceRead :: get_or_null
Try to get an element, returnnull
if the index
is invalid.
core :: Collection :: has_all
Does the collection contain at least each element ofother
?
core :: Collection :: has_any
Does the collection contain at least one element ofother
?
core :: Collection :: has_exactly
Does the collection contain exactly all the elements ofother
?
core :: SequenceRead :: index_of_from
The index of the first occurrence ofitem
, starting from pos.
core :: Sequence :: insert_all
Insert all elements at a given position, following elements are shifted.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: SequenceRead :: iterator_from
Gets a new Iterator starting at positionpos
core :: SequenceRead :: last_index_of
The index of the last occurrence ofitem
.
core :: SequenceRead :: last_index_of_from
The index of the last occurrence ofitem
starting from pos
and decrementing.
core :: AbstractArrayRead :: length=
core :: SequenceRead :: modulo_index
Returns the real index for a modulo index.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).core :: Collection :: permutations
Allr
-length permutations on self (all possible ordering) without repeated elements.
core :: Collection :: product
Cartesian product, overr
times self
.
core :: RemovableCollection :: remove
Remove an occurrence ofitem
core :: RemovableCollection :: remove_all
Remove all occurrences ofitem
nitc :: IndexMatches :: rerank
Reset score of each matches to followself
order
core :: SequenceRead :: reverse_iterator
Gets an iterator starting at the end and going backwardscore :: SequenceRead :: reverse_iterator_from
Gets an iterator on the chars of self starting frompos
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
core :: Collection :: serialize_to_pure_json
Utility to serialize a normal Json arraynitc :: IndexMatches :: sort
Sort the matches withcomparator
(or a list of comparators)
core :: Collection :: to_concurrent
Wrapsself
in a thread-safe collection
core :: Collection :: to_counter
Create and fill up a counter with the elements of `self.core :: Collection :: to_curlslist
Convert Collection[String] to CURLSListserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Collection :: to_shuffle
Return a new array made of elements in a random order.core :: Array :: with_capacity
Create an empty array with a given capacity.core :: Array :: with_native
Create a array filled with a given native array.Serializer::serialize
# An array of IndexMatch instances returned by the ModelIndex
#
# Index matches can be sorted, filtered and truncated.
#
# Thanks to the fluent interface, the index matches can be manipulated in chain
# from a model index query:
#
# ~~~nitish
# var res = index.find("Foo").
# uniq.
# sort(new ScoreComparator, new MEntityComparator).
# limit(10).
# sort(new VisibilityComparator)
# ~~~
class IndexMatches
super Array[IndexMatch]
# Create a new ModelMatches from an array of matches
#
# Elements are copied.
init from_matches(matches: Array[IndexMatch]) do self.add_all matches
# Sort the matches with `comparator` (or a list of comparators)
#
# Return a new IndexMatches instance with the sorted results.
#
# When more than one comparator is given, the comparators are applied in a
# pipeline where the `n`th comparator is applied only if the `n-1`th comparator
# returned 0.
fun sort(comparator: ScoreComparator...): IndexMatches do
var res = to_a
if comparator.length == 1 then
comparator.first.sort res
else
var comparators = new MatchComparators(comparator)
comparators.sort res
end
return new IndexMatches.from_matches(res)
end
# Limit the matches with `limit`
#
# Return a new IndexMatches instance with only the `limit` first matches.
fun limit(limit: Int): IndexMatches do
var res = new Array[IndexMatch]
for match in self do
if res.length >= limit then break
res.add match
end
return new IndexMatches.from_matches(res)
end
# Remove doublons from the matches
#
# Preverse the lowest score of all the matches for a MEntity.
fun uniq: IndexMatches do
var scores = new HashMap[MEntity, IndexMatch]
var res = new Array[IndexMatch]
for match in self do
var mentity = match.mentity
if scores.has_key(mentity) then
var older = scores[mentity]
if match.score < older.score then older.score = match.score
else
scores[mentity] = match
res.add match
end
end
return new IndexMatches.from_matches(res)
end
# Reset score of each matches to follow `self` order
#
# Usefull when you need to apply one sorter over another.
fun rerank: IndexMatches do
var res = new IndexMatches
for match in self do
res.add match
match.score = res.length
end
return res
end
# Aggregate the mentities for all the matches
#
# Preserve the match order.
fun mentities: Array[MEntity] do
var res = new Array[MEntity]
for match in self do res.add match.mentity
return res
end
end
src/model/model_index.nit:429,1--520,3