search whit '/' character-[LUCENE.NET 4] - lucene.net

How to search with the character '/' within a text? IN LUCENE 4 (in version 3 it works) I describe the tests
test1
Lucene 4 index
analizer: StandAnalizer
indeded values
"01/02/03"
"01/02/04"
"01/02/05"
Lucene 4 search
search "01/02/05" whit TermQuery = 0 hits
search "01/02*" whit WildCardQuery = 0 hits
search "01" whit TermQuery = 3 hits
search "01**" whit WildCardQuery = 0 hits
test2
Lucene 3 index
analizer: StandAnalizer
indeded values
"01/02/03"
"01/02/04"
"01/02/05"
Lucene 3 search
search "01/02/05" whit TermQuery = 1 hits
search "01/02*" whit WildCardQuery = 3 hits
search "01" whit TermQuery = 0 hits
search "01**" whit WildCardQuery = 3 hits
test3
Lucene 3 index
analizer: StandAnalizer
indeded values
"01/02/03"
"01/02/04"
"01/02/05"
Lucene 4 search
search "01/02/05" whit TermQuery = 1 hits
search "01/02*" whit WildCardQuery = 3 hits
search "01" whit TermQuery = 0 hits
search "01**" whit WildCardQuery = 3 hits
NOTE:search for full text and test whit scape
test4
Lucene 4 index
analizer: StandAnalizer
indeded values
"01\/02\/03"
"01\/02\/04"
"01\/02\/05"
Lucene 4 search
search "01/02/05" whit TermQuery = 0 hits
search "01/02*" whit WildCardQuery = 0 hits
search "01" whit TermQuery = 3 hits
search "01**" whit WildCardQuery = 0 hits
test5
Lucene 4 index
analizer: StandAnalizer
indeded values
"01\/02\/03"
"01\/02\/04"
"01\/02\/05"
Lucene 4 search
search "01\/02\/05" whit TermQuery = 0 hits
search "01\/02*" whit WildCardQuery = 0 hits
search "01" whit TermQuery = 3 hits
search "01**" whit WildCardQuery = 0 hits
test6
Lucene 4 index
analizer: StandAnalizer
indeded values
"01/02/03"
"01/02/04"
"01/02/05"
Lucene 4 search
search "01\/02\/05" whit TermQuery = 0 hits
search "01\/02*" whit WildCardQuery = 0 hits
search "01" whit TermQuery = 3 hits
search "01**" whit WildCardQuery = 0 hits

TermQuery with SimpleAnalyzer works just fine. I'm using Lucene.Net.4.8.0-beta00005. Here is an example:
[TestMethod]
public void SearchByDate()
{
using (RAMDirectory directory = new RAMDirectory())
{
using (SimpleAnalyzer analyzer = new SimpleAnalyzer(LuceneVersion.LUCENE_48))
{
IndexWriterConfig config = new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer);
Document[] documents = new Document[]
{
new Document { new StringField("Date", "01/02/03", Field.Store.YES), },
new Document { new StringField("Date", "01/02/04", Field.Store.YES), },
new Document { new StringField("Date", "01/02/05", Field.Store.YES), },
};
using (IndexWriter writer = new IndexWriter(directory, config))
foreach (Document document in documents)
writer.AddDocument(document);
using (DirectoryReader reader = DirectoryReader.Open(directory))
{
IndexSearcher searcher = new IndexSearcher(reader);
TermQuery query = new TermQuery(new Term("Date", "01/02/04"));
ScoreDoc[] hits = searcher.Search(query, 10).ScoreDocs;
Assert.AreEqual(1, hits.Length);
Document doc = searcher.Doc(hits.First().Doc);
Assert.AreEqual("01/02/04", doc.Fields.FirstOrDefault(x => x.Name == "Date").GetStringValue());
}
}
}
}

Related

TYPO3 - get last element of a splitted string

Trying to get the last part of the url as a body class. So far I got the slug of the page and split it by /
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.field = slug
page.bodyTagCObject.split {
token = /
cObjNum = 1
1.10 = TEXT
1.10.current = 1
1.10.noTrimWrap = | ||
1.10.dataWrap = |
1.10.required = 1
}
With this code, I am getting:
url: page/foo/bar/
class="page foo bar"
I need to get class="bar"
You'll need to use optionSplit for that. For example:
lib.test = TEXT
lib.test {
value = 1,2,3,4
split {
token = ,
cObjNum = 1 |*| 2 |*| 3
1 = TEXT
1 {
current = 1
wrap = First item:|<br/>
}
2 = TEXT
2 {
current = 1
wrap = Middle item:|<br/>
}
3 = TEXT
3 {
current = 1
wrap = Last item:|<br/>
}
}
}
1 |*| 2 |*| 3 means: use 1 for the first item, 3 for the last item and 2 for the rest.
You can just not set the ones you don't want, so this will only show the last item:
cObjNum = 1 |*| 1 |*| 2
2 = TEXT
2 {
current = 1
wrap = Last item:|<br/>
}

Get list of feusers with typoscript, can't get the names of the associated usergroups

I am generating this list of feusers and trying to get the names of the associated usergroups. This code worked before the update to TYPO3 8.x (it's just the relevant part of the whole thing):
40 = TEXT
40.field = usergroup
40.split {
token = ,
cObjNum = 1 || 2
1 {
10 = CONTENT
10.table = fe_groups
10.select.pidInList = 22
10.select.andWhere.current = 1
10.select.andWhere.wrap = uid=|
10.select.where = (title NOT LIKE 'Netzwerk')
10.renderObj = TEXT
10.renderObj.field = title
10.renderObj.wrap = |, <br />
}
2 < .1
2.10.renderObj.wrap >
}
With TYPO3 8 the 'andWhere' is depreciated and so I tried like this, but failed:
40 = TEXT
40.field = usergroup
40.split {
token = ,
cObjNum = 1 || 2
1{
10 = CONTENT
10 {
table = fe_groups
select {
pidInList = 22
where.current = 1
where.wrap = uid= |
}
10.renderObj = TEXT
10.renderObj.field = title
10.renderObj.wrap = |,
}
2 < .1
2.10.renderObj.wrap
}
}
Thanks for pointing me in the right direction.
You should not split up the comma separated values, but go for uidInList instead. This way you get rid of the surrounding split and fetch the elements within just one go.
40 = CONTENT
40 {
table = fe_groups
select {
uidInList.field = usergroup
pidInList = 22
}
renderObj = TEXT
renderObj.field = title
renderObj.wrap = |,
}

hide page & subpages from menu

I have the following page structure in TYPO3:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Now I want to have 1/* + 4/* included in the header menu and 4/* + 7/* in the footer menu. Since the header and footer menus are different, I cannot just use the "hide in menu" feature and need to do it in TypoScript instead.
Here's what I have so far:
HEADERMENU = HMENU
HEADERMENU {
1 = TMENU
1.expAll = 1
1.NO = 1
1.NO {
stdWrap.if.value.field = uid
stdWrap.if.equals = 7
stdWrap.if.negate = 1
}
2 < .1
}
FOOTERMENU < HEADERMENU
FOOTERMENU.1.NO.stdWrap.if.equals = 1
The problem with this is, that it still displays the pages 8+9 in the header and 2+3 in the footer, even if it does not display page 1/7 anymore. I know that I could use if.isInList and the provide all subpage IDs, but then I'd have to change the TypoScript everytime I add a new page. If possible, I'd like to dynamically exclude a page and all its subpages.
How can I do that?
As Daniel mentioned in his answer there is a way to display all subpages of the selected pages. special = directory displays however only the subpages. So you could see only 2/3 and 5/6 and 8/9 in your menus.
special = directory
"This will generate a menu of all pages with pid = 35 and pid = 56."
I would suggest the excludeUidList property.
HEADERMENU = HMENU
HEADERMENU {
excludeUidList = 7
1 = TMENU
1.expAll = 1
2 < .1
}
FOOTERMENU < HEADERMENU
FOOTERMENU.excludeUidList = 1
It is working as a WHERE condition in a db SELECT query, so you won't get those pages on the first level and neither will it find their subpages then.
You could go for the special=directory approach to render a Menu of one or more pages and their subpages.
HEADERMENU.special = directory
HEADERMENU.special.value = 1, 4
More information in the documentation.

sphinx: how to search for a phrase with wildcard?

I have a phrase "my name is bob". I want to match it by querying "my n".
How my query should look like? What config should I have?
min_prefix_len and min_prefix_len did not give any expecting results.
I had min_word_len set to 2, but changing it to 1 did not help either.
expand_keywords 1/2 had made no difference.
Here's my index config:
index track
{
source = track
path = /var/lib/sphinx/track
min_word_len = 1
docinfo = extern
mlock = 1
morphology = none
expand_keywords = 1
}
The queries i tried:
"my n*"
"my n"*
my n
"my n" | my n*
"my n" | "my n*" | my n*
No matter what, I cannot match "my name ...".
min_word_len = 1
min_prefix_len = 1
expand_keywords = 0
Need min_prefix_len to enable wildcard searches. But want expand_keywords off, as that makes all keywords have wildcards on them.
Then can just do
"my n*"

How to setup a browse menu to cycle a page and it's sub pages only in typo3?

I am trying to set up a browse menu to cycle a page and it's sub pages. I have to have it in the format of < 2 > where < is the previous page, 2 is the current page, and > is the next page. To reslove this I decided to put an extension template on the parent page which in which a browse menu points to the first page of the sub page tree:
lib.pagenumber = HMENU
lib.pagenumber{
special = browse
special.items = | next
special.next.uid = 100
special.next.fields.title = 2
1 = TMENU
1{
noBlur = 1
expAll = 0
NO = 1
NO.ATagTitle = 1
NO.before = <div id="currLGMpg" class= "currpg">1</div>
NO.linkWrap = <div class=nextLGMpg>|</div>
}
}
The current page is not linked but just an image box which has to be between the prev and next links and also be auto numbered. this is the second problem I am trying to solve.
For the subpages I am thinking that a template on the first subpage with option split on the linkwrap would work for styling the prev and next links but I have no idea how to put the image for the current page in the middle.
Hello for cycling you should follows the below steps this only for next please follow same steps for prev.
temp.lightbox_navi.30 = HMENU
temp.lightbox_navi.30 {
stdWrap.wrap = <li>|</li>
special = browse
special {
items = next
items.prevnextToSection = 0
next.fields.title = < next Projekt
}
1 = TMENU
1 {
NO = 1
}
stdWrap.ifEmpty.cObject = HMENU
stdWrap.ifEmpty.cObject {
special = browse
special {
items = first
items.prevnextToSection = 0
first.fields.title = < next Projekt o
}
1 = TMENU
1 {
NO = 1
}
}
}
So I finally solved all but one issue. which is to auto number the page. For those interested, you need to map the next and prev separately to so that you can put a page number button inbetween. The following typoscript code sits on the root page tree of the pages you want to setup browse buttons for:
#Next page button setup
lib.nextpage = HMENU
lib.nextpage.special = browse
lib.nextpage.special.items = next
#can't remove the page title some reason it just gets inserted back so we set it to nothing
lib.nextpage.special.next.fields.title =
#if we're on the parent page of the page tree we wish to browse next should point to the first page of the subtree.
[globalVar = TSFE:id = 46]
lib.nextpage.special.next.uid = 100
[global]
lib.nextpage.1 = TMENU
lib.nextpage.1{
noBlur = 1
expAll = 0
NO = 1
#NO.ATagTitle = 1
NO.linkWrap = <div class=nextLGMpg>|</div>
}
#Page number
lib.currpage = TEXT
#can't autonumber yet so put a 1 as a placeholder for the current page number
lib.currpage.value = 1
lib.currpage.wrap = <div id="currLGMpg">|</div>
#previous page button setup
#copy from next page setup; tbh all we gain is 1 less line code
lib.prevpage < lib.nextpage
lib.prevpage.special.items = prev
lib.prevpage.special.prev.fields.title =
#again if we're at the 1st subpage we need to target the parent page as that is page one.
[globalVar = TSFE:id = 100]
lib.prevpage.special.prev.uid = 46
#next line tests to see if we're at page 1. If we are we remove the prev object because browsing stops here.
[globalVar = TSFE:id = 46]
lib.prevpage >
[global]
lib.prevpage.1 = TMENU
lib.prevpage.1{
noBlur = 1
expAll = 0
NO = 1
#NO.ATagTitle = 1
NO.linkWrap = <div class=prevLGMpg>|</div>
}
Once I figure out how to autonumber I will update the answer.