returns a FTS query for partition created from decomposed search terms.

        args:
            terms (dict or str):

        returns:
            str containing fts query.
977659
def _make_query_from_terms(self, terms):
        

        expanded_terms = self._expand_terms(terms)

        cterms = ''
        if expanded_terms['doc']:
            cterms = self.backend._or_join(expanded_terms['doc'])

        keywords = expanded_terms['keywords']

        frm_to = self._from_to_as_term(expanded_terms['from'], expanded_terms['to'])

        if frm_to:
            keywords.append(frm_to)

        if keywords:
            if cterms:
                cterms = self.backend._and_join(
                    [cterms, self.backend._field_term('keywords', expanded_terms['keywords'])])
            else:
                cterms = self.backend._field_term('keywords', expanded_terms['keywords'])

        logger.debug('partition terms conversion: `{}` terms converted to `{}` query.'.format(terms, cterms))

        return cterms
82525
def get_terms_complete(self) -> pd.DataFrame:
        '''  '''
        if not self.terms_complete.empty:
            return self.terms_complete
        if self.from_backup:
            self.terms_complete = open_pickle(TERMS_COMPLETE_BACKUP_PATH)
            return self.terms_complete
        ilx2synonyms = self.get_ilx2synonyms()
        ilx2existing_ids = self.get_ilx2existing_ids()
        ilx2annotations = self.get_ilx2annotations()
        ilx2superclass = self.get_ilx2superclass()
        ilx_complete = []
        header = ['Index'] + list(self.fetch_terms().columns)
        for row in self.fetch_terms().itertuples():
            row = {header[i]:val for i, val in enumerate(row)}
            row['synonyms'] = ilx2synonyms.get(row['ilx'])
            row['existing_ids'] = ilx2existing_ids[row['ilx']] # if breaks we have worse problems
            row['annotations'] = ilx2annotations.get(row['ilx'])
            row['superclass'] = ilx2superclass.get(row['ilx'])
            ilx_complete.append(row)
        terms_complete = pd.DataFrame(ilx_complete)
        create_pickle(terms_complete, TERMS_COMPLETE_BACKUP_PATH)
        return terms_complete
1180183
def get_terms(self, field=None):
        

        if not field:
            raise AttributeError("Please provide field to apply aggregation to!")
        agg = A("terms", field=field, size=self.size, order={"_count": "desc"})
        self.aggregations['terms_' + field] = agg
        return self
873407
def get_splits_query(self):
        
        query = (
            self.book.session.query(Split)
            # .join(Transaction)
            .filter(Split.transaction_guid == self.transaction.guid)
        )
        return query
371925
def filterItems(self,
                    terms,
                    autoExpand=True,
                    caseSensitive=False):
        
        # create a dictionary of options
        if type(terms) != dict:
            terms = {'*': nativestring(terms)}
        
        # create a dictionary of options
        if type(terms) != dict:
            terms = {'*': nativestring(terms)}
        
        # validate the "all search"
        if '*' in terms and type(terms['*']) != list:
            sterms = nativestring(terms['*'])
            
            if not sterms.strip():
                terms.pop('*')
            else:
                dtype_matches = COLUMN_FILTER_EXPR.findall(sterms)
                
                # generate the filter for each data type
                for match, dtype, values in dtype_matches:
                    sterms = sterms.replace(match, '')
                    terms.setdefault(dtype, [])
                    terms[dtype] += values.split(',')
                
                keywords = sterms.replace(',', '').split()
                while '' in keywords:
                    keywords.remove('')
                
                terms['*'] = keywords
        
        # filter out any columns that are not being searched
        filtered_columns = self.filteredColumns()
        filter_terms = {}
        for column, keywords in terms.items():
            index = self.column(column)
            if column != '*' and not index in filtered_columns:
                continue
            
            if not caseSensitive:
                keywords = [nativestring(keyword).lower() for keyword in keywords]
            else:
                keywords = map(str, keywords)
            
            filter_terms[index] = keywords
        
        self.__filterItems(filter_terms, autoExpand, caseSensitive, 0)
525843
def get_parsed_query(self):
        
        return '{} OR {}'.format(
            self.backend.dataset_index.get_parsed_query()[0],
            self.backend.partition_index.get_parsed_query()[0])
1338010
def getquerylist(self, sep='&', encoding='utf-8', errors='strict'):
        
        if not self.query:
            return []
        elif isinstance(sep, type(self.query)):
            qsl = self.query.split(sep)
        elif isinstance(sep, bytes):
            qsl = self.query.split(sep.decode('ascii'))
        else:
            qsl = self.query.split(sep.encode('ascii'))
        items = []
        for parts in [qs.partition(self.EQ) for qs in qsl if qs]:
            name = uridecode(parts[0], encoding, errors)
            if parts[1]:
                value = uridecode(parts[2], encoding, errors)
            else:
                value = None
            items.append((name, value))
        return items
595516
def word_fts(self, word):
        
        return list(map(self.fts, self.segs(word)))
721286
def search(cls, term, weights=None, with_score=False, score_alias='score',
               explicit_ordering=False):
        """"""
        return cls.search_bm25(
            FTS5Model.clean_query(term),
            weights,
            with_score,
            score_alias,
            explicit_ordering)
12838
def get_lexicons(self, num_terms=10):
        '''
        
        '''
        return {k: v.index[:num_terms]
                for k, v in self.lexicons.items()}
863705
def _or_query(self, term_list, field, field_type):
        
        term_list = [self._term_query(term, field, field_type) for term in term_list]
        return xapian.Query(xapian.Query.OP_OR, term_list)
483311
def _term_query(self, term, field_name, field_type, stemmed=True):
        
        constructor = '{prefix}{term}'

        # construct the prefix to be used.
        prefix = ''
        if field_name:
            prefix = TERM_PREFIXES['field'] + field_name.upper()
            term = _to_xapian_term(term)

        if field_name in (ID, DJANGO_ID, DJANGO_CT):
            # to ensure the value is serialized correctly.
            if field_name == DJANGO_ID:
                term = int(term)
            term = _term_to_xapian_value(term, field_type)
            return xapian.Query('%s%s' % (TERM_PREFIXES[field_name], term))

        # we construct the query dates in a slightly different way
        if field_type == 'datetime':
            date, time = term.split()
            return xapian.Query(xapian.Query.OP_AND_MAYBE,
                                constructor.format(prefix=prefix, term=date),
                                constructor.format(prefix=prefix, term=time)
                                )

        # only use stem if field is text or "None"
        if field_type not in ('text', None):
            stemmed = False

        unstemmed_term = constructor.format(prefix=prefix, term=term)
        if stemmed:
            stem = xapian.Stem(self.backend.language)
            stemmed_term = 'Z' + constructor.format(prefix=prefix, term=stem(term).decode('utf-8'))

            return xapian.Query(xapian.Query.OP_OR,
                                xapian.Query(stemmed_term),
                                xapian.Query(unstemmed_term)
                                )
        else:
            return xapian.Query(unstemmed_term)
687683
public List<Term> getTermsFromWFs(List<String> wfIds) {
	List<Term> terms = new ArrayList<Term>();
	for (String wfId : wfIds) {
	    terms.addAll(this.wfId2Terms.get(wfId));
	}
	return terms;
    }
1009818
private Set<String> searchForIds(Context context, TermQuery query, ConsistencyLevel readConsistency) {
        Set<String> ids = Sets.newTreeSet();

        BoundStatement bindStatement = m_searchStatement.bind();
        bindStatement.setString(Schema.C_TERMS_CONTEXT, context.getId());
        bindStatement.setString(Schema.C_TERMS_FIELD, query.getTerm().getField(Constants.DEFAULT_TERM_FIELD));
        bindStatement.setString(Schema.C_TERMS_VALUE, query.getTerm().getValue());
        bindStatement.setConsistencyLevel(readConsistency);

        for (Row row : m_session.execute(bindStatement)) {
            ids.add(row.getString(Constants.Schema.C_TERMS_RESOURCE));
        }

        return ids;
    }
695231
def _output_terms(self):
        
        terms = list(six.itervalues(self._columns))
        screen = self.screen
        if screen is not None:
            terms.append(screen)
        return terms
1191486
def search(self, search_phrase, limit=None):
        

        # SQLite FTS can't find terms with `-`, therefore all hyphens replaced with underscore before save.
        # Now to make proper query we need to replace all hyphens in the search phrase.
        # See http://stackoverflow.com/questions/3865733/how-do-i-escape-the-character-in-sqlite-fts3-queries
        search_phrase = search_phrase.replace('-', '_')
        terms = SearchTermParser().parse(search_phrase)
        from_year = terms.pop('from', None)
        to_year = terms.pop('to', None)

        query, query_params = self._make_query_from_terms(terms)

        self._parsed_query = (query, query_params)

        connection = self.backend.library.database.connection

        connection.connection.create_function('rank', 1, _make_rank_func((1., .1, 0, 0)))

        # SQLite FTS implementation does not allow to create indexes on FTS tables.
        # see https://sqlite.org/fts3.html 1.5. Summary, p 1:
        # ... it is not possible to create indices ...
        #
        # So, filter years range here.

        results = connection.execute(query, query_params).fetchall()

        for result in results:
            vid, dataset_vid, score, db_from_year, db_to_year = result
            if from_year and from_year < db_from_year:
                continue
            if to_year and to_year > db_to_year:
                continue
            yield PartitionSearchResult(
                vid=vid, dataset_vid=dataset_vid, score=score)
1239703
def search(self, search_phrase, limit=None):
        """"""
        from ambry.identity import ObjectNumber
        from ambry.orm.exc import NotFoundError
        from ambry.library.search_backends.base import SearchTermParser

        results = []

        stp = SearchTermParser()

        # Because of the split between searching for partitions and bundles, some terms don't behave right.
        # The source term should be a limit on everything, but it isn't part of the partition doc,
        # so we check for it here.
        parsed_terms = stp.parse(search_phrase)

        for r in self.search_datasets(search_phrase, limit):
            vid = r.vid or ObjectNumber.parse(next(iter(r.partitions))).as_dataset

            r.vid = vid

            try:
                r.bundle = self.library.bundle(r.vid)

                if 'source' not in parsed_terms or parsed_terms['source'] in r.bundle.dataset.source:
                    results.append(r)
            except NotFoundError:
                pass

        return sorted(results, key=lambda r : r.score, reverse=True)