I'm building a WordPress autocomplete search which uses custom taxonomy terms as suggestions, and I'm using WP_Term_Query to query for the terms from what the user types in the search field.
WP_Term_Query has a parameter called "search" which according to the documentation uses the search criteria to match terms and will be SQL-formatted with wildcards before and after. I would need it to only include the wildcard after, so that from the input "ad" it would match "Addaday" and "Adidas", but not "Diadora" or "Fitness Mad" for example. Is this possible to accomplish somehow?
Another approach would be to write a bit more code to weed out the results you don't want and keep just the ones you do. How that would look would depend on the code you already have, but preg_match() might get you on the right track.
Related
How can I exclude multiple search terms in Kibana 4? If I type in only one term, it excludes it...but how can I have more than one excluded term. For example, the term "not yet classified"
If I understand your question properly, you're trying to use the "Exclude Pattern" to exclude certain values from populating in the chart.
The "Exclude Pattern" and "Include Pattern" fields are for Regular Expressions and are documented here: http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html.
If you want to exclude multiple fields, you could do something like this:
term1|term2|term3
The query field in Kibana uses Lucene syntax which has some info at http://www.lucenetutorial.com/lucene-query-syntax.html.
To exclude a term containing specific text, use
-field: "text"
to exclude different texts, I use
-field: ("text1" or "text2")
If it's two separate fields, try
-field1: "text1" -field2: "text2"
in newer version of kibana if you want to exclude some term use this:
not field : "text"
if you want to exclude a phrase use this:
not field : "some text phrase"
you can use other logical operation with not:
field: "should have phrase" and not field: "excluded phrase"
https://www.elastic.co/guide/en/kibana/master/kuery-query.html
To match documents where response is 200 but extension is not php or css.
response:200 and not (extension:php or extension:css)
So in the query above the visualization, you can use Lucene syntax to exclude the hits, once saved this will perform the same as an attempt of using regex or Lucene syntax in the Exclude Field of the Buckets advanced options.
I have a book in Drupal with 17 chapters, and several subchapters within them. I want to set up a filtered search that will let me restrict a search entry to only a specified chapter. I've labeled the chapters with a taxonomy vocabulary and using the custom search module, I have set up a search that lets you filter by taxonomy.
However, when I do this, the search doesn't work for the child pages associated with a chapter. For example, in using my method and searching chapter 1, I don't get any results from the subchapters in chapter 1. Is there a way to resolve this? Or do I have to set up my search in a different way?
You should change your filter to 'Has taxonomy terms (with depth)'
This will also include the child entities, or sub chapters in your situation.
I'm constructing an apachesolr query in my Drupal module programmatically and have had success with some aspects, but am still struggling with others.
So far, I have been able to construct a query that can search for specific text and limit the results based on terms to be filtered by with the following code:
$subquery_region->addFilter('tid', $term->tid);
$query->addFilterSubQuery($subquery_region, 'OR', 'AND');
What I'd like to achieve next is to be able to narrow the search further by adding a filter for finding certain text within a specific field in the node. Has anyone been able to do this.
I've been researching online and have tried lots of different ways such as adding the filter directly to the main search query
$query->addParam('fl', 'ss_my_field');
$query->addFilter("ss_my_field", "field_substring_to_search_for");
As well as breaking that out into a subquery to add to the main search query
$subquery_test = apachesolr_drupal_query("Test");
$subquery_test->addParam('fl', 'ss_my_field');
$subquery_test->addFilter("ss_my_field", "field_substring_to_search_for");
$query->addFilterSubQuery($subquery_test, 'OR', 'AND');
But none of these are working. They are returning an empty set, even though I know the substring exists in the field I'm adding as a filter and it has been indexed. I have verified through the apachesorl views module that the search index has been populated with that field and can see the substring exists.
Is there anything wrong with my syntax or the way I'm building the query?
If you know how to add filters for searching for text within certain fields, please share! It may not even be done with the addFilter function, but that's all I have been trying so far.
Thanks!
First you have to create an index for that specific field.
function hook_apachesolr_update_index(&$document, $node) {
$document->ss_your_field_name = $node->your_field_name;
}
where ss_* is the pattern.
ss_* -> String
is_* -> Integer
im_* -> Integer, Multivalued
After that you have to
1. delete the index - admin/settings/apachesolr/index
2. re-index the content
3. run the cron
4. check the filter that you created - admin/reports/apachesolr/index
Then, you can add filters
$query->addFilter("ss_your_field_name", "value");
Hope this helps you.
function hook_apachesolr_modify_query(&$query, &$params, $caller){
$subquery = apachesolr_drupal_query();
$subquery->add_filter("ss_my_field", "field_substring_to_search_for");
$query->add_subquery($subquery, "AND");
}
I'm trying to wrap my head around getting nodes that share the same taxonomy terms, but I have some questions.
Essentially, I want to display a view at the bottom of my event node that shows related events. I have tags for each event and will be using those to create the match.
In views, when I create a taxonomy argument and add multiple "tags" it searches for nodes with all the specified arguments. What I want is not to search just for nodes that contain all of the arguments, but nodes that contain either or. So far I haven't figured any solutions.
Edit:
Would it be easier to create a simple block module that queries the database for nodes that contain the terms?
I am using a Taxonomy Term ID as argument and then I selected the checkbox that allows Multiple Terms per argument. Notice the help text that says, "If selected, users can enter multiple arguments in the form of 1+2+3 (for OR) or 1,2,3 (for AND)." By using the + sign you will OR the arguments together, but if you use the , then they will be AND together thus forcing nodes to have all terms. For this specific view I am providing the default argument via php and I am using the plus sign to wrap the term ID arguments together. This will give me all the nodes that are tagged with any of the terms supplied as arguments.
edit: I might want to also add that I have the checkbox selected for "Let Multiple arguments work together." That may or may not be needed for your use case, but I needed it for mine.
Briefly: I'm making a custom view, I want a field listing the two taxonomy terms associated with an NID to output as two distinct links which return arguments for the view (term1 to view/term1, term2 to view/term2. Rather, it outputs as one aggregated link (both term1 and term2 output view/term1%0Aterm2.
Am I doing something wrong or is this not possible?
Exhaustively:
I am constructing a view of products (with the page output at http://example.com/products) in an drupal ubercart site because the built-in ubercart catalog psuedo-view isn't doing it for me. Some of these products belong to more than one taxonomy term (within the same vocabulary) - for instance, product_example1 belongs to terms blue and glowinthedark, product_example2 red and glowinthedark, product-example3 just blue.
I've created an argument which limits the view based on terms like so: products/red, products/glowinthedark etc returns this nice view I made but only with products which are associated with taxonomy terms red, glowinthedark, etc - so works as it should. Views is awesome!
Now, I want each product shown in this view to link to the generated product/[term] page(s). Outputting the field "taxonomy:all terms" as a link with replacement argument products/[tid] works for one term (product_example3's field works for its one term: /products/blue (views is awesome!) , but, AND HERE'S THE PROBLEM, it DOESN'T FOR TWO TERMS (or I assume more than two terms). This is true whether the field is output as a list or using a simple seperator. So, for product_example one, the field lists both terms blue and glowinthedark (correctly separated as list items or with the chosen "," simple separator), but both terms output the relative link products/blue%0Aglowinthedark.
Is that clear? I haven't been able to google anyone with a similar situation, strangely, although I can't imagine I'm the first to run into this. I may just give up since it's not all that important and I can think of several less-satisfactory but still doable workarounds, but I thought you all might have some insight. The only thing that gives me hope is that when the "Link this field to its term page" check box is selected, views successfully outputs two separate line items with links to the two separate terms' pages.
I'm also posting this question on Drupal.org. Thanks for your time!
Hmmm... strange. I read your question carefully. However I am getting the results that you desire!
I have a taxonomy vocabulary that is multiple select (lets call it "Sector")
I have a taxonomy vocabulary that is single select (lets call it "Location")
In my fields section, I add Taxonomy: All Terms
In the settings for Taxonomy: All Terms I select "Output this field as a link". In there, I set the "Link Path" to product/[tid]
I make sure "Link this field to its term page" is NOT checked
I use a simple comma separator
"Limit terms to a specific vocabulary" checkbox does not matter. It would depend on your business requirements.
As required by you I get products/abc, products/xyz etc. one after another on a single line. This works even if a particular node has multiple terms from the same taxonomy vocabulary. I don't get any %0A stuff.
This works out of the box for me. I tried with both views 2.11 and views 3.0-alpha3
Try upgrading to the latest version of views and see if you have better luck?